Mercurial > hg > soundsoftware-site
comparison .svn/pristine/c6/c63c3cd61fc296170b8167aad5904de39c22ed23.svn-base @ 1517:dffacf8a6908 redmine-2.5
Update to Redmine SVN revision 13367 on 2.5-stable branch
author | Chris Cannam |
---|---|
date | Tue, 09 Sep 2014 09:29:00 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
1516:b450a9d58aed | 1517:dffacf8a6908 |
---|---|
1 # Redmine - project management software | |
2 # Copyright (C) 2006-2014 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 | |
20 class ProjectsControllerTest < ActionController::TestCase | |
21 fixtures :projects, :versions, :users, :roles, :members, | |
22 :member_roles, :issues, :journals, :journal_details, | |
23 :trackers, :projects_trackers, :issue_statuses, | |
24 :enabled_modules, :enumerations, :boards, :messages, | |
25 :attachments, :custom_fields, :custom_values, :time_entries | |
26 | |
27 def setup | |
28 @request.session[:user_id] = nil | |
29 Setting.default_language = 'en' | |
30 end | |
31 | |
32 def test_index_by_anonymous_should_not_show_private_projects | |
33 get :index | |
34 assert_response :success | |
35 assert_template 'index' | |
36 projects = assigns(:projects) | |
37 assert_not_nil projects | |
38 assert projects.all?(&:is_public?) | |
39 | |
40 assert_select 'ul' do | |
41 assert_select 'li' do | |
42 assert_select 'a', :text => 'eCookbook' | |
43 assert_select 'ul' do | |
44 assert_select 'a', :text => 'Child of private child' | |
45 end | |
46 end | |
47 end | |
48 assert_select 'a', :text => /Private child of eCookbook/, :count => 0 | |
49 end | |
50 | |
51 def test_index_atom | |
52 get :index, :format => 'atom' | |
53 assert_response :success | |
54 assert_template 'common/feed' | |
55 assert_select 'feed>title', :text => 'Redmine: Latest projects' | |
56 assert_select 'feed>entry', :count => Project.visible(User.current).count | |
57 end | |
58 | |
59 test "#index by non-admin user with view_time_entries permission should show overall spent time link" do | |
60 @request.session[:user_id] = 3 | |
61 get :index | |
62 assert_template 'index' | |
63 assert_select 'a[href=?]', '/time_entries' | |
64 end | |
65 | |
66 test "#index by non-admin user without view_time_entries permission should not show overall spent time link" do | |
67 Role.find(2).remove_permission! :view_time_entries | |
68 Role.non_member.remove_permission! :view_time_entries | |
69 Role.anonymous.remove_permission! :view_time_entries | |
70 @request.session[:user_id] = 3 | |
71 | |
72 get :index | |
73 assert_template 'index' | |
74 assert_select 'a[href=?]', '/time_entries', 0 | |
75 end | |
76 | |
77 test "#new by admin user should accept get" do | |
78 @request.session[:user_id] = 1 | |
79 | |
80 get :new | |
81 assert_response :success | |
82 assert_template 'new' | |
83 end | |
84 | |
85 test "#new by non-admin user with add_project permission should accept get" do | |
86 Role.non_member.add_permission! :add_project | |
87 @request.session[:user_id] = 9 | |
88 | |
89 get :new | |
90 assert_response :success | |
91 assert_template 'new' | |
92 assert_select 'select[name=?]', 'project[parent_id]', 0 | |
93 end | |
94 | |
95 test "#new by non-admin user with add_subprojects permission should accept get" do | |
96 Role.find(1).remove_permission! :add_project | |
97 Role.find(1).add_permission! :add_subprojects | |
98 @request.session[:user_id] = 2 | |
99 | |
100 get :new, :parent_id => 'ecookbook' | |
101 assert_response :success | |
102 assert_template 'new' | |
103 | |
104 assert_select 'select[name=?]', 'project[parent_id]' do | |
105 # parent project selected | |
106 assert_select 'option[value=1][selected=selected]' | |
107 # no empty value | |
108 assert_select 'option[value=]', 0 | |
109 end | |
110 end | |
111 | |
112 test "#create by admin user should create a new project" do | |
113 @request.session[:user_id] = 1 | |
114 | |
115 post :create, | |
116 :project => { | |
117 :name => "blog", | |
118 :description => "weblog", | |
119 :homepage => 'http://weblog', | |
120 :identifier => "blog", | |
121 :is_public => 1, | |
122 :custom_field_values => { '3' => 'Beta' }, | |
123 :tracker_ids => ['1', '3'], | |
124 # an issue custom field that is not for all project | |
125 :issue_custom_field_ids => ['9'], | |
126 :enabled_module_names => ['issue_tracking', 'news', 'repository'] | |
127 } | |
128 assert_redirected_to '/projects/blog/settings' | |
129 | |
130 project = Project.find_by_name('blog') | |
131 assert_kind_of Project, project | |
132 assert project.active? | |
133 assert_equal 'weblog', project.description | |
134 assert_equal 'http://weblog', project.homepage | |
135 assert_equal true, project.is_public? | |
136 assert_nil project.parent | |
137 assert_equal 'Beta', project.custom_value_for(3).value | |
138 assert_equal [1, 3], project.trackers.map(&:id).sort | |
139 assert_equal ['issue_tracking', 'news', 'repository'], project.enabled_module_names.sort | |
140 assert project.issue_custom_fields.include?(IssueCustomField.find(9)) | |
141 end | |
142 | |
143 test "#create by admin user should create a new subproject" do | |
144 @request.session[:user_id] = 1 | |
145 | |
146 assert_difference 'Project.count' do | |
147 post :create, :project => { :name => "blog", | |
148 :description => "weblog", | |
149 :identifier => "blog", | |
150 :is_public => 1, | |
151 :custom_field_values => { '3' => 'Beta' }, | |
152 :parent_id => 1 | |
153 } | |
154 assert_redirected_to '/projects/blog/settings' | |
155 end | |
156 | |
157 project = Project.find_by_name('blog') | |
158 assert_kind_of Project, project | |
159 assert_equal Project.find(1), project.parent | |
160 end | |
161 | |
162 test "#create by admin user should continue" do | |
163 @request.session[:user_id] = 1 | |
164 | |
165 assert_difference 'Project.count' do | |
166 post :create, :project => {:name => "blog", :identifier => "blog"}, :continue => 'Create and continue' | |
167 end | |
168 assert_redirected_to '/projects/new' | |
169 end | |
170 | |
171 test "#create by non-admin user with add_project permission should create a new project" do | |
172 Role.non_member.add_permission! :add_project | |
173 @request.session[:user_id] = 9 | |
174 | |
175 post :create, :project => { :name => "blog", | |
176 :description => "weblog", | |
177 :identifier => "blog", | |
178 :is_public => 1, | |
179 :custom_field_values => { '3' => 'Beta' }, | |
180 :tracker_ids => ['1', '3'], | |
181 :enabled_module_names => ['issue_tracking', 'news', 'repository'] | |
182 } | |
183 | |
184 assert_redirected_to '/projects/blog/settings' | |
185 | |
186 project = Project.find_by_name('blog') | |
187 assert_kind_of Project, project | |
188 assert_equal 'weblog', project.description | |
189 assert_equal true, project.is_public? | |
190 assert_equal [1, 3], project.trackers.map(&:id).sort | |
191 assert_equal ['issue_tracking', 'news', 'repository'], project.enabled_module_names.sort | |
192 | |
193 # User should be added as a project member | |
194 assert User.find(9).member_of?(project) | |
195 assert_equal 1, project.members.size | |
196 end | |
197 | |
198 test "#create by non-admin user with add_project permission should fail with parent_id" do | |
199 Role.non_member.add_permission! :add_project | |
200 @request.session[:user_id] = 9 | |
201 | |
202 assert_no_difference 'Project.count' do | |
203 post :create, :project => { :name => "blog", | |
204 :description => "weblog", | |
205 :identifier => "blog", | |
206 :is_public => 1, | |
207 :custom_field_values => { '3' => 'Beta' }, | |
208 :parent_id => 1 | |
209 } | |
210 end | |
211 assert_response :success | |
212 project = assigns(:project) | |
213 assert_kind_of Project, project | |
214 assert_not_equal [], project.errors[:parent_id] | |
215 end | |
216 | |
217 test "#create by non-admin user with add_subprojects permission should create a project with a parent_id" do | |
218 Role.find(1).remove_permission! :add_project | |
219 Role.find(1).add_permission! :add_subprojects | |
220 @request.session[:user_id] = 2 | |
221 | |
222 post :create, :project => { :name => "blog", | |
223 :description => "weblog", | |
224 :identifier => "blog", | |
225 :is_public => 1, | |
226 :custom_field_values => { '3' => 'Beta' }, | |
227 :parent_id => 1 | |
228 } | |
229 assert_redirected_to '/projects/blog/settings' | |
230 project = Project.find_by_name('blog') | |
231 end | |
232 | |
233 test "#create by non-admin user with add_subprojects permission should fail without parent_id" do | |
234 Role.find(1).remove_permission! :add_project | |
235 Role.find(1).add_permission! :add_subprojects | |
236 @request.session[:user_id] = 2 | |
237 | |
238 assert_no_difference 'Project.count' do | |
239 post :create, :project => { :name => "blog", | |
240 :description => "weblog", | |
241 :identifier => "blog", | |
242 :is_public => 1, | |
243 :custom_field_values => { '3' => 'Beta' } | |
244 } | |
245 end | |
246 assert_response :success | |
247 project = assigns(:project) | |
248 assert_kind_of Project, project | |
249 assert_not_equal [], project.errors[:parent_id] | |
250 end | |
251 | |
252 test "#create by non-admin user with add_subprojects permission should fail with unauthorized parent_id" do | |
253 Role.find(1).remove_permission! :add_project | |
254 Role.find(1).add_permission! :add_subprojects | |
255 @request.session[:user_id] = 2 | |
256 | |
257 assert !User.find(2).member_of?(Project.find(6)) | |
258 assert_no_difference 'Project.count' do | |
259 post :create, :project => { :name => "blog", | |
260 :description => "weblog", | |
261 :identifier => "blog", | |
262 :is_public => 1, | |
263 :custom_field_values => { '3' => 'Beta' }, | |
264 :parent_id => 6 | |
265 } | |
266 end | |
267 assert_response :success | |
268 project = assigns(:project) | |
269 assert_kind_of Project, project | |
270 assert_not_equal [], project.errors[:parent_id] | |
271 end | |
272 | |
273 def test_create_subproject_with_inherit_members_should_inherit_members | |
274 Role.find_by_name('Manager').add_permission! :add_subprojects | |
275 parent = Project.find(1) | |
276 @request.session[:user_id] = 2 | |
277 | |
278 assert_difference 'Project.count' do | |
279 post :create, :project => { | |
280 :name => 'inherited', :identifier => 'inherited', :parent_id => parent.id, :inherit_members => '1' | |
281 } | |
282 assert_response 302 | |
283 end | |
284 | |
285 project = Project.order('id desc').first | |
286 assert_equal 'inherited', project.name | |
287 assert_equal parent, project.parent | |
288 assert project.memberships.count > 0 | |
289 assert_equal parent.memberships.count, project.memberships.count | |
290 end | |
291 | |
292 def test_create_should_preserve_modules_on_validation_failure | |
293 with_settings :default_projects_modules => ['issue_tracking', 'repository'] do | |
294 @request.session[:user_id] = 1 | |
295 assert_no_difference 'Project.count' do | |
296 post :create, :project => { | |
297 :name => "blog", | |
298 :identifier => "", | |
299 :enabled_module_names => %w(issue_tracking news) | |
300 } | |
301 end | |
302 assert_response :success | |
303 project = assigns(:project) | |
304 assert_equal %w(issue_tracking news), project.enabled_module_names.sort | |
305 end | |
306 end | |
307 | |
308 def test_show_by_id | |
309 get :show, :id => 1 | |
310 assert_response :success | |
311 assert_template 'show' | |
312 assert_not_nil assigns(:project) | |
313 end | |
314 | |
315 def test_show_by_identifier | |
316 get :show, :id => 'ecookbook' | |
317 assert_response :success | |
318 assert_template 'show' | |
319 assert_not_nil assigns(:project) | |
320 assert_equal Project.find_by_identifier('ecookbook'), assigns(:project) | |
321 | |
322 assert_select 'li', :text => /Development status/ | |
323 end | |
324 | |
325 def test_show_should_not_display_empty_sidebar | |
326 p = Project.find(1) | |
327 p.enabled_module_names = [] | |
328 p.save! | |
329 | |
330 get :show, :id => 'ecookbook' | |
331 assert_response :success | |
332 assert_select '#main.nosidebar' | |
333 end | |
334 | |
335 def test_show_should_not_display_hidden_custom_fields | |
336 ProjectCustomField.find_by_name('Development status').update_attribute :visible, false | |
337 get :show, :id => 'ecookbook' | |
338 assert_response :success | |
339 assert_template 'show' | |
340 assert_not_nil assigns(:project) | |
341 | |
342 assert_select 'li', :text => /Development status/, :count => 0 | |
343 end | |
344 | |
345 def test_show_should_not_fail_when_custom_values_are_nil | |
346 project = Project.find_by_identifier('ecookbook') | |
347 project.custom_values.first.update_attribute(:value, nil) | |
348 get :show, :id => 'ecookbook' | |
349 assert_response :success | |
350 assert_template 'show' | |
351 assert_not_nil assigns(:project) | |
352 assert_equal Project.find_by_identifier('ecookbook'), assigns(:project) | |
353 end | |
354 | |
355 def show_archived_project_should_be_denied | |
356 project = Project.find_by_identifier('ecookbook') | |
357 project.archive! | |
358 | |
359 get :show, :id => 'ecookbook' | |
360 assert_response 403 | |
361 assert_nil assigns(:project) | |
362 assert_select 'p', :text => /archived/ | |
363 end | |
364 | |
365 def test_show_should_not_show_private_subprojects_that_are_not_visible | |
366 get :show, :id => 'ecookbook' | |
367 assert_response :success | |
368 assert_template 'show' | |
369 assert_select 'a', :text => /Private child/, :count => 0 | |
370 end | |
371 | |
372 def test_show_should_show_private_subprojects_that_are_visible | |
373 @request.session[:user_id] = 2 # manager who is a member of the private subproject | |
374 get :show, :id => 'ecookbook' | |
375 assert_response :success | |
376 assert_template 'show' | |
377 assert_select 'a', :text => /Private child/ | |
378 end | |
379 | |
380 def test_settings | |
381 @request.session[:user_id] = 2 # manager | |
382 get :settings, :id => 1 | |
383 assert_response :success | |
384 assert_template 'settings' | |
385 end | |
386 | |
387 def test_settings_of_subproject | |
388 @request.session[:user_id] = 2 | |
389 get :settings, :id => 'private-child' | |
390 assert_response :success | |
391 assert_template 'settings' | |
392 | |
393 assert_select 'input[type=checkbox][name=?]', 'project[inherit_members]' | |
394 end | |
395 | |
396 def test_settings_should_be_denied_for_member_on_closed_project | |
397 Project.find(1).close | |
398 @request.session[:user_id] = 2 # manager | |
399 | |
400 get :settings, :id => 1 | |
401 assert_response 403 | |
402 end | |
403 | |
404 def test_settings_should_be_denied_for_anonymous_on_closed_project | |
405 Project.find(1).close | |
406 | |
407 get :settings, :id => 1 | |
408 assert_response 302 | |
409 end | |
410 | |
411 def test_update | |
412 @request.session[:user_id] = 2 # manager | |
413 post :update, :id => 1, :project => {:name => 'Test changed name', | |
414 :issue_custom_field_ids => ['']} | |
415 assert_redirected_to '/projects/ecookbook/settings' | |
416 project = Project.find(1) | |
417 assert_equal 'Test changed name', project.name | |
418 end | |
419 | |
420 def test_update_with_failure | |
421 @request.session[:user_id] = 2 # manager | |
422 post :update, :id => 1, :project => {:name => ''} | |
423 assert_response :success | |
424 assert_template 'settings' | |
425 assert_error_tag :content => /name #{ESCAPED_CANT} be blank/i | |
426 end | |
427 | |
428 def test_update_should_be_denied_for_member_on_closed_project | |
429 Project.find(1).close | |
430 @request.session[:user_id] = 2 # manager | |
431 | |
432 post :update, :id => 1, :project => {:name => 'Closed'} | |
433 assert_response 403 | |
434 assert_equal 'eCookbook', Project.find(1).name | |
435 end | |
436 | |
437 def test_update_should_be_denied_for_anonymous_on_closed_project | |
438 Project.find(1).close | |
439 | |
440 post :update, :id => 1, :project => {:name => 'Closed'} | |
441 assert_response 302 | |
442 assert_equal 'eCookbook', Project.find(1).name | |
443 end | |
444 | |
445 def test_modules | |
446 @request.session[:user_id] = 2 | |
447 Project.find(1).enabled_module_names = ['issue_tracking', 'news'] | |
448 | |
449 post :modules, :id => 1, :enabled_module_names => ['issue_tracking', 'repository', 'documents'] | |
450 assert_redirected_to '/projects/ecookbook/settings/modules' | |
451 assert_equal ['documents', 'issue_tracking', 'repository'], Project.find(1).enabled_module_names.sort | |
452 end | |
453 | |
454 def test_destroy_leaf_project_without_confirmation_should_show_confirmation | |
455 @request.session[:user_id] = 1 # admin | |
456 | |
457 assert_no_difference 'Project.count' do | |
458 delete :destroy, :id => 2 | |
459 assert_response :success | |
460 assert_template 'destroy' | |
461 end | |
462 end | |
463 | |
464 def test_destroy_without_confirmation_should_show_confirmation_with_subprojects | |
465 @request.session[:user_id] = 1 # admin | |
466 | |
467 assert_no_difference 'Project.count' do | |
468 delete :destroy, :id => 1 | |
469 assert_response :success | |
470 assert_template 'destroy' | |
471 end | |
472 assert_select 'strong', | |
473 :text => ['Private child of eCookbook', | |
474 'Child of private child, eCookbook Subproject 1', | |
475 'eCookbook Subproject 2'].join(', ') | |
476 end | |
477 | |
478 def test_destroy_with_confirmation_should_destroy_the_project_and_subprojects | |
479 @request.session[:user_id] = 1 # admin | |
480 | |
481 assert_difference 'Project.count', -5 do | |
482 delete :destroy, :id => 1, :confirm => 1 | |
483 assert_redirected_to '/admin/projects' | |
484 end | |
485 assert_nil Project.find_by_id(1) | |
486 end | |
487 | |
488 def test_archive | |
489 @request.session[:user_id] = 1 # admin | |
490 post :archive, :id => 1 | |
491 assert_redirected_to '/admin/projects' | |
492 assert !Project.find(1).active? | |
493 end | |
494 | |
495 def test_archive_with_failure | |
496 @request.session[:user_id] = 1 | |
497 Project.any_instance.stubs(:archive).returns(false) | |
498 post :archive, :id => 1 | |
499 assert_redirected_to '/admin/projects' | |
500 assert_match /project cannot be archived/i, flash[:error] | |
501 end | |
502 | |
503 def test_unarchive | |
504 @request.session[:user_id] = 1 # admin | |
505 Project.find(1).archive | |
506 post :unarchive, :id => 1 | |
507 assert_redirected_to '/admin/projects' | |
508 assert Project.find(1).active? | |
509 end | |
510 | |
511 def test_close | |
512 @request.session[:user_id] = 2 | |
513 post :close, :id => 1 | |
514 assert_redirected_to '/projects/ecookbook' | |
515 assert_equal Project::STATUS_CLOSED, Project.find(1).status | |
516 end | |
517 | |
518 def test_reopen | |
519 Project.find(1).close | |
520 @request.session[:user_id] = 2 | |
521 post :reopen, :id => 1 | |
522 assert_redirected_to '/projects/ecookbook' | |
523 assert Project.find(1).active? | |
524 end | |
525 | |
526 def test_project_breadcrumbs_should_be_limited_to_3_ancestors | |
527 CustomField.delete_all | |
528 parent = nil | |
529 6.times do |i| | |
530 p = Project.generate_with_parent!(parent) | |
531 get :show, :id => p | |
532 assert_select '#header h1' do | |
533 assert_select 'a', :count => [i, 3].min | |
534 end | |
535 | |
536 parent = p | |
537 end | |
538 end | |
539 | |
540 def test_get_copy | |
541 @request.session[:user_id] = 1 # admin | |
542 get :copy, :id => 1 | |
543 assert_response :success | |
544 assert_template 'copy' | |
545 assert assigns(:project) | |
546 assert_equal Project.find(1).description, assigns(:project).description | |
547 assert_nil assigns(:project).id | |
548 | |
549 assert_select 'input[name=?][value=?]', 'project[enabled_module_names][]', 'issue_tracking', 1 | |
550 end | |
551 | |
552 def test_get_copy_with_invalid_source_should_respond_with_404 | |
553 @request.session[:user_id] = 1 | |
554 get :copy, :id => 99 | |
555 assert_response 404 | |
556 end | |
557 | |
558 def test_post_copy_should_copy_requested_items | |
559 @request.session[:user_id] = 1 # admin | |
560 CustomField.delete_all | |
561 | |
562 assert_difference 'Project.count' do | |
563 post :copy, :id => 1, | |
564 :project => { | |
565 :name => 'Copy', | |
566 :identifier => 'unique-copy', | |
567 :tracker_ids => ['1', '2', '3', ''], | |
568 :enabled_module_names => %w(issue_tracking time_tracking) | |
569 }, | |
570 :only => %w(issues versions) | |
571 end | |
572 project = Project.find('unique-copy') | |
573 source = Project.find(1) | |
574 assert_equal %w(issue_tracking time_tracking), project.enabled_module_names.sort | |
575 | |
576 assert_equal source.versions.count, project.versions.count, "All versions were not copied" | |
577 assert_equal source.issues.count, project.issues.count, "All issues were not copied" | |
578 assert_equal 0, project.members.count | |
579 end | |
580 | |
581 def test_post_copy_should_redirect_to_settings_when_successful | |
582 @request.session[:user_id] = 1 # admin | |
583 post :copy, :id => 1, :project => {:name => 'Copy', :identifier => 'unique-copy'} | |
584 assert_response :redirect | |
585 assert_redirected_to :controller => 'projects', :action => 'settings', :id => 'unique-copy' | |
586 end | |
587 | |
588 def test_jump_should_redirect_to_active_tab | |
589 get :show, :id => 1, :jump => 'issues' | |
590 assert_redirected_to '/projects/ecookbook/issues' | |
591 end | |
592 | |
593 def test_jump_should_not_redirect_to_inactive_tab | |
594 get :show, :id => 3, :jump => 'documents' | |
595 assert_response :success | |
596 assert_template 'show' | |
597 end | |
598 | |
599 def test_jump_should_not_redirect_to_unknown_tab | |
600 get :show, :id => 3, :jump => 'foobar' | |
601 assert_response :success | |
602 assert_template 'show' | |
603 end | |
604 | |
605 def test_body_should_have_project_css_class | |
606 get :show, :id => 1 | |
607 assert_select 'body.project-ecookbook' | |
608 end | |
609 end |