Mercurial > hg > soundsoftware-site
comparison .svn/pristine/5b/5b4d21bca26fd3fe16dbb733fe9dd17bcabdb041.svn-base @ 1295:622f24f53b42 redmine-2.3
Update to Redmine SVN revision 11972 on 2.3-stable branch
author | Chris Cannam |
---|---|
date | Fri, 14 Jun 2013 09:02:21 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
1294:3e4c3460b6ca | 1295:622f24f53b42 |
---|---|
1 # Redmine - project management software | |
2 # Copyright (C) 2006-2012 Jean-Philippe Lang | |
3 # | |
4 # This program is free software; you can redistribute it and/or | |
5 # modify it under the terms of the GNU General Public License | |
6 # as published by the Free Software Foundation; either version 2 | |
7 # of the License, or (at your option) any later version. | |
8 # | |
9 # This program is distributed in the hope that it will be useful, | |
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 # GNU General Public License for more details. | |
13 # | |
14 # You should have received a copy of the GNU General Public License | |
15 # along with this program; if not, write to the Free Software | |
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |
17 | |
18 require File.expand_path('../../test_helper', __FILE__) | |
19 require 'repositories_controller' | |
20 | |
21 # Re-raise errors caught by the controller. | |
22 class RepositoriesController; def rescue_action(e) raise e end; end | |
23 | |
24 class RepositoriesControllerTest < ActionController::TestCase | |
25 fixtures :projects, :users, :roles, :members, :member_roles, :enabled_modules, | |
26 :repositories, :issues, :issue_statuses, :changesets, :changes, | |
27 :issue_categories, :enumerations, :custom_fields, :custom_values, :trackers | |
28 | |
29 def setup | |
30 @controller = RepositoriesController.new | |
31 @request = ActionController::TestRequest.new | |
32 @response = ActionController::TestResponse.new | |
33 User.current = nil | |
34 end | |
35 | |
36 def test_new | |
37 @request.session[:user_id] = 1 | |
38 get :new, :project_id => 'subproject1' | |
39 assert_response :success | |
40 assert_template 'new' | |
41 assert_kind_of Repository::Subversion, assigns(:repository) | |
42 assert assigns(:repository).new_record? | |
43 assert_tag 'input', :attributes => {:name => 'repository[url]', :disabled => nil} | |
44 end | |
45 | |
46 def test_new_should_propose_enabled_scm_only | |
47 @request.session[:user_id] = 1 | |
48 with_settings :enabled_scm => ['Mercurial', 'Git'] do | |
49 get :new, :project_id => 'subproject1' | |
50 end | |
51 assert_response :success | |
52 assert_template 'new' | |
53 assert_kind_of Repository::Mercurial, assigns(:repository) | |
54 assert_tag 'select', :attributes => {:name => 'repository_scm'}, | |
55 :children => {:count => 3} | |
56 assert_tag 'select', :attributes => {:name => 'repository_scm'}, | |
57 :child => {:tag => 'option', :attributes => {:value => 'Mercurial', :selected => 'selected'}} | |
58 assert_tag 'select', :attributes => {:name => 'repository_scm'}, | |
59 :child => {:tag => 'option', :attributes => {:value => 'Git', :selected => nil}} | |
60 end | |
61 | |
62 def test_create | |
63 @request.session[:user_id] = 1 | |
64 assert_difference 'Repository.count' do | |
65 post :create, :project_id => 'subproject1', | |
66 :repository_scm => 'Subversion', | |
67 :repository => {:url => 'file:///test', :is_default => '1', :identifier => ''} | |
68 end | |
69 assert_response 302 | |
70 repository = Repository.first(:order => 'id DESC') | |
71 assert_kind_of Repository::Subversion, repository | |
72 assert_equal 'file:///test', repository.url | |
73 end | |
74 | |
75 def test_create_with_failure | |
76 @request.session[:user_id] = 1 | |
77 assert_no_difference 'Repository.count' do | |
78 post :create, :project_id => 'subproject1', | |
79 :repository_scm => 'Subversion', | |
80 :repository => {:url => 'invalid'} | |
81 end | |
82 assert_response :success | |
83 assert_template 'new' | |
84 assert_kind_of Repository::Subversion, assigns(:repository) | |
85 assert assigns(:repository).new_record? | |
86 end | |
87 | |
88 def test_edit | |
89 @request.session[:user_id] = 1 | |
90 get :edit, :id => 11 | |
91 assert_response :success | |
92 assert_template 'edit' | |
93 assert_equal Repository.find(11), assigns(:repository) | |
94 assert_tag 'input', :attributes => {:name => 'repository[url]', :value => 'svn://localhost/test', :disabled => 'disabled'} | |
95 end | |
96 | |
97 def test_update | |
98 @request.session[:user_id] = 1 | |
99 put :update, :id => 11, :repository => {:password => 'test_update'} | |
100 assert_response 302 | |
101 assert_equal 'test_update', Repository.find(11).password | |
102 end | |
103 | |
104 def test_update_with_failure | |
105 @request.session[:user_id] = 1 | |
106 put :update, :id => 11, :repository => {:password => 'x'*260} | |
107 assert_response :success | |
108 assert_template 'edit' | |
109 assert_equal Repository.find(11), assigns(:repository) | |
110 end | |
111 | |
112 def test_destroy | |
113 @request.session[:user_id] = 1 | |
114 assert_difference 'Repository.count', -1 do | |
115 delete :destroy, :id => 11 | |
116 end | |
117 assert_response 302 | |
118 assert_nil Repository.find_by_id(11) | |
119 end | |
120 | |
121 def test_revisions | |
122 get :revisions, :id => 1 | |
123 assert_response :success | |
124 assert_template 'revisions' | |
125 assert_equal Repository.find(10), assigns(:repository) | |
126 assert_not_nil assigns(:changesets) | |
127 end | |
128 | |
129 def test_revisions_for_other_repository | |
130 repository = Repository::Subversion.create!(:project_id => 1, :identifier => 'foo', :url => 'file:///foo') | |
131 | |
132 get :revisions, :id => 1, :repository_id => 'foo' | |
133 assert_response :success | |
134 assert_template 'revisions' | |
135 assert_equal repository, assigns(:repository) | |
136 assert_not_nil assigns(:changesets) | |
137 end | |
138 | |
139 def test_revisions_for_invalid_repository | |
140 get :revisions, :id => 1, :repository_id => 'foo' | |
141 assert_response 404 | |
142 end | |
143 | |
144 def test_revision | |
145 get :revision, :id => 1, :rev => 1 | |
146 assert_response :success | |
147 assert_not_nil assigns(:changeset) | |
148 assert_equal "1", assigns(:changeset).revision | |
149 end | |
150 | |
151 def test_revision_should_not_change_the_project_menu_link | |
152 get :revision, :id => 1, :rev => 1 | |
153 assert_response :success | |
154 | |
155 assert_tag 'a', :attributes => {:href => '/projects/ecookbook/repository', :class => /repository/}, | |
156 :ancestor => {:attributes => {:id => 'main-menu'}} | |
157 end | |
158 | |
159 def test_revision_with_before_nil_and_afer_normal | |
160 get :revision, {:id => 1, :rev => 1} | |
161 assert_response :success | |
162 assert_template 'revision' | |
163 assert_no_tag :tag => "div", :attributes => { :class => "contextual" }, | |
164 :child => { :tag => "a", :attributes => { :href => '/projects/ecookbook/repository/revisions/0'} | |
165 } | |
166 assert_tag :tag => "div", :attributes => { :class => "contextual" }, | |
167 :child => { :tag => "a", :attributes => { :href => '/projects/ecookbook/repository/revisions/2'} | |
168 } | |
169 end | |
170 | |
171 def test_add_related_issue | |
172 @request.session[:user_id] = 2 | |
173 assert_difference 'Changeset.find(103).issues.size' do | |
174 xhr :post, :add_related_issue, :id => 1, :rev => 4, :issue_id => 2, :format => 'js' | |
175 assert_response :success | |
176 assert_template 'add_related_issue' | |
177 assert_equal 'text/javascript', response.content_type | |
178 end | |
179 assert_equal [2], Changeset.find(103).issue_ids | |
180 assert_include 'related-issues', response.body | |
181 assert_include 'Feature request #2', response.body | |
182 end | |
183 | |
184 def test_add_related_issue_with_invalid_issue_id | |
185 @request.session[:user_id] = 2 | |
186 assert_no_difference 'Changeset.find(103).issues.size' do | |
187 xhr :post, :add_related_issue, :id => 1, :rev => 4, :issue_id => 9999, :format => 'js' | |
188 assert_response :success | |
189 assert_template 'add_related_issue' | |
190 assert_equal 'text/javascript', response.content_type | |
191 end | |
192 assert_include 'alert("Issue is invalid")', response.body | |
193 end | |
194 | |
195 def test_remove_related_issue | |
196 Changeset.find(103).issues << Issue.find(1) | |
197 Changeset.find(103).issues << Issue.find(2) | |
198 | |
199 @request.session[:user_id] = 2 | |
200 assert_difference 'Changeset.find(103).issues.size', -1 do | |
201 xhr :delete, :remove_related_issue, :id => 1, :rev => 4, :issue_id => 2, :format => 'js' | |
202 assert_response :success | |
203 assert_template 'remove_related_issue' | |
204 assert_equal 'text/javascript', response.content_type | |
205 end | |
206 assert_equal [1], Changeset.find(103).issue_ids | |
207 assert_include 'related-issue-2', response.body | |
208 end | |
209 | |
210 def test_graph_commits_per_month | |
211 # Make sure there's some data to display | |
212 latest = Project.find(1).repository.changesets.maximum(:commit_date) | |
213 assert_not_nil latest | |
214 Date.stubs(:today).returns(latest.to_date + 10) | |
215 | |
216 get :graph, :id => 1, :graph => 'commits_per_month' | |
217 assert_response :success | |
218 assert_equal 'image/svg+xml', @response.content_type | |
219 end | |
220 | |
221 def test_graph_commits_per_author | |
222 get :graph, :id => 1, :graph => 'commits_per_author' | |
223 assert_response :success | |
224 assert_equal 'image/svg+xml', @response.content_type | |
225 end | |
226 | |
227 def test_get_committers | |
228 @request.session[:user_id] = 2 | |
229 # add a commit with an unknown user | |
230 Changeset.create!( | |
231 :repository => Project.find(1).repository, | |
232 :committer => 'foo', | |
233 :committed_on => Time.now, | |
234 :revision => 100, | |
235 :comments => 'Committed by foo.' | |
236 ) | |
237 | |
238 get :committers, :id => 10 | |
239 assert_response :success | |
240 assert_template 'committers' | |
241 | |
242 assert_tag :td, :content => 'dlopper', | |
243 :sibling => { :tag => 'td', | |
244 :child => { :tag => 'select', :attributes => { :name => %r{^committers\[\d+\]\[\]$} }, | |
245 :child => { :tag => 'option', :content => 'Dave Lopper', | |
246 :attributes => { :value => '3', :selected => 'selected' }}}} | |
247 assert_tag :td, :content => 'foo', | |
248 :sibling => { :tag => 'td', | |
249 :child => { :tag => 'select', :attributes => { :name => %r{^committers\[\d+\]\[\]$} }}} | |
250 assert_no_tag :td, :content => 'foo', | |
251 :sibling => { :tag => 'td', | |
252 :descendant => { :tag => 'option', :attributes => { :selected => 'selected' }}} | |
253 end | |
254 | |
255 def test_post_committers | |
256 @request.session[:user_id] = 2 | |
257 # add a commit with an unknown user | |
258 c = Changeset.create!( | |
259 :repository => Project.find(1).repository, | |
260 :committer => 'foo', | |
261 :committed_on => Time.now, | |
262 :revision => 100, | |
263 :comments => 'Committed by foo.' | |
264 ) | |
265 assert_no_difference "Changeset.count(:conditions => 'user_id = 3')" do | |
266 post :committers, :id => 10, :committers => { '0' => ['foo', '2'], '1' => ['dlopper', '3']} | |
267 assert_response 302 | |
268 assert_equal User.find(2), c.reload.user | |
269 end | |
270 end | |
271 end |