Mercurial > hg > soundsoftware-site
comparison test/functional/issues_controller_test.rb @ 37:94944d00e43c
* Update to SVN trunk rev 4411
author | Chris Cannam <chris.cannam@soundsoftware.ac.uk> |
---|---|
date | Fri, 19 Nov 2010 13:24:41 +0000 |
parents | 40f7cfd4df19 |
children | af80e5618e9b |
comparison
equal
deleted
inserted
replaced
22:40f7cfd4df19 | 37:94944d00e43c |
---|---|
123 assert_tag :tag => 'a', :content => /Can't print recipes/ | 123 assert_tag :tag => 'a', :content => /Can't print recipes/ |
124 assert_tag :tag => 'a', :content => /Subproject issue/ | 124 assert_tag :tag => 'a', :content => /Subproject issue/ |
125 assert_tag :tag => 'a', :content => /Issue of a private subproject/ | 125 assert_tag :tag => 'a', :content => /Issue of a private subproject/ |
126 end | 126 end |
127 | 127 |
128 def test_index_with_project_and_default_filter | |
129 get :index, :project_id => 1, :set_filter => 1 | |
130 assert_response :success | |
131 assert_template 'index.rhtml' | |
132 assert_not_nil assigns(:issues) | |
133 | |
134 query = assigns(:query) | |
135 assert_not_nil query | |
136 # default filter | |
137 assert_equal({'status_id' => {:operator => 'o', :values => ['']}}, query.filters) | |
138 end | |
139 | |
128 def test_index_with_project_and_filter | 140 def test_index_with_project_and_filter |
129 get :index, :project_id => 1, :set_filter => 1 | 141 get :index, :project_id => 1, :set_filter => 1, |
142 :fields => ['tracker_id'], | |
143 :operators => {'tracker_id' => '='}, | |
144 :values => {'tracker_id' => ['1']} | |
130 assert_response :success | 145 assert_response :success |
131 assert_template 'index.rhtml' | 146 assert_template 'index.rhtml' |
132 assert_not_nil assigns(:issues) | 147 assert_not_nil assigns(:issues) |
148 | |
149 query = assigns(:query) | |
150 assert_not_nil query | |
151 assert_equal({'tracker_id' => {:operator => '=', :values => ['1']}}, query.filters) | |
152 end | |
153 | |
154 def test_index_with_project_and_empty_filters | |
155 get :index, :project_id => 1, :set_filter => 1, :fields => [''] | |
156 assert_response :success | |
157 assert_template 'index.rhtml' | |
158 assert_not_nil assigns(:issues) | |
159 | |
160 query = assigns(:query) | |
161 assert_not_nil query | |
162 # no filter | |
163 assert_equal({}, query.filters) | |
133 end | 164 end |
134 | 165 |
135 def test_index_with_query | 166 def test_index_with_query |
136 get :index, :project_id => 1, :query_id => 5 | 167 get :index, :project_id => 1, :query_id => 5 |
137 assert_response :success | 168 assert_response :success |
338 @request.session[:user_id] = 2 | 369 @request.session[:user_id] = 2 |
339 IssueStatus.delete_all | 370 IssueStatus.delete_all |
340 | 371 |
341 get :new, :project_id => 1 | 372 get :new, :project_id => 1 |
342 assert_response 500 | 373 assert_response 500 |
343 assert_not_nil flash[:error] | 374 assert_error_tag :content => /No default issue/ |
344 assert_tag :tag => 'div', :attributes => { :class => /error/ }, | |
345 :content => /No default issue/ | |
346 end | 375 end |
347 | 376 |
348 def test_get_new_with_no_tracker_should_display_an_error | 377 def test_get_new_with_no_tracker_should_display_an_error |
349 @request.session[:user_id] = 2 | 378 @request.session[:user_id] = 2 |
350 Tracker.delete_all | 379 Tracker.delete_all |
351 | 380 |
352 get :new, :project_id => 1 | 381 get :new, :project_id => 1 |
353 assert_response 500 | 382 assert_response 500 |
354 assert_not_nil flash[:error] | 383 assert_error_tag :content => /No tracker/ |
355 assert_tag :tag => 'div', :attributes => { :class => /error/ }, | |
356 :content => /No tracker/ | |
357 end | 384 end |
358 | 385 |
359 def test_update_new_form | 386 def test_update_new_form |
360 @request.session[:user_id] = 2 | 387 @request.session[:user_id] = 2 |
361 xhr :post, :new, :project_id => 1, | 388 xhr :post, :new, :project_id => 1, |
380 :issue => {:tracker_id => 3, | 407 :issue => {:tracker_id => 3, |
381 :status_id => 2, | 408 :status_id => 2, |
382 :subject => 'This is the test_new issue', | 409 :subject => 'This is the test_new issue', |
383 :description => 'This is the description', | 410 :description => 'This is the description', |
384 :priority_id => 5, | 411 :priority_id => 5, |
412 :start_date => '2010-11-07', | |
385 :estimated_hours => '', | 413 :estimated_hours => '', |
386 :custom_field_values => {'2' => 'Value for field 2'}} | 414 :custom_field_values => {'2' => 'Value for field 2'}} |
387 end | 415 end |
388 assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id | 416 assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id |
389 | 417 |
390 issue = Issue.find_by_subject('This is the test_new issue') | 418 issue = Issue.find_by_subject('This is the test_new issue') |
391 assert_not_nil issue | 419 assert_not_nil issue |
392 assert_equal 2, issue.author_id | 420 assert_equal 2, issue.author_id |
393 assert_equal 3, issue.tracker_id | 421 assert_equal 3, issue.tracker_id |
394 assert_equal 2, issue.status_id | 422 assert_equal 2, issue.status_id |
423 assert_equal Date.parse('2010-11-07'), issue.start_date | |
395 assert_nil issue.estimated_hours | 424 assert_nil issue.estimated_hours |
396 v = issue.custom_values.find(:first, :conditions => {:custom_field_id => 2}) | 425 v = issue.custom_values.find(:first, :conditions => {:custom_field_id => 2}) |
397 assert_not_nil v | 426 assert_not_nil v |
398 assert_equal 'Value for field 2', v.value | 427 assert_equal 'Value for field 2', v.value |
428 end | |
429 | |
430 def test_post_create_without_start_date | |
431 @request.session[:user_id] = 2 | |
432 assert_difference 'Issue.count' do | |
433 post :create, :project_id => 1, | |
434 :issue => {:tracker_id => 3, | |
435 :status_id => 2, | |
436 :subject => 'This is the test_new issue', | |
437 :description => 'This is the description', | |
438 :priority_id => 5, | |
439 :start_date => '', | |
440 :estimated_hours => '', | |
441 :custom_field_values => {'2' => 'Value for field 2'}} | |
442 end | |
443 assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id | |
444 | |
445 issue = Issue.find_by_subject('This is the test_new issue') | |
446 assert_not_nil issue | |
447 assert_nil issue.start_date | |
399 end | 448 end |
400 | 449 |
401 def test_post_create_and_continue | 450 def test_post_create_and_continue |
402 @request.session[:user_id] = 2 | 451 @request.session[:user_id] = 2 |
403 post :create, :project_id => 1, | 452 post :create, :project_id => 1, |
529 end | 578 end |
530 | 579 |
531 context "without workflow privilege" do | 580 context "without workflow privilege" do |
532 setup do | 581 setup do |
533 Workflow.delete_all(["role_id = ?", Role.anonymous.id]) | 582 Workflow.delete_all(["role_id = ?", Role.anonymous.id]) |
534 Role.anonymous.add_permission! :add_issues | 583 Role.anonymous.add_permission! :add_issues, :add_issue_notes |
535 end | 584 end |
536 | 585 |
537 context "#new" do | 586 context "#new" do |
538 should "propose default status only" do | 587 should "propose default status only" do |
539 get :new, :project_id => 1 | 588 get :new, :project_id => 1 |
554 end | 603 end |
555 issue = Issue.last(:order => 'id') | 604 issue = Issue.last(:order => 'id') |
556 assert_equal IssueStatus.default, issue.status | 605 assert_equal IssueStatus.default, issue.status |
557 end | 606 end |
558 | 607 |
608 should "accept default status" do | |
609 assert_difference 'Issue.count' do | |
610 post :create, :project_id => 1, | |
611 :issue => {:tracker_id => 1, | |
612 :subject => 'This is an issue', | |
613 :status_id => 1} | |
614 end | |
615 issue = Issue.last(:order => 'id') | |
616 assert_equal IssueStatus.default, issue.status | |
617 end | |
618 | |
559 should "ignore unauthorized status" do | 619 should "ignore unauthorized status" do |
560 assert_difference 'Issue.count' do | 620 assert_difference 'Issue.count' do |
561 post :create, :project_id => 1, | 621 post :create, :project_id => 1, |
562 :issue => {:tracker_id => 1, | 622 :issue => {:tracker_id => 1, |
563 :subject => 'This is an issue', | 623 :subject => 'This is an issue', |
565 end | 625 end |
566 issue = Issue.last(:order => 'id') | 626 issue = Issue.last(:order => 'id') |
567 assert_equal IssueStatus.default, issue.status | 627 assert_equal IssueStatus.default, issue.status |
568 end | 628 end |
569 end | 629 end |
630 | |
631 context "#update" do | |
632 should "ignore status change" do | |
633 assert_difference 'Journal.count' do | |
634 put :update, :id => 1, :notes => 'just trying', :issue => {:status_id => 3} | |
635 end | |
636 assert_equal 1, Issue.find(1).status_id | |
637 end | |
638 | |
639 should "ignore attributes changes" do | |
640 assert_difference 'Journal.count' do | |
641 put :update, :id => 1, :notes => 'just trying', :issue => {:subject => 'changed', :assigned_to_id => 2} | |
642 end | |
643 issue = Issue.find(1) | |
644 assert_equal "Can't print recipes", issue.subject | |
645 assert_nil issue.assigned_to | |
646 end | |
647 end | |
648 end | |
649 | |
650 context "with workflow privilege" do | |
651 setup do | |
652 Workflow.delete_all(["role_id = ?", Role.anonymous.id]) | |
653 Workflow.create!(:role => Role.anonymous, :tracker_id => 1, :old_status_id => 1, :new_status_id => 3) | |
654 Workflow.create!(:role => Role.anonymous, :tracker_id => 1, :old_status_id => 1, :new_status_id => 4) | |
655 Role.anonymous.add_permission! :add_issues, :add_issue_notes | |
656 end | |
657 | |
658 context "#update" do | |
659 should "accept authorized status" do | |
660 assert_difference 'Journal.count' do | |
661 put :update, :id => 1, :notes => 'just trying', :issue => {:status_id => 3} | |
662 end | |
663 assert_equal 3, Issue.find(1).status_id | |
664 end | |
665 | |
666 should "ignore unauthorized status" do | |
667 assert_difference 'Journal.count' do | |
668 put :update, :id => 1, :notes => 'just trying', :issue => {:status_id => 2} | |
669 end | |
670 assert_equal 1, Issue.find(1).status_id | |
671 end | |
672 | |
673 should "accept authorized attributes changes" do | |
674 assert_difference 'Journal.count' do | |
675 put :update, :id => 1, :notes => 'just trying', :issue => {:assigned_to_id => 2} | |
676 end | |
677 issue = Issue.find(1) | |
678 assert_equal 2, issue.assigned_to_id | |
679 end | |
680 | |
681 should "ignore unauthorized attributes changes" do | |
682 assert_difference 'Journal.count' do | |
683 put :update, :id => 1, :notes => 'just trying', :issue => {:subject => 'changed'} | |
684 end | |
685 issue = Issue.find(1) | |
686 assert_equal "Can't print recipes", issue.subject | |
687 end | |
688 end | |
689 | |
690 context "and :edit_issues permission" do | |
691 setup do | |
692 Role.anonymous.add_permission! :add_issues, :edit_issues | |
693 end | |
694 | |
695 should "accept authorized status" do | |
696 assert_difference 'Journal.count' do | |
697 put :update, :id => 1, :notes => 'just trying', :issue => {:status_id => 3} | |
698 end | |
699 assert_equal 3, Issue.find(1).status_id | |
700 end | |
701 | |
702 should "ignore unauthorized status" do | |
703 assert_difference 'Journal.count' do | |
704 put :update, :id => 1, :notes => 'just trying', :issue => {:status_id => 2} | |
705 end | |
706 assert_equal 1, Issue.find(1).status_id | |
707 end | |
708 | |
709 should "accept authorized attributes changes" do | |
710 assert_difference 'Journal.count' do | |
711 put :update, :id => 1, :notes => 'just trying', :issue => {:subject => 'changed', :assigned_to_id => 2} | |
712 end | |
713 issue = Issue.find(1) | |
714 assert_equal "changed", issue.subject | |
715 assert_equal 2, issue.assigned_to_id | |
716 end | |
717 end | |
570 end | 718 end |
571 | 719 |
572 def test_copy_issue | 720 def test_copy_issue |
573 @request.session[:user_id] = 2 | 721 @request.session[:user_id] = 2 |
574 get :new, :project_id => 1, :copy_from => 1 | 722 get :new, :project_id => 1, :copy_from => 1 |
587 assert_equal Issue.find(1), assigns(:issue) | 735 assert_equal Issue.find(1), assigns(:issue) |
588 end | 736 end |
589 | 737 |
590 def test_get_edit_with_params | 738 def test_get_edit_with_params |
591 @request.session[:user_id] = 2 | 739 @request.session[:user_id] = 2 |
592 get :edit, :id => 1, :issue => { :status_id => 5, :priority_id => 7 } | 740 get :edit, :id => 1, :issue => { :status_id => 5, :priority_id => 7 }, |
741 :time_entry => { :hours => '2.5', :comments => 'test_get_edit_with_params', :activity_id => TimeEntryActivity.first.id } | |
593 assert_response :success | 742 assert_response :success |
594 assert_template 'edit' | 743 assert_template 'edit' |
595 | 744 |
596 issue = assigns(:issue) | 745 issue = assigns(:issue) |
597 assert_not_nil issue | 746 assert_not_nil issue |
605 assert_equal 7, issue.priority_id | 754 assert_equal 7, issue.priority_id |
606 assert_tag :select, :attributes => { :name => 'issue[priority_id]' }, | 755 assert_tag :select, :attributes => { :name => 'issue[priority_id]' }, |
607 :child => { :tag => 'option', | 756 :child => { :tag => 'option', |
608 :content => 'Urgent', | 757 :content => 'Urgent', |
609 :attributes => { :selected => 'selected' } } | 758 :attributes => { :selected => 'selected' } } |
759 | |
760 assert_tag :input, :attributes => { :name => 'time_entry[hours]', :value => '2.5' } | |
761 assert_tag :select, :attributes => { :name => 'time_entry[activity_id]' }, | |
762 :child => { :tag => 'option', | |
763 :attributes => { :selected => 'selected', :value => TimeEntryActivity.first.id } } | |
764 assert_tag :input, :attributes => { :name => 'time_entry[comments]', :value => 'test_get_edit_with_params' } | |
610 end | 765 end |
611 | 766 |
612 def test_update_edit_form | 767 def test_update_edit_form |
613 @request.session[:user_id] = 2 | 768 @request.session[:user_id] = 2 |
614 xhr :post, :new, :project_id => 1, | 769 xhr :post, :new, :project_id => 1, |
909 # System wide custom field | 1064 # System wide custom field |
910 assert CustomField.find(1).is_for_all? | 1065 assert CustomField.find(1).is_for_all? |
911 assert_tag :select, :attributes => {:name => 'issue[custom_field_values][1]'} | 1066 assert_tag :select, :attributes => {:name => 'issue[custom_field_values][1]'} |
912 end | 1067 end |
913 | 1068 |
1069 def test_get_bulk_edit_on_different_projects | |
1070 @request.session[:user_id] = 2 | |
1071 get :bulk_edit, :ids => [1, 2, 6] | |
1072 assert_response :success | |
1073 assert_template 'bulk_edit' | |
1074 | |
1075 # Project specific custom field, date type | |
1076 field = CustomField.find(9) | |
1077 assert !field.is_for_all? | |
1078 assert !field.project_ids.include?(Issue.find(6).project_id) | |
1079 assert_no_tag :input, :attributes => {:name => 'issue[custom_field_values][9]'} | |
1080 end | |
1081 | |
914 def test_bulk_update | 1082 def test_bulk_update |
915 @request.session[:user_id] = 2 | 1083 @request.session[:user_id] = 2 |
916 # update issues priority | 1084 # update issues priority |
917 post :bulk_update, :ids => [1, 2], :notes => 'Bulk editing', | 1085 post :bulk_update, :ids => [1, 2], :notes => 'Bulk editing', |
918 :issue => {:priority_id => 7, | 1086 :issue => {:priority_id => 7, |
928 assert_equal '125', issue.custom_value_for(2).value | 1096 assert_equal '125', issue.custom_value_for(2).value |
929 assert_equal 'Bulk editing', journal.notes | 1097 assert_equal 'Bulk editing', journal.notes |
930 assert_equal 1, journal.details.size | 1098 assert_equal 1, journal.details.size |
931 end | 1099 end |
932 | 1100 |
1101 def test_bulk_update_on_different_projects | |
1102 @request.session[:user_id] = 2 | |
1103 # update issues priority | |
1104 post :bulk_update, :ids => [1, 2, 6], :notes => 'Bulk editing', | |
1105 :issue => {:priority_id => 7, | |
1106 :assigned_to_id => '', | |
1107 :custom_field_values => {'2' => ''}} | |
1108 | |
1109 assert_response 302 | |
1110 # check that the issues were updated | |
1111 assert_equal [7, 7, 7], Issue.find([1,2,6]).map(&:priority_id) | |
1112 | |
1113 issue = Issue.find(1) | |
1114 journal = issue.journals.find(:first, :order => 'created_on DESC') | |
1115 assert_equal '125', issue.custom_value_for(2).value | |
1116 assert_equal 'Bulk editing', journal.notes | |
1117 assert_equal 1, journal.details.size | |
1118 end | |
1119 | |
1120 def test_bulk_update_on_different_projects_without_rights | |
1121 @request.session[:user_id] = 3 | |
1122 user = User.find(3) | |
1123 action = { :controller => "issues", :action => "bulk_update" } | |
1124 assert user.allowed_to?(action, Issue.find(1).project) | |
1125 assert ! user.allowed_to?(action, Issue.find(6).project) | |
1126 post :bulk_update, :ids => [1, 6], :notes => 'Bulk should fail', | |
1127 :issue => {:priority_id => 7, | |
1128 :assigned_to_id => '', | |
1129 :custom_field_values => {'2' => ''}} | |
1130 assert_response 403 | |
1131 assert_not_equal "Bulk should fail", Journal.last.notes | |
1132 end | |
1133 | |
933 def test_bullk_update_should_send_a_notification | 1134 def test_bullk_update_should_send_a_notification |
934 @request.session[:user_id] = 2 | 1135 @request.session[:user_id] = 2 |
935 ActionMailer::Base.deliveries.clear | 1136 ActionMailer::Base.deliveries.clear |
936 post(:bulk_update, | 1137 post(:bulk_update, |
937 { | 1138 { |
1059 assert !(Issue.find_by_id(1) || Issue.find_by_id(3)) | 1260 assert !(Issue.find_by_id(1) || Issue.find_by_id(3)) |
1060 assert_equal 2, TimeEntry.find(1).issue_id | 1261 assert_equal 2, TimeEntry.find(1).issue_id |
1061 assert_equal 2, TimeEntry.find(2).issue_id | 1262 assert_equal 2, TimeEntry.find(2).issue_id |
1062 end | 1263 end |
1063 | 1264 |
1265 def test_destroy_issues_from_different_projects | |
1266 @request.session[:user_id] = 2 | |
1267 post :destroy, :ids => [1, 2, 6], :todo => 'destroy' | |
1268 assert_redirected_to :controller => 'issues', :action => 'index' | |
1269 assert !(Issue.find_by_id(1) || Issue.find_by_id(2) || Issue.find_by_id(6)) | |
1270 end | |
1271 | |
1064 def test_default_search_scope | 1272 def test_default_search_scope |
1065 get :index | 1273 get :index |
1066 assert_tag :div, :attributes => {:id => 'quick-search'}, | 1274 assert_tag :div, :attributes => {:id => 'quick-search'}, |
1067 :child => {:tag => 'form', | 1275 :child => {:tag => 'form', |
1068 :child => {:tag => 'input', :attributes => {:name => 'issues', :type => 'hidden', :value => '1'}}} | 1276 :child => {:tag => 'input', :attributes => {:name => 'issues', :type => 'hidden', :value => '1'}}} |