Mercurial > hg > soundsoftware-site
comparison test/functional/projects_controller_test.rb @ 1115:433d4f72a19b redmine-2.2
Update to Redmine SVN revision 11137 on 2.2-stable branch
author | Chris Cannam |
---|---|
date | Mon, 07 Jan 2013 12:01:42 +0000 |
parents | cbb26bc654de |
children | 622f24f53b42 261b3d9a4903 |
comparison
equal
deleted
inserted
replaced
929:5f33065ddc4b | 1115:433d4f72a19b |
---|---|
1 # Redmine - project management software | 1 # Redmine - project management software |
2 # Copyright (C) 2006-2011 Jean-Philippe Lang | 2 # Copyright (C) 2006-2012 Jean-Philippe Lang |
3 # | 3 # |
4 # This program is free software; you can redistribute it and/or | 4 # This program is free software; you can redistribute it and/or |
5 # modify it under the terms of the GNU General Public License | 5 # modify it under the terms of the GNU General Public License |
6 # as published by the Free Software Foundation; either version 2 | 6 # as published by the Free Software Foundation; either version 2 |
7 # of the License, or (at your option) any later version. | 7 # of the License, or (at your option) any later version. |
53 end | 53 end |
54 | 54 |
55 def test_index_atom | 55 def test_index_atom |
56 get :index, :format => 'atom' | 56 get :index, :format => 'atom' |
57 assert_response :success | 57 assert_response :success |
58 assert_template 'common/feed.atom' | 58 assert_template 'common/feed' |
59 assert_select 'feed>title', :text => 'Redmine: Latest projects' | 59 assert_select 'feed>title', :text => 'Redmine: Latest projects' |
60 assert_select 'feed>entry', :count => Project.count(:conditions => Project.visible_condition(User.current)) | 60 assert_select 'feed>entry', :count => Project.count(:conditions => Project.visible_condition(User.current)) |
61 end | 61 end |
62 | 62 |
63 context "#index" do | 63 context "#index" do |
309 project = assigns(:project) | 309 project = assigns(:project) |
310 assert_equal %w(issue_tracking news), project.enabled_module_names.sort | 310 assert_equal %w(issue_tracking news), project.enabled_module_names.sort |
311 end | 311 end |
312 end | 312 end |
313 | 313 |
314 def test_create_should_not_accept_get | |
315 @request.session[:user_id] = 1 | |
316 get :create | |
317 assert_response :method_not_allowed | |
318 end | |
319 | |
320 def test_show_by_id | 314 def test_show_by_id |
321 get :show, :id => 1 | 315 get :show, :id => 1 |
322 assert_response :success | 316 assert_response :success |
323 assert_template 'show' | 317 assert_template 'show' |
324 assert_not_nil assigns(:project) | 318 assert_not_nil assigns(:project) |
382 def test_settings | 376 def test_settings |
383 @request.session[:user_id] = 2 # manager | 377 @request.session[:user_id] = 2 # manager |
384 get :settings, :id => 1 | 378 get :settings, :id => 1 |
385 assert_response :success | 379 assert_response :success |
386 assert_template 'settings' | 380 assert_template 'settings' |
381 end | |
382 | |
383 def test_settings_should_be_denied_for_member_on_closed_project | |
384 Project.find(1).close | |
385 @request.session[:user_id] = 2 # manager | |
386 | |
387 get :settings, :id => 1 | |
388 assert_response 403 | |
389 end | |
390 | |
391 def test_settings_should_be_denied_for_anonymous_on_closed_project | |
392 Project.find(1).close | |
393 | |
394 get :settings, :id => 1 | |
395 assert_response 302 | |
387 end | 396 end |
388 | 397 |
389 def test_update | 398 def test_update |
390 @request.session[:user_id] = 2 # manager | 399 @request.session[:user_id] = 2 # manager |
391 post :update, :id => 1, :project => {:name => 'Test changed name', | 400 post :update, :id => 1, :project => {:name => 'Test changed name', |
393 assert_redirected_to '/projects/ecookbook/settings' | 402 assert_redirected_to '/projects/ecookbook/settings' |
394 project = Project.find(1) | 403 project = Project.find(1) |
395 assert_equal 'Test changed name', project.name | 404 assert_equal 'Test changed name', project.name |
396 end | 405 end |
397 | 406 |
407 def test_update_with_failure | |
408 @request.session[:user_id] = 2 # manager | |
409 post :update, :id => 1, :project => {:name => ''} | |
410 assert_response :success | |
411 assert_template 'settings' | |
412 assert_error_tag :content => /name can't be blank/i | |
413 end | |
414 | |
415 def test_update_should_be_denied_for_member_on_closed_project | |
416 Project.find(1).close | |
417 @request.session[:user_id] = 2 # manager | |
418 | |
419 post :update, :id => 1, :project => {:name => 'Closed'} | |
420 assert_response 403 | |
421 assert_equal 'eCookbook', Project.find(1).name | |
422 end | |
423 | |
424 def test_update_should_be_denied_for_anonymous_on_closed_project | |
425 Project.find(1).close | |
426 | |
427 post :update, :id => 1, :project => {:name => 'Closed'} | |
428 assert_response 302 | |
429 assert_equal 'eCookbook', Project.find(1).name | |
430 end | |
431 | |
398 def test_modules | 432 def test_modules |
399 @request.session[:user_id] = 2 | 433 @request.session[:user_id] = 2 |
400 Project.find(1).enabled_module_names = ['issue_tracking', 'news'] | 434 Project.find(1).enabled_module_names = ['issue_tracking', 'news'] |
401 | 435 |
402 post :modules, :id => 1, :enabled_module_names => ['issue_tracking', 'repository', 'documents'] | 436 post :modules, :id => 1, :enabled_module_names => ['issue_tracking', 'repository', 'documents'] |
403 assert_redirected_to '/projects/ecookbook/settings/modules' | 437 assert_redirected_to '/projects/ecookbook/settings/modules' |
404 assert_equal ['documents', 'issue_tracking', 'repository'], Project.find(1).enabled_module_names.sort | 438 assert_equal ['documents', 'issue_tracking', 'repository'], Project.find(1).enabled_module_names.sort |
405 end | 439 end |
406 | 440 |
407 def test_modules_should_not_allow_get | 441 def test_destroy_without_confirmation |
408 @request.session[:user_id] = 1 | 442 @request.session[:user_id] = 1 # admin |
409 get :modules, :id => 1 | 443 delete :destroy, :id => 1 |
410 assert_response :method_not_allowed | |
411 end | |
412 | |
413 def test_get_destroy | |
414 @request.session[:user_id] = 1 # admin | |
415 get :destroy, :id => 1 | |
416 assert_response :success | 444 assert_response :success |
417 assert_template 'destroy' | 445 assert_template 'destroy' |
418 assert_not_nil Project.find_by_id(1) | 446 assert_not_nil Project.find_by_id(1) |
419 end | 447 assert_tag :tag => 'strong', |
420 | 448 :content => ['Private child of eCookbook', |
421 def test_post_destroy | 449 'Child of private child, eCookbook Subproject 1', |
422 @request.session[:user_id] = 1 # admin | 450 'eCookbook Subproject 2'].join(', ') |
423 post :destroy, :id => 1, :confirm => 1 | 451 end |
452 | |
453 def test_destroy | |
454 @request.session[:user_id] = 1 # admin | |
455 delete :destroy, :id => 1, :confirm => 1 | |
424 assert_redirected_to '/admin/projects' | 456 assert_redirected_to '/admin/projects' |
425 assert_nil Project.find_by_id(1) | 457 assert_nil Project.find_by_id(1) |
426 end | 458 end |
427 | 459 |
428 def test_archive | 460 def test_archive |
430 post :archive, :id => 1 | 462 post :archive, :id => 1 |
431 assert_redirected_to '/admin/projects' | 463 assert_redirected_to '/admin/projects' |
432 assert !Project.find(1).active? | 464 assert !Project.find(1).active? |
433 end | 465 end |
434 | 466 |
467 def test_archive_with_failure | |
468 @request.session[:user_id] = 1 | |
469 Project.any_instance.stubs(:archive).returns(false) | |
470 post :archive, :id => 1 | |
471 assert_redirected_to '/admin/projects' | |
472 assert_match /project cannot be archived/i, flash[:error] | |
473 end | |
474 | |
435 def test_unarchive | 475 def test_unarchive |
436 @request.session[:user_id] = 1 # admin | 476 @request.session[:user_id] = 1 # admin |
437 Project.find(1).archive | 477 Project.find(1).archive |
438 post :unarchive, :id => 1 | 478 post :unarchive, :id => 1 |
439 assert_redirected_to '/admin/projects' | 479 assert_redirected_to '/admin/projects' |
480 assert Project.find(1).active? | |
481 end | |
482 | |
483 def test_close | |
484 @request.session[:user_id] = 2 | |
485 post :close, :id => 1 | |
486 assert_redirected_to '/projects/ecookbook' | |
487 assert_equal Project::STATUS_CLOSED, Project.find(1).status | |
488 end | |
489 | |
490 def test_reopen | |
491 Project.find(1).close | |
492 @request.session[:user_id] = 2 | |
493 post :reopen, :id => 1 | |
494 assert_redirected_to '/projects/ecookbook' | |
440 assert Project.find(1).active? | 495 assert Project.find(1).active? |
441 end | 496 end |
442 | 497 |
443 def test_project_breadcrumbs_should_be_limited_to_3_ancestors | 498 def test_project_breadcrumbs_should_be_limited_to_3_ancestors |
444 CustomField.delete_all | 499 CustomField.delete_all |
466 | 521 |
467 assert_tag :tag => 'input', | 522 assert_tag :tag => 'input', |
468 :attributes => {:name => 'project[enabled_module_names][]', :value => 'issue_tracking'} | 523 :attributes => {:name => 'project[enabled_module_names][]', :value => 'issue_tracking'} |
469 end | 524 end |
470 | 525 |
471 def test_get_copy_without_project | 526 def test_get_copy_with_invalid_source_should_respond_with_404 |
472 @request.session[:user_id] = 1 # admin | 527 @request.session[:user_id] = 1 |
473 get :copy | 528 get :copy, :id => 99 |
474 assert_response :redirect | 529 assert_response 404 |
475 assert_redirected_to :controller => 'admin', :action => 'projects' | |
476 end | 530 end |
477 | 531 |
478 def test_post_copy_should_copy_requested_items | 532 def test_post_copy_should_copy_requested_items |
479 @request.session[:user_id] = 1 # admin | 533 @request.session[:user_id] = 1 # admin |
480 CustomField.delete_all | 534 CustomField.delete_all |
492 project = Project.find('unique-copy') | 546 project = Project.find('unique-copy') |
493 source = Project.find(1) | 547 source = Project.find(1) |
494 assert_equal %w(issue_tracking time_tracking), project.enabled_module_names.sort | 548 assert_equal %w(issue_tracking time_tracking), project.enabled_module_names.sort |
495 | 549 |
496 assert_equal source.versions.count, project.versions.count, "All versions were not copied" | 550 assert_equal source.versions.count, project.versions.count, "All versions were not copied" |
497 # issues assigned to a closed version won't be copied | 551 assert_equal source.issues.count, project.issues.count, "All issues were not copied" |
498 assert_equal source.issues.select {|i| i.fixed_version.nil? || i.fixed_version.open?}.size, | |
499 project.issues.count, "All issues were not copied" | |
500 assert_equal 0, project.members.count | 552 assert_equal 0, project.members.count |
501 end | 553 end |
502 | 554 |
503 def test_post_copy_should_redirect_to_settings_when_successful | 555 def test_post_copy_should_redirect_to_settings_when_successful |
504 @request.session[:user_id] = 1 # admin | 556 @request.session[:user_id] = 1 # admin |
521 def test_jump_should_not_redirect_to_unknown_tab | 573 def test_jump_should_not_redirect_to_unknown_tab |
522 get :show, :id => 3, :jump => 'foobar' | 574 get :show, :id => 3, :jump => 'foobar' |
523 assert_response :success | 575 assert_response :success |
524 assert_template 'show' | 576 assert_template 'show' |
525 end | 577 end |
526 | |
527 # A hook that is manually registered later | |
528 class ProjectBasedTemplate < Redmine::Hook::ViewListener | |
529 def view_layouts_base_html_head(context) | |
530 # Adds a project stylesheet | |
531 stylesheet_link_tag(context[:project].identifier) if context[:project] | |
532 end | |
533 end | |
534 # Don't use this hook now | |
535 Redmine::Hook.clear_listeners | |
536 | |
537 def test_hook_response | |
538 Redmine::Hook.add_listener(ProjectBasedTemplate) | |
539 get :show, :id => 1 | |
540 assert_tag :tag => 'link', :attributes => {:href => '/stylesheets/ecookbook.css'}, | |
541 :parent => {:tag => 'head'} | |
542 | |
543 Redmine::Hook.clear_listeners | |
544 end | |
545 end | 578 end |