@@ -1,574 +1,572 | |||
|
1 | 1 | # Redmine - project management software |
|
2 | 2 | # Copyright (C) 2006-2012 Jean-Philippe Lang |
|
3 | 3 | # |
|
4 | 4 | # This program is free software; you can redistribute it and/or |
|
5 | 5 | # modify it under the terms of the GNU General Public License |
|
6 | 6 | # as published by the Free Software Foundation; either version 2 |
|
7 | 7 | # of the License, or (at your option) any later version. |
|
8 | 8 | # |
|
9 | 9 | # This program is distributed in the hope that it will be useful, |
|
10 | 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 | 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 | 12 | # GNU General Public License for more details. |
|
13 | 13 | # |
|
14 | 14 | # You should have received a copy of the GNU General Public License |
|
15 | 15 | # along with this program; if not, write to the Free Software |
|
16 | 16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
17 | 17 | |
|
18 | 18 | require File.expand_path('../../test_helper', __FILE__) |
|
19 | 19 | require 'projects_controller' |
|
20 | 20 | |
|
21 | 21 | # Re-raise errors caught by the controller. |
|
22 | 22 | class ProjectsController; def rescue_action(e) raise e end; end |
|
23 | 23 | |
|
24 | 24 | class ProjectsControllerTest < ActionController::TestCase |
|
25 | 25 | fixtures :projects, :versions, :users, :roles, :members, :member_roles, :issues, :journals, :journal_details, |
|
26 | 26 | :trackers, :projects_trackers, :issue_statuses, :enabled_modules, :enumerations, :boards, :messages, |
|
27 | 27 | :attachments, :custom_fields, :custom_values, :time_entries |
|
28 | 28 | |
|
29 | 29 | def setup |
|
30 | 30 | @controller = ProjectsController.new |
|
31 | 31 | @request = ActionController::TestRequest.new |
|
32 | 32 | @response = ActionController::TestResponse.new |
|
33 | 33 | @request.session[:user_id] = nil |
|
34 | 34 | Setting.default_language = 'en' |
|
35 | 35 | end |
|
36 | 36 | |
|
37 | 37 | def test_index |
|
38 | 38 | get :index |
|
39 | 39 | assert_response :success |
|
40 | 40 | assert_template 'index' |
|
41 | 41 | assert_not_nil assigns(:projects) |
|
42 | 42 | |
|
43 | 43 | assert_tag :ul, :child => {:tag => 'li', |
|
44 | 44 | :descendant => {:tag => 'a', :content => 'eCookbook'}, |
|
45 | 45 | :child => { :tag => 'ul', |
|
46 | 46 | :descendant => { :tag => 'a', |
|
47 | 47 | :content => 'Child of private child' |
|
48 | 48 | } |
|
49 | 49 | } |
|
50 | 50 | } |
|
51 | 51 | |
|
52 | 52 | assert_no_tag :a, :content => /Private child of eCookbook/ |
|
53 | 53 | end |
|
54 | 54 | |
|
55 | 55 | def test_index_atom |
|
56 | 56 | get :index, :format => 'atom' |
|
57 | 57 | assert_response :success |
|
58 | 58 | assert_template 'common/feed' |
|
59 | 59 | assert_select 'feed>title', :text => 'Redmine: Latest projects' |
|
60 | 60 | assert_select 'feed>entry', :count => Project.count(:conditions => Project.visible_condition(User.current)) |
|
61 | 61 | end |
|
62 | 62 | |
|
63 | 63 | context "#index" do |
|
64 | 64 | context "by non-admin user with view_time_entries permission" do |
|
65 | 65 | setup do |
|
66 | 66 | @request.session[:user_id] = 3 |
|
67 | 67 | end |
|
68 | 68 | should "show overall spent time link" do |
|
69 | 69 | get :index |
|
70 | 70 | assert_template 'index' |
|
71 | 71 | assert_tag :a, :attributes => {:href => '/time_entries'} |
|
72 | 72 | end |
|
73 | 73 | end |
|
74 | 74 | |
|
75 | 75 | context "by non-admin user without view_time_entries permission" do |
|
76 | 76 | setup do |
|
77 | 77 | Role.find(2).remove_permission! :view_time_entries |
|
78 | 78 | Role.non_member.remove_permission! :view_time_entries |
|
79 | 79 | Role.anonymous.remove_permission! :view_time_entries |
|
80 | 80 | @request.session[:user_id] = 3 |
|
81 | 81 | end |
|
82 | 82 | should "not show overall spent time link" do |
|
83 | 83 | get :index |
|
84 | 84 | assert_template 'index' |
|
85 | 85 | assert_no_tag :a, :attributes => {:href => '/time_entries'} |
|
86 | 86 | end |
|
87 | 87 | end |
|
88 | 88 | end |
|
89 | 89 | |
|
90 | 90 | context "#new" do |
|
91 | 91 | context "by admin user" do |
|
92 | 92 | setup do |
|
93 | 93 | @request.session[:user_id] = 1 |
|
94 | 94 | end |
|
95 | 95 | |
|
96 | 96 | should "accept get" do |
|
97 | 97 | get :new |
|
98 | 98 | assert_response :success |
|
99 | 99 | assert_template 'new' |
|
100 | 100 | end |
|
101 | 101 | |
|
102 | 102 | end |
|
103 | 103 | |
|
104 | 104 | context "by non-admin user with add_project permission" do |
|
105 | 105 | setup do |
|
106 | 106 | Role.non_member.add_permission! :add_project |
|
107 | 107 | @request.session[:user_id] = 9 |
|
108 | 108 | end |
|
109 | 109 | |
|
110 | 110 | should "accept get" do |
|
111 | 111 | get :new |
|
112 | 112 | assert_response :success |
|
113 | 113 | assert_template 'new' |
|
114 | 114 | assert_no_tag :select, :attributes => {:name => 'project[parent_id]'} |
|
115 | 115 | end |
|
116 | 116 | end |
|
117 | 117 | |
|
118 | 118 | context "by non-admin user with add_subprojects permission" do |
|
119 | 119 | setup do |
|
120 | 120 | Role.find(1).remove_permission! :add_project |
|
121 | 121 | Role.find(1).add_permission! :add_subprojects |
|
122 | 122 | @request.session[:user_id] = 2 |
|
123 | 123 | end |
|
124 | 124 | |
|
125 | 125 | should "accept get" do |
|
126 | 126 | get :new, :parent_id => 'ecookbook' |
|
127 | 127 | assert_response :success |
|
128 | 128 | assert_template 'new' |
|
129 | 129 | # parent project selected |
|
130 | 130 | assert_tag :select, :attributes => {:name => 'project[parent_id]'}, |
|
131 | 131 | :child => {:tag => 'option', :attributes => {:value => '1', :selected => 'selected'}} |
|
132 | 132 | # no empty value |
|
133 | 133 | assert_no_tag :select, :attributes => {:name => 'project[parent_id]'}, |
|
134 | 134 | :child => {:tag => 'option', :attributes => {:value => ''}} |
|
135 | 135 | end |
|
136 | 136 | end |
|
137 | 137 | |
|
138 | 138 | end |
|
139 | 139 | |
|
140 | 140 | context "POST :create" do |
|
141 | 141 | context "by admin user" do |
|
142 | 142 | setup do |
|
143 | 143 | @request.session[:user_id] = 1 |
|
144 | 144 | end |
|
145 | 145 | |
|
146 | 146 | should "create a new project" do |
|
147 | 147 | post :create, |
|
148 | 148 | :project => { |
|
149 | 149 | :name => "blog", |
|
150 | 150 | :description => "weblog", |
|
151 | 151 | :homepage => 'http://weblog', |
|
152 | 152 | :identifier => "blog", |
|
153 | 153 | :is_public => 1, |
|
154 | 154 | :custom_field_values => { '3' => 'Beta' }, |
|
155 | 155 | :tracker_ids => ['1', '3'], |
|
156 | 156 | # an issue custom field that is not for all project |
|
157 | 157 | :issue_custom_field_ids => ['9'], |
|
158 | 158 | :enabled_module_names => ['issue_tracking', 'news', 'repository'] |
|
159 | 159 | } |
|
160 | 160 | assert_redirected_to '/projects/blog/settings' |
|
161 | 161 | |
|
162 | 162 | project = Project.find_by_name('blog') |
|
163 | 163 | assert_kind_of Project, project |
|
164 | 164 | assert project.active? |
|
165 | 165 | assert_equal 'weblog', project.description |
|
166 | 166 | assert_equal 'http://weblog', project.homepage |
|
167 | 167 | assert_equal true, project.is_public? |
|
168 | 168 | assert_nil project.parent |
|
169 | 169 | assert_equal 'Beta', project.custom_value_for(3).value |
|
170 | 170 | assert_equal [1, 3], project.trackers.map(&:id).sort |
|
171 | 171 | assert_equal ['issue_tracking', 'news', 'repository'], project.enabled_module_names.sort |
|
172 | 172 | assert project.issue_custom_fields.include?(IssueCustomField.find(9)) |
|
173 | 173 | end |
|
174 | 174 | |
|
175 | 175 | should "create a new subproject" do |
|
176 | 176 | post :create, :project => { :name => "blog", |
|
177 | 177 | :description => "weblog", |
|
178 | 178 | :identifier => "blog", |
|
179 | 179 | :is_public => 1, |
|
180 | 180 | :custom_field_values => { '3' => 'Beta' }, |
|
181 | 181 | :parent_id => 1 |
|
182 | 182 | } |
|
183 | 183 | assert_redirected_to '/projects/blog/settings' |
|
184 | 184 | |
|
185 | 185 | project = Project.find_by_name('blog') |
|
186 | 186 | assert_kind_of Project, project |
|
187 | 187 | assert_equal Project.find(1), project.parent |
|
188 | 188 | end |
|
189 | 189 | |
|
190 | 190 | should "continue" do |
|
191 | 191 | assert_difference 'Project.count' do |
|
192 | 192 | post :create, :project => {:name => "blog", :identifier => "blog"}, :continue => 'Create and continue' |
|
193 | 193 | end |
|
194 | 194 | assert_redirected_to '/projects/new?' |
|
195 | 195 | end |
|
196 | 196 | end |
|
197 | 197 | |
|
198 | 198 | context "by non-admin user with add_project permission" do |
|
199 | 199 | setup do |
|
200 | 200 | Role.non_member.add_permission! :add_project |
|
201 | 201 | @request.session[:user_id] = 9 |
|
202 | 202 | end |
|
203 | 203 | |
|
204 | 204 | should "accept create a Project" do |
|
205 | 205 | post :create, :project => { :name => "blog", |
|
206 | 206 | :description => "weblog", |
|
207 | 207 | :identifier => "blog", |
|
208 | 208 | :is_public => 1, |
|
209 | 209 | :custom_field_values => { '3' => 'Beta' }, |
|
210 | 210 | :tracker_ids => ['1', '3'], |
|
211 | 211 | :enabled_module_names => ['issue_tracking', 'news', 'repository'] |
|
212 | 212 | } |
|
213 | 213 | |
|
214 | 214 | assert_redirected_to '/projects/blog/settings' |
|
215 | 215 | |
|
216 | 216 | project = Project.find_by_name('blog') |
|
217 | 217 | assert_kind_of Project, project |
|
218 | 218 | assert_equal 'weblog', project.description |
|
219 | 219 | assert_equal true, project.is_public? |
|
220 | 220 | assert_equal [1, 3], project.trackers.map(&:id).sort |
|
221 | 221 | assert_equal ['issue_tracking', 'news', 'repository'], project.enabled_module_names.sort |
|
222 | 222 | |
|
223 | 223 | # User should be added as a project member |
|
224 | 224 | assert User.find(9).member_of?(project) |
|
225 | 225 | assert_equal 1, project.members.size |
|
226 | 226 | end |
|
227 | 227 | |
|
228 | 228 | should "fail with parent_id" do |
|
229 | 229 | assert_no_difference 'Project.count' do |
|
230 | 230 | post :create, :project => { :name => "blog", |
|
231 | 231 | :description => "weblog", |
|
232 | 232 | :identifier => "blog", |
|
233 | 233 | :is_public => 1, |
|
234 | 234 | :custom_field_values => { '3' => 'Beta' }, |
|
235 | 235 | :parent_id => 1 |
|
236 | 236 | } |
|
237 | 237 | end |
|
238 | 238 | assert_response :success |
|
239 | 239 | project = assigns(:project) |
|
240 | 240 | assert_kind_of Project, project |
|
241 | 241 | assert_not_nil project.errors[:parent_id] |
|
242 | 242 | end |
|
243 | 243 | end |
|
244 | 244 | |
|
245 | 245 | context "by non-admin user with add_subprojects permission" do |
|
246 | 246 | setup do |
|
247 | 247 | Role.find(1).remove_permission! :add_project |
|
248 | 248 | Role.find(1).add_permission! :add_subprojects |
|
249 | 249 | @request.session[:user_id] = 2 |
|
250 | 250 | end |
|
251 | 251 | |
|
252 | 252 | should "create a project with a parent_id" do |
|
253 | 253 | post :create, :project => { :name => "blog", |
|
254 | 254 | :description => "weblog", |
|
255 | 255 | :identifier => "blog", |
|
256 | 256 | :is_public => 1, |
|
257 | 257 | :custom_field_values => { '3' => 'Beta' }, |
|
258 | 258 | :parent_id => 1 |
|
259 | 259 | } |
|
260 | 260 | assert_redirected_to '/projects/blog/settings' |
|
261 | 261 | project = Project.find_by_name('blog') |
|
262 | 262 | end |
|
263 | 263 | |
|
264 | 264 | should "fail without parent_id" do |
|
265 | 265 | assert_no_difference 'Project.count' do |
|
266 | 266 | post :create, :project => { :name => "blog", |
|
267 | 267 | :description => "weblog", |
|
268 | 268 | :identifier => "blog", |
|
269 | 269 | :is_public => 1, |
|
270 | 270 | :custom_field_values => { '3' => 'Beta' } |
|
271 | 271 | } |
|
272 | 272 | end |
|
273 | 273 | assert_response :success |
|
274 | 274 | project = assigns(:project) |
|
275 | 275 | assert_kind_of Project, project |
|
276 | 276 | assert_not_nil project.errors[:parent_id] |
|
277 | 277 | end |
|
278 | 278 | |
|
279 | 279 | should "fail with unauthorized parent_id" do |
|
280 | 280 | assert !User.find(2).member_of?(Project.find(6)) |
|
281 | 281 | assert_no_difference 'Project.count' do |
|
282 | 282 | post :create, :project => { :name => "blog", |
|
283 | 283 | :description => "weblog", |
|
284 | 284 | :identifier => "blog", |
|
285 | 285 | :is_public => 1, |
|
286 | 286 | :custom_field_values => { '3' => 'Beta' }, |
|
287 | 287 | :parent_id => 6 |
|
288 | 288 | } |
|
289 | 289 | end |
|
290 | 290 | assert_response :success |
|
291 | 291 | project = assigns(:project) |
|
292 | 292 | assert_kind_of Project, project |
|
293 | 293 | assert_not_nil project.errors[:parent_id] |
|
294 | 294 | end |
|
295 | 295 | end |
|
296 | 296 | end |
|
297 | 297 | |
|
298 | 298 | def test_create_should_preserve_modules_on_validation_failure |
|
299 | 299 | with_settings :default_projects_modules => ['issue_tracking', 'repository'] do |
|
300 | 300 | @request.session[:user_id] = 1 |
|
301 | 301 | assert_no_difference 'Project.count' do |
|
302 | 302 | post :create, :project => { |
|
303 | 303 | :name => "blog", |
|
304 | 304 | :identifier => "", |
|
305 | 305 | :enabled_module_names => %w(issue_tracking news) |
|
306 | 306 | } |
|
307 | 307 | end |
|
308 | 308 | assert_response :success |
|
309 | 309 | project = assigns(:project) |
|
310 | 310 | assert_equal %w(issue_tracking news), project.enabled_module_names.sort |
|
311 | 311 | end |
|
312 | 312 | end |
|
313 | 313 | |
|
314 | 314 | def test_show_by_id |
|
315 | 315 | get :show, :id => 1 |
|
316 | 316 | assert_response :success |
|
317 | 317 | assert_template 'show' |
|
318 | 318 | assert_not_nil assigns(:project) |
|
319 | 319 | end |
|
320 | 320 | |
|
321 | 321 | def test_show_by_identifier |
|
322 | 322 | get :show, :id => 'ecookbook' |
|
323 | 323 | assert_response :success |
|
324 | 324 | assert_template 'show' |
|
325 | 325 | assert_not_nil assigns(:project) |
|
326 | 326 | assert_equal Project.find_by_identifier('ecookbook'), assigns(:project) |
|
327 | 327 | |
|
328 | 328 | assert_tag 'li', :content => /Development status/ |
|
329 | 329 | end |
|
330 | 330 | |
|
331 | 331 | def test_show_should_not_display_hidden_custom_fields |
|
332 | 332 | ProjectCustomField.find_by_name('Development status').update_attribute :visible, false |
|
333 | 333 | get :show, :id => 'ecookbook' |
|
334 | 334 | assert_response :success |
|
335 | 335 | assert_template 'show' |
|
336 | 336 | assert_not_nil assigns(:project) |
|
337 | 337 | |
|
338 | 338 | assert_no_tag 'li', :content => /Development status/ |
|
339 | 339 | end |
|
340 | 340 | |
|
341 | 341 | def test_show_should_not_fail_when_custom_values_are_nil |
|
342 | 342 | project = Project.find_by_identifier('ecookbook') |
|
343 | 343 | project.custom_values.first.update_attribute(:value, nil) |
|
344 | 344 | get :show, :id => 'ecookbook' |
|
345 | 345 | assert_response :success |
|
346 | 346 | assert_template 'show' |
|
347 | 347 | assert_not_nil assigns(:project) |
|
348 | 348 | assert_equal Project.find_by_identifier('ecookbook'), assigns(:project) |
|
349 | 349 | end |
|
350 | 350 | |
|
351 | 351 | def show_archived_project_should_be_denied |
|
352 | 352 | project = Project.find_by_identifier('ecookbook') |
|
353 | 353 | project.archive! |
|
354 | 354 | |
|
355 | 355 | get :show, :id => 'ecookbook' |
|
356 | 356 | assert_response 403 |
|
357 | 357 | assert_nil assigns(:project) |
|
358 | 358 | assert_tag :tag => 'p', :content => /archived/ |
|
359 | 359 | end |
|
360 | 360 | |
|
361 | 361 | def test_private_subprojects_hidden |
|
362 | 362 | get :show, :id => 'ecookbook' |
|
363 | 363 | assert_response :success |
|
364 | 364 | assert_template 'show' |
|
365 | 365 | assert_no_tag :tag => 'a', :content => /Private child/ |
|
366 | 366 | end |
|
367 | 367 | |
|
368 | 368 | def test_private_subprojects_visible |
|
369 | 369 | @request.session[:user_id] = 2 # manager who is a member of the private subproject |
|
370 | 370 | get :show, :id => 'ecookbook' |
|
371 | 371 | assert_response :success |
|
372 | 372 | assert_template 'show' |
|
373 | 373 | assert_tag :tag => 'a', :content => /Private child/ |
|
374 | 374 | end |
|
375 | 375 | |
|
376 | 376 | def test_settings |
|
377 | 377 | @request.session[:user_id] = 2 # manager |
|
378 | 378 | get :settings, :id => 1 |
|
379 | 379 | assert_response :success |
|
380 | 380 | assert_template 'settings' |
|
381 | 381 | end |
|
382 | 382 | |
|
383 | 383 | def test_settings_should_be_denied_for_member_on_closed_project |
|
384 | 384 | Project.find(1).close |
|
385 | 385 | @request.session[:user_id] = 2 # manager |
|
386 | 386 | |
|
387 | 387 | get :settings, :id => 1 |
|
388 | 388 | assert_response 403 |
|
389 | 389 | end |
|
390 | 390 | |
|
391 | 391 | def test_settings_should_be_denied_for_anonymous_on_closed_project |
|
392 | 392 | Project.find(1).close |
|
393 | 393 | |
|
394 | 394 | get :settings, :id => 1 |
|
395 | 395 | assert_response 302 |
|
396 | 396 | end |
|
397 | 397 | |
|
398 | 398 | def test_update |
|
399 | 399 | @request.session[:user_id] = 2 # manager |
|
400 | 400 | post :update, :id => 1, :project => {:name => 'Test changed name', |
|
401 | 401 | :issue_custom_field_ids => ['']} |
|
402 | 402 | assert_redirected_to '/projects/ecookbook/settings' |
|
403 | 403 | project = Project.find(1) |
|
404 | 404 | assert_equal 'Test changed name', project.name |
|
405 | 405 | end |
|
406 | 406 | |
|
407 | 407 | def test_update_with_failure |
|
408 | 408 | @request.session[:user_id] = 2 # manager |
|
409 | 409 | post :update, :id => 1, :project => {:name => ''} |
|
410 | 410 | assert_response :success |
|
411 | 411 | assert_template 'settings' |
|
412 | 412 | assert_error_tag :content => /name can't be blank/i |
|
413 | 413 | end |
|
414 | 414 | |
|
415 | 415 | def test_update_should_be_denied_for_member_on_closed_project |
|
416 | 416 | Project.find(1).close |
|
417 | 417 | @request.session[:user_id] = 2 # manager |
|
418 | 418 | |
|
419 | 419 | post :update, :id => 1, :project => {:name => 'Closed'} |
|
420 | 420 | assert_response 403 |
|
421 | 421 | assert_equal 'eCookbook', Project.find(1).name |
|
422 | 422 | end |
|
423 | 423 | |
|
424 | 424 | def test_update_should_be_denied_for_anonymous_on_closed_project |
|
425 | 425 | Project.find(1).close |
|
426 | 426 | |
|
427 | 427 | post :update, :id => 1, :project => {:name => 'Closed'} |
|
428 | 428 | assert_response 302 |
|
429 | 429 | assert_equal 'eCookbook', Project.find(1).name |
|
430 | 430 | end |
|
431 | 431 | |
|
432 | 432 | def test_modules |
|
433 | 433 | @request.session[:user_id] = 2 |
|
434 | 434 | Project.find(1).enabled_module_names = ['issue_tracking', 'news'] |
|
435 | 435 | |
|
436 | 436 | post :modules, :id => 1, :enabled_module_names => ['issue_tracking', 'repository', 'documents'] |
|
437 | 437 | assert_redirected_to '/projects/ecookbook/settings/modules' |
|
438 | 438 | assert_equal ['documents', 'issue_tracking', 'repository'], Project.find(1).enabled_module_names.sort |
|
439 | 439 | end |
|
440 | 440 | |
|
441 | 441 | def test_destroy_without_confirmation |
|
442 | 442 | @request.session[:user_id] = 1 # admin |
|
443 | 443 | delete :destroy, :id => 1 |
|
444 | 444 | assert_response :success |
|
445 | 445 | assert_template 'destroy' |
|
446 | 446 | assert_not_nil Project.find_by_id(1) |
|
447 | 447 | assert_tag :tag => 'strong', |
|
448 | 448 | :content => ['Private child of eCookbook', |
|
449 | 449 | 'Child of private child, eCookbook Subproject 1', |
|
450 | 450 | 'eCookbook Subproject 2'].join(', ') |
|
451 | 451 | end |
|
452 | 452 | |
|
453 | 453 | def test_destroy |
|
454 | 454 | @request.session[:user_id] = 1 # admin |
|
455 | 455 | delete :destroy, :id => 1, :confirm => 1 |
|
456 | 456 | assert_redirected_to '/admin/projects' |
|
457 | 457 | assert_nil Project.find_by_id(1) |
|
458 | 458 | end |
|
459 | 459 | |
|
460 | 460 | def test_archive |
|
461 | 461 | @request.session[:user_id] = 1 # admin |
|
462 | 462 | post :archive, :id => 1 |
|
463 | 463 | assert_redirected_to '/admin/projects' |
|
464 | 464 | assert !Project.find(1).active? |
|
465 | 465 | end |
|
466 | 466 | |
|
467 | 467 | def test_archive_with_failure |
|
468 | 468 | @request.session[:user_id] = 1 |
|
469 | 469 | Project.any_instance.stubs(:archive).returns(false) |
|
470 | 470 | post :archive, :id => 1 |
|
471 | 471 | assert_redirected_to '/admin/projects' |
|
472 | 472 | assert_match /project cannot be archived/i, flash[:error] |
|
473 | 473 | end |
|
474 | 474 | |
|
475 | 475 | def test_unarchive |
|
476 | 476 | @request.session[:user_id] = 1 # admin |
|
477 | 477 | Project.find(1).archive |
|
478 | 478 | post :unarchive, :id => 1 |
|
479 | 479 | assert_redirected_to '/admin/projects' |
|
480 | 480 | assert Project.find(1).active? |
|
481 | 481 | end |
|
482 | 482 | |
|
483 | 483 | def test_close |
|
484 | 484 | @request.session[:user_id] = 2 |
|
485 | 485 | post :close, :id => 1 |
|
486 | 486 | assert_redirected_to '/projects/ecookbook' |
|
487 | 487 | assert_equal Project::STATUS_CLOSED, Project.find(1).status |
|
488 | 488 | end |
|
489 | 489 | |
|
490 | 490 | def test_reopen |
|
491 | 491 | Project.find(1).close |
|
492 | 492 | @request.session[:user_id] = 2 |
|
493 | 493 | post :reopen, :id => 1 |
|
494 | 494 | assert_redirected_to '/projects/ecookbook' |
|
495 | 495 | assert Project.find(1).active? |
|
496 | 496 | end |
|
497 | 497 | |
|
498 | 498 | def test_project_breadcrumbs_should_be_limited_to_3_ancestors |
|
499 | 499 | CustomField.delete_all |
|
500 | 500 | parent = nil |
|
501 | 501 | 6.times do |i| |
|
502 | 502 | p = Project.create!(:name => "Breadcrumbs #{i}", :identifier => "breadcrumbs-#{i}") |
|
503 | 503 | p.set_parent!(parent) |
|
504 | 504 | get :show, :id => p |
|
505 | 505 | assert_tag :h1, :parent => { :attributes => {:id => 'header'}}, |
|
506 | 506 | :children => { :count => [i, 3].min, |
|
507 | 507 | :only => { :tag => 'a' } } |
|
508 | 508 | |
|
509 | 509 | parent = p |
|
510 | 510 | end |
|
511 | 511 | end |
|
512 | 512 | |
|
513 | 513 | def test_get_copy |
|
514 | 514 | @request.session[:user_id] = 1 # admin |
|
515 | 515 | get :copy, :id => 1 |
|
516 | 516 | assert_response :success |
|
517 | 517 | assert_template 'copy' |
|
518 | 518 | assert assigns(:project) |
|
519 | 519 | assert_equal Project.find(1).description, assigns(:project).description |
|
520 | 520 | assert_nil assigns(:project).id |
|
521 | 521 | |
|
522 | 522 | assert_tag :tag => 'input', |
|
523 | 523 | :attributes => {:name => 'project[enabled_module_names][]', :value => 'issue_tracking'} |
|
524 | 524 | end |
|
525 | 525 | |
|
526 | 526 | def test_post_copy_should_copy_requested_items |
|
527 | 527 | @request.session[:user_id] = 1 # admin |
|
528 | 528 | CustomField.delete_all |
|
529 | 529 | |
|
530 | 530 | assert_difference 'Project.count' do |
|
531 | 531 | post :copy, :id => 1, |
|
532 | 532 | :project => { |
|
533 | 533 | :name => 'Copy', |
|
534 | 534 | :identifier => 'unique-copy', |
|
535 | 535 | :tracker_ids => ['1', '2', '3', ''], |
|
536 | 536 | :enabled_module_names => %w(issue_tracking time_tracking) |
|
537 | 537 | }, |
|
538 | 538 | :only => %w(issues versions) |
|
539 | 539 | end |
|
540 | 540 | project = Project.find('unique-copy') |
|
541 | 541 | source = Project.find(1) |
|
542 | 542 | assert_equal %w(issue_tracking time_tracking), project.enabled_module_names.sort |
|
543 | 543 | |
|
544 | 544 | assert_equal source.versions.count, project.versions.count, "All versions were not copied" |
|
545 | # issues assigned to a closed version won't be copied | |
|
546 | assert_equal source.issues.select {|i| i.fixed_version.nil? || i.fixed_version.open?}.size, | |
|
547 | project.issues.count, "All issues were not copied" | |
|
545 | assert_equal source.issues.count, project.issues.count, "All issues were not copied" | |
|
548 | 546 | assert_equal 0, project.members.count |
|
549 | 547 | end |
|
550 | 548 | |
|
551 | 549 | def test_post_copy_should_redirect_to_settings_when_successful |
|
552 | 550 | @request.session[:user_id] = 1 # admin |
|
553 | 551 | post :copy, :id => 1, :project => {:name => 'Copy', :identifier => 'unique-copy'} |
|
554 | 552 | assert_response :redirect |
|
555 | 553 | assert_redirected_to :controller => 'projects', :action => 'settings', :id => 'unique-copy' |
|
556 | 554 | end |
|
557 | 555 | |
|
558 | 556 | def test_jump_should_redirect_to_active_tab |
|
559 | 557 | get :show, :id => 1, :jump => 'issues' |
|
560 | 558 | assert_redirected_to '/projects/ecookbook/issues' |
|
561 | 559 | end |
|
562 | 560 | |
|
563 | 561 | def test_jump_should_not_redirect_to_inactive_tab |
|
564 | 562 | get :show, :id => 3, :jump => 'documents' |
|
565 | 563 | assert_response :success |
|
566 | 564 | assert_template 'show' |
|
567 | 565 | end |
|
568 | 566 | |
|
569 | 567 | def test_jump_should_not_redirect_to_unknown_tab |
|
570 | 568 | get :show, :id => 3, :jump => 'foobar' |
|
571 | 569 | assert_response :success |
|
572 | 570 | assert_template 'show' |
|
573 | 571 | end |
|
574 | 572 | end |
General Comments 0
You need to be logged in to leave comments.
Login now