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