comparison test/functional/issues_controller_test.rb @ 14:1d32c0a0efbf

* Update to SVN trunk (revisions 3892-4040)
author Chris Cannam
date Wed, 25 Aug 2010 16:30:24 +0100
parents 513646585e45
children 40f7cfd4df19
comparison
equal deleted inserted replaced
4:9cc62779c13a 14:1d32c0a0efbf
229 assert_kind_of Hash, session[:query] 229 assert_kind_of Hash, session[:query]
230 assert_kind_of Array, session[:query][:column_names] 230 assert_kind_of Array, session[:query][:column_names]
231 assert_equal columns, session[:query][:column_names].map(&:to_s) 231 assert_equal columns, session[:query][:column_names].map(&:to_s)
232 end 232 end
233 233
234 def test_changes
235 get :changes, :project_id => 1
236 assert_response :success
237 assert_not_nil assigns(:journals)
238 assert_equal 'application/atom+xml', @response.content_type
239 end
240
241 def test_show_by_anonymous 234 def test_show_by_anonymous
242 get :show, :id => 1 235 get :show, :id => 1
243 assert_response :success 236 assert_response :success
244 assert_template 'show.rhtml' 237 assert_template 'show.rhtml'
245 assert_not_nil assigns(:issue) 238 assert_not_nil assigns(:issue)
305 end 298 end
306 299
307 def test_show_atom 300 def test_show_atom
308 get :show, :id => 2, :format => 'atom' 301 get :show, :id => 2, :format => 'atom'
309 assert_response :success 302 assert_response :success
310 assert_template 'changes.rxml' 303 assert_template 'journals/index.rxml'
311 # Inline image 304 # Inline image
312 assert_select 'content', :text => Regexp.new(Regexp.quote('http://test.host/attachments/download/10')) 305 assert_select 'content', :text => Regexp.new(Regexp.quote('http://test.host/attachments/download/10'))
313 end 306 end
314 307
315 def test_show_export_to_pdf 308 def test_show_export_to_pdf
363 :content => /No tracker/ 356 :content => /No tracker/
364 end 357 end
365 358
366 def test_update_new_form 359 def test_update_new_form
367 @request.session[:user_id] = 2 360 @request.session[:user_id] = 2
368 xhr :post, :update_form, :project_id => 1, 361 xhr :post, :new, :project_id => 1,
369 :issue => {:tracker_id => 2, 362 :issue => {:tracker_id => 2,
370 :subject => 'This is the test_new issue', 363 :subject => 'This is the test_new issue',
371 :description => 'This is the description', 364 :description => 'This is the description',
372 :priority_id => 5} 365 :priority_id => 5}
373 assert_response :success 366 assert_response :success
615 :attributes => { :selected => 'selected' } } 608 :attributes => { :selected => 'selected' } }
616 end 609 end
617 610
618 def test_update_edit_form 611 def test_update_edit_form
619 @request.session[:user_id] = 2 612 @request.session[:user_id] = 2
620 xhr :post, :update_form, :project_id => 1, 613 xhr :post, :new, :project_id => 1,
621 :id => 1, 614 :id => 1,
622 :issue => {:tracker_id => 2, 615 :issue => {:tracker_id => 2,
623 :subject => 'This is the test_new issue', 616 :subject => 'This is the test_new issue',
624 :description => 'This is the description', 617 :description => 'This is the description',
625 :priority_id => 5} 618 :priority_id => 5}
632 assert_equal 1, issue.project_id 625 assert_equal 1, issue.project_id
633 assert_equal 2, issue.tracker_id 626 assert_equal 2, issue.tracker_id
634 assert_equal 'This is the test_new issue', issue.subject 627 assert_equal 'This is the test_new issue', issue.subject
635 end 628 end
636 629
637 def test_reply_to_issue
638 @request.session[:user_id] = 2
639 get :reply, :id => 1
640 assert_response :success
641 assert_select_rjs :show, "update"
642 end
643
644 def test_reply_to_note
645 @request.session[:user_id] = 2
646 get :reply, :id => 1, :journal_id => 2
647 assert_response :success
648 assert_select_rjs :show, "update"
649 end
650
651 def test_update_using_invalid_http_verbs 630 def test_update_using_invalid_http_verbs
652 @request.session[:user_id] = 2 631 @request.session[:user_id] = 2
653 subject = 'Updated by an invalid http verb' 632 subject = 'Updated by an invalid http verb'
654 633
655 get :update, :id => 1, :issue => {:subject => subject} 634 get :update, :id => 1, :issue => {:subject => subject}
929 # System wide custom field 908 # System wide custom field
930 assert CustomField.find(1).is_for_all? 909 assert CustomField.find(1).is_for_all?
931 assert_tag :select, :attributes => {:name => 'issue[custom_field_values][1]'} 910 assert_tag :select, :attributes => {:name => 'issue[custom_field_values][1]'}
932 end 911 end
933 912
934 def test_bulk_edit 913 def test_bulk_update
935 @request.session[:user_id] = 2 914 @request.session[:user_id] = 2
936 # update issues priority 915 # update issues priority
937 post :bulk_edit, :ids => [1, 2], :notes => 'Bulk editing', 916 post :bulk_update, :ids => [1, 2], :notes => 'Bulk editing',
938 :issue => {:priority_id => 7, 917 :issue => {:priority_id => 7,
939 :assigned_to_id => '', 918 :assigned_to_id => '',
940 :custom_field_values => {'2' => ''}} 919 :custom_field_values => {'2' => ''}}
941 920
942 assert_response 302 921 assert_response 302
948 assert_equal '125', issue.custom_value_for(2).value 927 assert_equal '125', issue.custom_value_for(2).value
949 assert_equal 'Bulk editing', journal.notes 928 assert_equal 'Bulk editing', journal.notes
950 assert_equal 1, journal.details.size 929 assert_equal 1, journal.details.size
951 end 930 end
952 931
953 def test_bullk_edit_should_send_a_notification 932 def test_bullk_update_should_send_a_notification
954 @request.session[:user_id] = 2 933 @request.session[:user_id] = 2
955 ActionMailer::Base.deliveries.clear 934 ActionMailer::Base.deliveries.clear
956 post(:bulk_edit, 935 post(:bulk_update,
957 { 936 {
958 :ids => [1, 2], 937 :ids => [1, 2],
959 :notes => 'Bulk editing', 938 :notes => 'Bulk editing',
960 :issue => { 939 :issue => {
961 :priority_id => 7, 940 :priority_id => 7,
966 945
967 assert_response 302 946 assert_response 302
968 assert_equal 2, ActionMailer::Base.deliveries.size 947 assert_equal 2, ActionMailer::Base.deliveries.size
969 end 948 end
970 949
971 def test_bulk_edit_status 950 def test_bulk_update_status
972 @request.session[:user_id] = 2 951 @request.session[:user_id] = 2
973 # update issues priority 952 # update issues priority
974 post :bulk_edit, :ids => [1, 2], :notes => 'Bulk editing status', 953 post :bulk_update, :ids => [1, 2], :notes => 'Bulk editing status',
975 :issue => {:priority_id => '', 954 :issue => {:priority_id => '',
976 :assigned_to_id => '', 955 :assigned_to_id => '',
977 :status_id => '5'} 956 :status_id => '5'}
978 957
979 assert_response 302 958 assert_response 302
980 issue = Issue.find(1) 959 issue = Issue.find(1)
981 assert issue.closed? 960 assert issue.closed?
982 end 961 end
983 962
984 def test_bulk_edit_custom_field 963 def test_bulk_update_custom_field
985 @request.session[:user_id] = 2 964 @request.session[:user_id] = 2
986 # update issues priority 965 # update issues priority
987 post :bulk_edit, :ids => [1, 2], :notes => 'Bulk editing custom field', 966 post :bulk_update, :ids => [1, 2], :notes => 'Bulk editing custom field',
988 :issue => {:priority_id => '', 967 :issue => {:priority_id => '',
989 :assigned_to_id => '', 968 :assigned_to_id => '',
990 :custom_field_values => {'2' => '777'}} 969 :custom_field_values => {'2' => '777'}}
991 970
992 assert_response 302 971 assert_response 302
997 assert_equal 1, journal.details.size 976 assert_equal 1, journal.details.size
998 assert_equal '125', journal.details.first.old_value 977 assert_equal '125', journal.details.first.old_value
999 assert_equal '777', journal.details.first.value 978 assert_equal '777', journal.details.first.value
1000 end 979 end
1001 980
1002 def test_bulk_unassign 981 def test_bulk_update_unassign
1003 assert_not_nil Issue.find(2).assigned_to 982 assert_not_nil Issue.find(2).assigned_to
1004 @request.session[:user_id] = 2 983 @request.session[:user_id] = 2
1005 # unassign issues 984 # unassign issues
1006 post :bulk_edit, :ids => [1, 2], :notes => 'Bulk unassigning', :issue => {:assigned_to_id => 'none'} 985 post :bulk_update, :ids => [1, 2], :notes => 'Bulk unassigning', :issue => {:assigned_to_id => 'none'}
1007 assert_response 302 986 assert_response 302
1008 # check that the issues were updated 987 # check that the issues were updated
1009 assert_nil Issue.find(2).assigned_to 988 assert_nil Issue.find(2).assigned_to
1010 end 989 end
1011 990
1012 def test_post_bulk_edit_should_allow_fixed_version_to_be_set_to_a_subproject 991 def test_post_bulk_update_should_allow_fixed_version_to_be_set_to_a_subproject
1013 @request.session[:user_id] = 2 992 @request.session[:user_id] = 2
1014 993
1015 post :bulk_edit, :ids => [1,2], :issue => {:fixed_version_id => 4} 994 post :bulk_update, :ids => [1,2], :issue => {:fixed_version_id => 4}
1016 995
1017 assert_response :redirect 996 assert_response :redirect
1018 issues = Issue.find([1,2]) 997 issues = Issue.find([1,2])
1019 issues.each do |issue| 998 issues.each do |issue|
1020 assert_equal 4, issue.fixed_version_id 999 assert_equal 4, issue.fixed_version_id
1021 assert_not_equal issue.project_id, issue.fixed_version.project_id 1000 assert_not_equal issue.project_id, issue.fixed_version.project_id
1022 end 1001 end
1023 end 1002 end
1024 1003
1025 def test_post_bulk_edit_should_redirect_back_using_the_back_url_parameter 1004 def test_post_bulk_update_should_redirect_back_using_the_back_url_parameter
1026 @request.session[:user_id] = 2 1005 @request.session[:user_id] = 2
1027 post :bulk_edit, :ids => [1,2], :back_url => '/issues' 1006 post :bulk_update, :ids => [1,2], :back_url => '/issues'
1028 1007
1029 assert_response :redirect 1008 assert_response :redirect
1030 assert_redirected_to '/issues' 1009 assert_redirected_to '/issues'
1031 end 1010 end
1032 1011
1033 def test_post_bulk_edit_should_not_redirect_back_using_the_back_url_parameter_off_the_host 1012 def test_post_bulk_update_should_not_redirect_back_using_the_back_url_parameter_off_the_host
1034 @request.session[:user_id] = 2 1013 @request.session[:user_id] = 2
1035 post :bulk_edit, :ids => [1,2], :back_url => 'http://google.com' 1014 post :bulk_update, :ids => [1,2], :back_url => 'http://google.com'
1036 1015
1037 assert_response :redirect 1016 assert_response :redirect
1038 assert_redirected_to :controller => 'issues', :action => 'index', :project_id => Project.find(1).identifier 1017 assert_redirected_to :controller => 'issues', :action => 'index', :project_id => Project.find(1).identifier
1039 end
1040
1041 def test_move_one_issue_to_another_project
1042 @request.session[:user_id] = 2
1043 post :move, :id => 1, :new_project_id => 2, :tracker_id => '', :assigned_to_id => '', :status_id => '', :start_date => '', :due_date => ''
1044 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
1045 assert_equal 2, Issue.find(1).project_id
1046 end
1047
1048 def test_move_one_issue_to_another_project_should_follow_when_needed
1049 @request.session[:user_id] = 2
1050 post :move, :id => 1, :new_project_id => 2, :follow => '1'
1051 assert_redirected_to '/issues/1'
1052 end
1053
1054 def test_bulk_move_to_another_project
1055 @request.session[:user_id] = 2
1056 post :move, :ids => [1, 2], :new_project_id => 2
1057 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
1058 # Issues moved to project 2
1059 assert_equal 2, Issue.find(1).project_id
1060 assert_equal 2, Issue.find(2).project_id
1061 # No tracker change
1062 assert_equal 1, Issue.find(1).tracker_id
1063 assert_equal 2, Issue.find(2).tracker_id
1064 end
1065
1066 def test_bulk_move_to_another_tracker
1067 @request.session[:user_id] = 2
1068 post :move, :ids => [1, 2], :new_tracker_id => 2
1069 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
1070 assert_equal 2, Issue.find(1).tracker_id
1071 assert_equal 2, Issue.find(2).tracker_id
1072 end
1073
1074 def test_bulk_copy_to_another_project
1075 @request.session[:user_id] = 2
1076 assert_difference 'Issue.count', 2 do
1077 assert_no_difference 'Project.find(1).issues.count' do
1078 post :move, :ids => [1, 2], :new_project_id => 2, :copy_options => {:copy => '1'}
1079 end
1080 end
1081 assert_redirected_to 'projects/ecookbook/issues'
1082 end
1083
1084 context "#move via bulk copy" do
1085 should "allow not changing the issue's attributes" do
1086 @request.session[:user_id] = 2
1087 issue_before_move = Issue.find(1)
1088 assert_difference 'Issue.count', 1 do
1089 assert_no_difference 'Project.find(1).issues.count' do
1090 post :move, :ids => [1], :new_project_id => 2, :copy_options => {:copy => '1'}, :new_tracker_id => '', :assigned_to_id => '', :status_id => '', :start_date => '', :due_date => ''
1091 end
1092 end
1093 issue_after_move = Issue.first(:order => 'id desc', :conditions => {:project_id => 2})
1094 assert_equal issue_before_move.tracker_id, issue_after_move.tracker_id
1095 assert_equal issue_before_move.status_id, issue_after_move.status_id
1096 assert_equal issue_before_move.assigned_to_id, issue_after_move.assigned_to_id
1097 end
1098
1099 should "allow changing the issue's attributes" do
1100 # Fixes random test failure with Mysql
1101 # where Issue.all(:limit => 2, :order => 'id desc', :conditions => {:project_id => 2}) doesn't return the expected results
1102 Issue.delete_all("project_id=2")
1103
1104 @request.session[:user_id] = 2
1105 assert_difference 'Issue.count', 2 do
1106 assert_no_difference 'Project.find(1).issues.count' do
1107 post :move, :ids => [1, 2], :new_project_id => 2, :copy_options => {:copy => '1'}, :new_tracker_id => '', :assigned_to_id => 4, :status_id => 3, :start_date => '2009-12-01', :due_date => '2009-12-31'
1108 end
1109 end
1110
1111 copied_issues = Issue.all(:limit => 2, :order => 'id desc', :conditions => {:project_id => 2})
1112 assert_equal 2, copied_issues.size
1113 copied_issues.each do |issue|
1114 assert_equal 2, issue.project_id, "Project is incorrect"
1115 assert_equal 4, issue.assigned_to_id, "Assigned to is incorrect"
1116 assert_equal 3, issue.status_id, "Status is incorrect"
1117 assert_equal '2009-12-01', issue.start_date.to_s, "Start date is incorrect"
1118 assert_equal '2009-12-31', issue.due_date.to_s, "Due date is incorrect"
1119 end
1120 end
1121 end
1122
1123 def test_copy_to_another_project_should_follow_when_needed
1124 @request.session[:user_id] = 2
1125 post :move, :ids => [1], :new_project_id => 2, :copy_options => {:copy => '1'}, :follow => '1'
1126 issue = Issue.first(:order => 'id DESC')
1127 assert_redirected_to :controller => 'issues', :action => 'show', :id => issue
1128 end
1129
1130 def test_context_menu_one_issue
1131 @request.session[:user_id] = 2
1132 get :context_menu, :ids => [1]
1133 assert_response :success
1134 assert_template 'context_menu'
1135 assert_tag :tag => 'a', :content => 'Edit',
1136 :attributes => { :href => '/issues/1/edit',
1137 :class => 'icon-edit' }
1138 assert_tag :tag => 'a', :content => 'Closed',
1139 :attributes => { :href => '/issues/1/edit?issue%5Bstatus_id%5D=5',
1140 :class => '' }
1141 assert_tag :tag => 'a', :content => 'Immediate',
1142 :attributes => { :href => '/issues/bulk_edit?ids%5B%5D=1&issue%5Bpriority_id%5D=8',
1143 :class => '' }
1144 # Versions
1145 assert_tag :tag => 'a', :content => '2.0',
1146 :attributes => { :href => '/issues/bulk_edit?ids%5B%5D=1&issue%5Bfixed_version_id%5D=3',
1147 :class => '' }
1148 assert_tag :tag => 'a', :content => 'eCookbook Subproject 1 - 2.0',
1149 :attributes => { :href => '/issues/bulk_edit?ids%5B%5D=1&issue%5Bfixed_version_id%5D=4',
1150 :class => '' }
1151
1152 assert_tag :tag => 'a', :content => 'Dave Lopper',
1153 :attributes => { :href => '/issues/bulk_edit?ids%5B%5D=1&issue%5Bassigned_to_id%5D=3',
1154 :class => '' }
1155 assert_tag :tag => 'a', :content => 'Duplicate',
1156 :attributes => { :href => '/projects/ecookbook/issues/1/copy',
1157 :class => 'icon-duplicate' }
1158 assert_tag :tag => 'a', :content => 'Copy',
1159 :attributes => { :href => '/issues/move?copy_options%5Bcopy%5D=t&ids%5B%5D=1',
1160 :class => 'icon-copy' }
1161 assert_tag :tag => 'a', :content => 'Move',
1162 :attributes => { :href => '/issues/move?ids%5B%5D=1',
1163 :class => 'icon-move' }
1164 assert_tag :tag => 'a', :content => 'Delete',
1165 :attributes => { :href => '/issues/destroy?ids%5B%5D=1',
1166 :class => 'icon-del' }
1167 end
1168
1169 def test_context_menu_one_issue_by_anonymous
1170 get :context_menu, :ids => [1]
1171 assert_response :success
1172 assert_template 'context_menu'
1173 assert_tag :tag => 'a', :content => 'Delete',
1174 :attributes => { :href => '#',
1175 :class => 'icon-del disabled' }
1176 end
1177
1178 def test_context_menu_multiple_issues_of_same_project
1179 @request.session[:user_id] = 2
1180 get :context_menu, :ids => [1, 2]
1181 assert_response :success
1182 assert_template 'context_menu'
1183 assert_tag :tag => 'a', :content => 'Edit',
1184 :attributes => { :href => '/issues/bulk_edit?ids%5B%5D=1&ids%5B%5D=2',
1185 :class => 'icon-edit' }
1186 assert_tag :tag => 'a', :content => 'Immediate',
1187 :attributes => { :href => '/issues/bulk_edit?ids%5B%5D=1&ids%5B%5D=2&issue%5Bpriority_id%5D=8',
1188 :class => '' }
1189 assert_tag :tag => 'a', :content => 'Dave Lopper',
1190 :attributes => { :href => '/issues/bulk_edit?ids%5B%5D=1&ids%5B%5D=2&issue%5Bassigned_to_id%5D=3',
1191 :class => '' }
1192 assert_tag :tag => 'a', :content => 'Copy',
1193 :attributes => { :href => '/issues/move?copy_options%5Bcopy%5D=t&ids%5B%5D=1&ids%5B%5D=2',
1194 :class => 'icon-copy' }
1195 assert_tag :tag => 'a', :content => 'Move',
1196 :attributes => { :href => '/issues/move?ids%5B%5D=1&ids%5B%5D=2',
1197 :class => 'icon-move' }
1198 assert_tag :tag => 'a', :content => 'Delete',
1199 :attributes => { :href => '/issues/destroy?ids%5B%5D=1&ids%5B%5D=2',
1200 :class => 'icon-del' }
1201 end
1202
1203 def test_context_menu_multiple_issues_of_different_project
1204 @request.session[:user_id] = 2
1205 get :context_menu, :ids => [1, 2, 4]
1206 assert_response :success
1207 assert_template 'context_menu'
1208 assert_tag :tag => 'a', :content => 'Delete',
1209 :attributes => { :href => '#',
1210 :class => 'icon-del disabled' }
1211 end
1212
1213 def test_preview_new_issue
1214 @request.session[:user_id] = 2
1215 post :preview, :project_id => '1', :issue => {:description => 'Foo'}
1216 assert_response :success
1217 assert_template 'preview'
1218 assert_not_nil assigns(:description)
1219 end
1220
1221 def test_preview_notes
1222 @request.session[:user_id] = 2
1223 post :preview, :project_id => '1', :id => 1, :issue => {:description => Issue.find(1).description}, :notes => 'Foo'
1224 assert_response :success
1225 assert_template 'preview'
1226 assert_not_nil assigns(:notes)
1227 end
1228
1229 def test_auto_complete_should_not_be_case_sensitive
1230 get :auto_complete, :project_id => 'ecookbook', :q => 'ReCiPe'
1231 assert_response :success
1232 assert_not_nil assigns(:issues)
1233 assert assigns(:issues).detect {|issue| issue.subject.match /recipe/}
1234 end
1235
1236 def test_auto_complete_should_return_issue_with_given_id
1237 get :auto_complete, :project_id => 'subproject1', :q => '13'
1238 assert_response :success
1239 assert_not_nil assigns(:issues)
1240 assert assigns(:issues).include?(Issue.find(13))
1241 end 1018 end
1242 1019
1243 def test_destroy_issue_with_no_time_entries 1020 def test_destroy_issue_with_no_time_entries
1244 assert_nil TimeEntry.find_by_issue_id(2) 1021 assert_nil TimeEntry.find_by_issue_id(2)
1245 @request.session[:user_id] = 2 1022 @request.session[:user_id] = 2