Mercurial > hg > soundsoftware-site
comparison .svn/pristine/04/045b82572747e8f57f122a0ac4102b9d20ea2c04.svn-base @ 1298:4f746d8966dd redmine_2.3_integration
Merge from redmine-2.3 branch to create new branch redmine-2.3-integration
author | Chris Cannam |
---|---|
date | Fri, 14 Jun 2013 09:28:30 +0100 |
parents | 622f24f53b42 |
children |
comparison
equal
deleted
inserted
replaced
1297:0a574315af3e | 1298:4f746d8966dd |
---|---|
1 # Redmine - project management software | |
2 # Copyright (C) 2006-2013 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.count(:conditions => Project.visible_condition(User.current)) | |
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_nil 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_nil 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_nil 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_hidden_custom_fields | |
324 ProjectCustomField.find_by_name('Development status').update_attribute :visible, false | |
325 get :show, :id => 'ecookbook' | |
326 assert_response :success | |
327 assert_template 'show' | |
328 assert_not_nil assigns(:project) | |
329 | |
330 assert_select 'li', :text => /Development status/, :count => 0 | |
331 end | |
332 | |
333 def test_show_should_not_fail_when_custom_values_are_nil | |
334 project = Project.find_by_identifier('ecookbook') | |
335 project.custom_values.first.update_attribute(:value, nil) | |
336 get :show, :id => 'ecookbook' | |
337 assert_response :success | |
338 assert_template 'show' | |
339 assert_not_nil assigns(:project) | |
340 assert_equal Project.find_by_identifier('ecookbook'), assigns(:project) | |
341 end | |
342 | |
343 def show_archived_project_should_be_denied | |
344 project = Project.find_by_identifier('ecookbook') | |
345 project.archive! | |
346 | |
347 get :show, :id => 'ecookbook' | |
348 assert_response 403 | |
349 assert_nil assigns(:project) | |
350 assert_select 'p', :text => /archived/ | |
351 end | |
352 | |
353 def test_show_should_not_show_private_subprojects_that_are_not_visible | |
354 get :show, :id => 'ecookbook' | |
355 assert_response :success | |
356 assert_template 'show' | |
357 assert_select 'a', :text => /Private child/, :count => 0 | |
358 end | |
359 | |
360 def test_show_should_show_private_subprojects_that_are_visible | |
361 @request.session[:user_id] = 2 # manager who is a member of the private subproject | |
362 get :show, :id => 'ecookbook' | |
363 assert_response :success | |
364 assert_template 'show' | |
365 assert_select 'a', :text => /Private child/ | |
366 end | |
367 | |
368 def test_settings | |
369 @request.session[:user_id] = 2 # manager | |
370 get :settings, :id => 1 | |
371 assert_response :success | |
372 assert_template 'settings' | |
373 end | |
374 | |
375 def test_settings_of_subproject | |
376 @request.session[:user_id] = 2 | |
377 get :settings, :id => 'private-child' | |
378 assert_response :success | |
379 assert_template 'settings' | |
380 | |
381 assert_select 'input[type=checkbox][name=?]', 'project[inherit_members]' | |
382 end | |
383 | |
384 def test_settings_should_be_denied_for_member_on_closed_project | |
385 Project.find(1).close | |
386 @request.session[:user_id] = 2 # manager | |
387 | |
388 get :settings, :id => 1 | |
389 assert_response 403 | |
390 end | |
391 | |
392 def test_settings_should_be_denied_for_anonymous_on_closed_project | |
393 Project.find(1).close | |
394 | |
395 get :settings, :id => 1 | |
396 assert_response 302 | |
397 end | |
398 | |
399 def test_update | |
400 @request.session[:user_id] = 2 # manager | |
401 post :update, :id => 1, :project => {:name => 'Test changed name', | |
402 :issue_custom_field_ids => ['']} | |
403 assert_redirected_to '/projects/ecookbook/settings' | |
404 project = Project.find(1) | |
405 assert_equal 'Test changed name', project.name | |
406 end | |
407 | |
408 def test_update_with_failure | |
409 @request.session[:user_id] = 2 # manager | |
410 post :update, :id => 1, :project => {:name => ''} | |
411 assert_response :success | |
412 assert_template 'settings' | |
413 assert_error_tag :content => /name can't be blank/i | |
414 end | |
415 | |
416 def test_update_should_be_denied_for_member_on_closed_project | |
417 Project.find(1).close | |
418 @request.session[:user_id] = 2 # manager | |
419 | |
420 post :update, :id => 1, :project => {:name => 'Closed'} | |
421 assert_response 403 | |
422 assert_equal 'eCookbook', Project.find(1).name | |
423 end | |
424 | |
425 def test_update_should_be_denied_for_anonymous_on_closed_project | |
426 Project.find(1).close | |
427 | |
428 post :update, :id => 1, :project => {:name => 'Closed'} | |
429 assert_response 302 | |
430 assert_equal 'eCookbook', Project.find(1).name | |
431 end | |
432 | |
433 def test_modules | |
434 @request.session[:user_id] = 2 | |
435 Project.find(1).enabled_module_names = ['issue_tracking', 'news'] | |
436 | |
437 post :modules, :id => 1, :enabled_module_names => ['issue_tracking', 'repository', 'documents'] | |
438 assert_redirected_to '/projects/ecookbook/settings/modules' | |
439 assert_equal ['documents', 'issue_tracking', 'repository'], Project.find(1).enabled_module_names.sort | |
440 end | |
441 | |
442 def test_destroy_leaf_project_without_confirmation_should_show_confirmation | |
443 @request.session[:user_id] = 1 # admin | |
444 | |
445 assert_no_difference 'Project.count' do | |
446 delete :destroy, :id => 2 | |
447 assert_response :success | |
448 assert_template 'destroy' | |
449 end | |
450 end | |
451 | |
452 def test_destroy_without_confirmation_should_show_confirmation_with_subprojects | |
453 @request.session[:user_id] = 1 # admin | |
454 | |
455 assert_no_difference 'Project.count' do | |
456 delete :destroy, :id => 1 | |
457 assert_response :success | |
458 assert_template 'destroy' | |
459 end | |
460 assert_select 'strong', | |
461 :text => ['Private child of eCookbook', | |
462 'Child of private child, eCookbook Subproject 1', | |
463 'eCookbook Subproject 2'].join(', ') | |
464 end | |
465 | |
466 def test_destroy_with_confirmation_should_destroy_the_project_and_subprojects | |
467 @request.session[:user_id] = 1 # admin | |
468 | |
469 assert_difference 'Project.count', -5 do | |
470 delete :destroy, :id => 1, :confirm => 1 | |
471 assert_redirected_to '/admin/projects' | |
472 end | |
473 assert_nil Project.find_by_id(1) | |
474 end | |
475 | |
476 def test_archive | |
477 @request.session[:user_id] = 1 # admin | |
478 post :archive, :id => 1 | |
479 assert_redirected_to '/admin/projects' | |
480 assert !Project.find(1).active? | |
481 end | |
482 | |
483 def test_archive_with_failure | |
484 @request.session[:user_id] = 1 | |
485 Project.any_instance.stubs(:archive).returns(false) | |
486 post :archive, :id => 1 | |
487 assert_redirected_to '/admin/projects' | |
488 assert_match /project cannot be archived/i, flash[:error] | |
489 end | |
490 | |
491 def test_unarchive | |
492 @request.session[:user_id] = 1 # admin | |
493 Project.find(1).archive | |
494 post :unarchive, :id => 1 | |
495 assert_redirected_to '/admin/projects' | |
496 assert Project.find(1).active? | |
497 end | |
498 | |
499 def test_close | |
500 @request.session[:user_id] = 2 | |
501 post :close, :id => 1 | |
502 assert_redirected_to '/projects/ecookbook' | |
503 assert_equal Project::STATUS_CLOSED, Project.find(1).status | |
504 end | |
505 | |
506 def test_reopen | |
507 Project.find(1).close | |
508 @request.session[:user_id] = 2 | |
509 post :reopen, :id => 1 | |
510 assert_redirected_to '/projects/ecookbook' | |
511 assert Project.find(1).active? | |
512 end | |
513 | |
514 def test_project_breadcrumbs_should_be_limited_to_3_ancestors | |
515 CustomField.delete_all | |
516 parent = nil | |
517 6.times do |i| | |
518 p = Project.generate_with_parent!(parent) | |
519 get :show, :id => p | |
520 assert_select '#header h1' do | |
521 assert_select 'a', :count => [i, 3].min | |
522 end | |
523 | |
524 parent = p | |
525 end | |
526 end | |
527 | |
528 def test_get_copy | |
529 @request.session[:user_id] = 1 # admin | |
530 get :copy, :id => 1 | |
531 assert_response :success | |
532 assert_template 'copy' | |
533 assert assigns(:project) | |
534 assert_equal Project.find(1).description, assigns(:project).description | |
535 assert_nil assigns(:project).id | |
536 | |
537 assert_select 'input[name=?][value=?]', 'project[enabled_module_names][]', 'issue_tracking', 1 | |
538 end | |
539 | |
540 def test_get_copy_with_invalid_source_should_respond_with_404 | |
541 @request.session[:user_id] = 1 | |
542 get :copy, :id => 99 | |
543 assert_response 404 | |
544 end | |
545 | |
546 def test_post_copy_should_copy_requested_items | |
547 @request.session[:user_id] = 1 # admin | |
548 CustomField.delete_all | |
549 | |
550 assert_difference 'Project.count' do | |
551 post :copy, :id => 1, | |
552 :project => { | |
553 :name => 'Copy', | |
554 :identifier => 'unique-copy', | |
555 :tracker_ids => ['1', '2', '3', ''], | |
556 :enabled_module_names => %w(issue_tracking time_tracking) | |
557 }, | |
558 :only => %w(issues versions) | |
559 end | |
560 project = Project.find('unique-copy') | |
561 source = Project.find(1) | |
562 assert_equal %w(issue_tracking time_tracking), project.enabled_module_names.sort | |
563 | |
564 assert_equal source.versions.count, project.versions.count, "All versions were not copied" | |
565 assert_equal source.issues.count, project.issues.count, "All issues were not copied" | |
566 assert_equal 0, project.members.count | |
567 end | |
568 | |
569 def test_post_copy_should_redirect_to_settings_when_successful | |
570 @request.session[:user_id] = 1 # admin | |
571 post :copy, :id => 1, :project => {:name => 'Copy', :identifier => 'unique-copy'} | |
572 assert_response :redirect | |
573 assert_redirected_to :controller => 'projects', :action => 'settings', :id => 'unique-copy' | |
574 end | |
575 | |
576 def test_jump_should_redirect_to_active_tab | |
577 get :show, :id => 1, :jump => 'issues' | |
578 assert_redirected_to '/projects/ecookbook/issues' | |
579 end | |
580 | |
581 def test_jump_should_not_redirect_to_inactive_tab | |
582 get :show, :id => 3, :jump => 'documents' | |
583 assert_response :success | |
584 assert_template 'show' | |
585 end | |
586 | |
587 def test_jump_should_not_redirect_to_unknown_tab | |
588 get :show, :id => 3, :jump => 'foobar' | |
589 assert_response :success | |
590 assert_template 'show' | |
591 end | |
592 end |