comparison test/functional/issues_controller_test.rb @ 1517:dffacf8a6908 redmine-2.5

Update to Redmine SVN revision 13367 on 2.5-stable branch
author Chris Cannam
date Tue, 09 Sep 2014 09:29:00 +0100
parents e248c7af89ec
children
comparison
equal deleted inserted replaced
1516:b450a9d58aed 1517:dffacf8a6908
57 assert_template 'index' 57 assert_template 'index'
58 assert_not_nil assigns(:issues) 58 assert_not_nil assigns(:issues)
59 assert_nil assigns(:project) 59 assert_nil assigns(:project)
60 60
61 # links to visible issues 61 # links to visible issues
62 assert_select 'a[href=/issues/1]', :text => /Can't print recipes/ 62 assert_select 'a[href=/issues/1]', :text => /#{ESCAPED_UCANT} print recipes/
63 assert_select 'a[href=/issues/5]', :text => /Subproject issue/ 63 assert_select 'a[href=/issues/5]', :text => /Subproject issue/
64 # private projects hidden 64 # private projects hidden
65 assert_select 'a[href=/issues/6]', 0 65 assert_select 'a[href=/issues/6]', 0
66 assert_select 'a[href=/issues/4]', 0 66 assert_select 'a[href=/issues/4]', 0
67 # project column 67 # project column
93 get :index, :project_id => 1 93 get :index, :project_id => 1
94 assert_response :success 94 assert_response :success
95 assert_template 'index' 95 assert_template 'index'
96 assert_not_nil assigns(:issues) 96 assert_not_nil assigns(:issues)
97 97
98 assert_select 'a[href=/issues/1]', :text => /Can't print recipes/ 98 assert_select 'a[href=/issues/1]', :text => /#{ESCAPED_UCANT} print recipes/
99 assert_select 'a[href=/issues/5]', 0 99 assert_select 'a[href=/issues/5]', 0
100 end 100 end
101 101
102 def test_index_with_project_and_subprojects 102 def test_index_with_project_and_subprojects
103 Setting.display_subprojects_issues = 1 103 Setting.display_subprojects_issues = 1
104 get :index, :project_id => 1 104 get :index, :project_id => 1
105 assert_response :success 105 assert_response :success
106 assert_template 'index' 106 assert_template 'index'
107 assert_not_nil assigns(:issues) 107 assert_not_nil assigns(:issues)
108 108
109 assert_select 'a[href=/issues/1]', :text => /Can't print recipes/ 109 assert_select 'a[href=/issues/1]', :text => /#{ESCAPED_UCANT} print recipes/
110 assert_select 'a[href=/issues/5]', :text => /Subproject issue/ 110 assert_select 'a[href=/issues/5]', :text => /Subproject issue/
111 assert_select 'a[href=/issues/6]', 0 111 assert_select 'a[href=/issues/6]', 0
112 end 112 end
113 113
114 def test_index_with_project_and_subprojects_should_show_private_subprojects_with_permission 114 def test_index_with_project_and_subprojects_should_show_private_subprojects_with_permission
117 get :index, :project_id => 1 117 get :index, :project_id => 1
118 assert_response :success 118 assert_response :success
119 assert_template 'index' 119 assert_template 'index'
120 assert_not_nil assigns(:issues) 120 assert_not_nil assigns(:issues)
121 121
122 assert_select 'a[href=/issues/1]', :text => /Can't print recipes/ 122 assert_select 'a[href=/issues/1]', :text => /#{ESCAPED_UCANT} print recipes/
123 assert_select 'a[href=/issues/5]', :text => /Subproject issue/ 123 assert_select 'a[href=/issues/5]', :text => /Subproject issue/
124 assert_select 'a[href=/issues/6]', :text => /Issue of a private subproject/ 124 assert_select 'a[href=/issues/6]', :text => /Issue of a private subproject/
125 end 125 end
126 126
127 def test_index_with_project_and_default_filter 127 def test_index_with_project_and_default_filter
371 assert_select 'a.csv[href=/issues.csv]' 371 assert_select 'a.csv[href=/issues.csv]'
372 assert_select 'a.pdf[href=/issues.pdf]' 372 assert_select 'a.pdf[href=/issues.pdf]'
373 assert_select 'form#csv-export-form[action=/issues.csv]' 373 assert_select 'form#csv-export-form[action=/issues.csv]'
374 end 374 end
375 375
376 def test_index_should_not_warn_when_not_exceeding_export_limit
377 with_settings :issues_export_limit => 200 do
378 get :index
379 assert_select '#csv-export-options p.icon-warning', 0
380 end
381 end
382
383 def test_index_should_warn_when_exceeding_export_limit
384 with_settings :issues_export_limit => 2 do
385 get :index
386 assert_select '#csv-export-options p.icon-warning', :text => %r{limit: 2}
387 end
388 end
389
376 def test_index_csv 390 def test_index_csv
377 get :index, :format => 'csv' 391 get :index, :format => 'csv'
378 assert_response :success 392 assert_response :success
379 assert_not_nil assigns(:issues) 393 assert_not_nil assigns(:issues)
380 assert_equal 'text/csv; header=present', @response.content_type 394 assert_equal 'text/csv; header=present', @response.content_type
876 assert_select 'fieldset' do 890 assert_select 'fieldset' do
877 assert_select 'legend', :text => 'Notes' 891 assert_select 'legend', :text => 'Notes'
878 assert_select 'textarea[name=?]', 'issue[notes]' 892 assert_select 'textarea[name=?]', 'issue[notes]'
879 end 893 end
880 end 894 end
881 assert_select 'title', :text => "Bug #1: Can't print recipes - eCookbook - Redmine" 895 assert_select 'title', :text => "Bug #1: #{ESCAPED_UCANT} print recipes - eCookbook - Redmine"
882 end 896 end
883 897
884 def test_show_by_manager 898 def test_show_by_manager
885 @request.session[:user_id] = 2 899 @request.session[:user_id] = 2
886 get :show, :id => 1 900 get :show, :id => 1
1024 get :show, :id => 1 1038 get :show, :id => 1
1025 assert_response :redirect 1039 assert_response :redirect
1026 end 1040 end
1027 1041
1028 def test_show_should_deny_anonymous_access_to_private_issue 1042 def test_show_should_deny_anonymous_access_to_private_issue
1029 Issue.update_all(["is_private = ?", true], "id = 1") 1043 Issue.where(:id => 1).update_all(["is_private = ?", true])
1030 get :show, :id => 1 1044 get :show, :id => 1
1031 assert_response :redirect 1045 assert_response :redirect
1032 end 1046 end
1033 1047
1034 def test_show_should_deny_non_member_access_without_permission 1048 def test_show_should_deny_non_member_access_without_permission
1037 get :show, :id => 1 1051 get :show, :id => 1
1038 assert_response 403 1052 assert_response 403
1039 end 1053 end
1040 1054
1041 def test_show_should_deny_non_member_access_to_private_issue 1055 def test_show_should_deny_non_member_access_to_private_issue
1042 Issue.update_all(["is_private = ?", true], "id = 1") 1056 Issue.where(:id => 1).update_all(["is_private = ?", true])
1043 @request.session[:user_id] = 9 1057 @request.session[:user_id] = 9
1044 get :show, :id => 1 1058 get :show, :id => 1
1045 assert_response 403 1059 assert_response 403
1046 end 1060 end
1047 1061
1051 get :show, :id => 1 1065 get :show, :id => 1
1052 assert_response 403 1066 assert_response 403
1053 end 1067 end
1054 1068
1055 def test_show_should_deny_member_access_to_private_issue_without_permission 1069 def test_show_should_deny_member_access_to_private_issue_without_permission
1056 Issue.update_all(["is_private = ?", true], "id = 1") 1070 Issue.where(:id => 1).update_all(["is_private = ?", true])
1057 @request.session[:user_id] = 3 1071 @request.session[:user_id] = 3
1058 get :show, :id => 1 1072 get :show, :id => 1
1059 assert_response 403 1073 assert_response 403
1060 end 1074 end
1061 1075
1062 def test_show_should_allow_author_access_to_private_issue 1076 def test_show_should_allow_author_access_to_private_issue
1063 Issue.update_all(["is_private = ?, author_id = 3", true], "id = 1") 1077 Issue.where(:id => 1).update_all(["is_private = ?, author_id = 3", true])
1064 @request.session[:user_id] = 3 1078 @request.session[:user_id] = 3
1065 get :show, :id => 1 1079 get :show, :id => 1
1066 assert_response :success 1080 assert_response :success
1067 end 1081 end
1068 1082
1069 def test_show_should_allow_assignee_access_to_private_issue 1083 def test_show_should_allow_assignee_access_to_private_issue
1070 Issue.update_all(["is_private = ?, assigned_to_id = 3", true], "id = 1") 1084 Issue.where(:id => 1).update_all(["is_private = ?, assigned_to_id = 3", true])
1071 @request.session[:user_id] = 3 1085 @request.session[:user_id] = 3
1072 get :show, :id => 1 1086 get :show, :id => 1
1073 assert_response :success 1087 assert_response :success
1074 end 1088 end
1075 1089
1076 def test_show_should_allow_member_access_to_private_issue_with_permission 1090 def test_show_should_allow_member_access_to_private_issue_with_permission
1077 Issue.update_all(["is_private = ?", true], "id = 1") 1091 Issue.where(:id => 1).update_all(["is_private = ?", true])
1078 User.find(3).roles_for_project(Project.find(1)).first.update_attribute :issues_visibility, 'all' 1092 User.find(3).roles_for_project(Project.find(1)).first.update_attribute :issues_visibility, 'all'
1079 @request.session[:user_id] = 3 1093 @request.session[:user_id] = 3
1080 get :show, :id => 1 1094 get :show, :id => 1
1081 assert_response :success 1095 assert_response :success
1082 end 1096 end
1359 issue.save! 1373 issue.save!
1360 1374
1361 get :show, :id => 1 1375 get :show, :id => 1
1362 assert_response :success 1376 assert_response :success
1363 1377
1364 # TODO: should display links 1378 assert_select "td.cf_#{field.id}", :text => 'Dave Lopper, John Smith' do
1365 assert_select 'td', :text => 'Dave Lopper, John Smith' 1379 assert_select 'a', :text => 'Dave Lopper'
1380 assert_select 'a', :text => 'John Smith'
1381 end
1366 end 1382 end
1367 1383
1368 def test_show_should_display_private_notes_with_permission_only 1384 def test_show_should_display_private_notes_with_permission_only
1369 journal = Journal.create!(:journalized => Issue.find(2), :notes => 'Privates notes', :private_notes => true, :user_id => 1) 1385 journal = Journal.create!(:journalized => Issue.find(2), :notes => 'Privates notes', :private_notes => true, :user_id => 1)
1370 @request.session[:user_id] = 2 1386 @request.session[:user_id] = 2
1421 assert_equal 'application/pdf', @response.content_type 1437 assert_equal 'application/pdf', @response.content_type
1422 assert @response.body.starts_with?('%PDF') 1438 assert @response.body.starts_with?('%PDF')
1423 end 1439 end
1424 1440
1425 def test_show_export_to_pdf_with_changesets 1441 def test_show_export_to_pdf_with_changesets
1426 Issue.find(3).changesets = Changeset.find_all_by_id(100, 101, 102) 1442 [[100], [100, 101], [100, 101, 102]].each do |cs|
1427 1443 issue1 = Issue.find(3)
1428 get :show, :id => 3, :format => 'pdf' 1444 issue1.changesets = Changeset.find(cs)
1429 assert_response :success 1445 issue1.save!
1430 assert_equal 'application/pdf', @response.content_type 1446 issue = Issue.find(3)
1431 assert @response.body.starts_with?('%PDF') 1447 assert_equal issue.changesets.count, cs.size
1448 get :show, :id => 3, :format => 'pdf'
1449 assert_response :success
1450 assert_equal 'application/pdf', @response.content_type
1451 assert @response.body.starts_with?('%PDF')
1452 end
1432 end 1453 end
1433 1454
1434 def test_show_invalid_should_respond_with_404 1455 def test_show_invalid_should_respond_with_404
1435 get :show, :id => 999 1456 get :show, :id => 999
1436 assert_response 404 1457 assert_response 404
1689 :subject => 'This is the test_new issue', 1710 :subject => 'This is the test_new issue',
1690 :description => 'This is the description', 1711 :description => 'This is the description',
1691 :priority_id => 5} 1712 :priority_id => 5}
1692 assert_response :success 1713 assert_response :success
1693 assert_template 'update_form' 1714 assert_template 'update_form'
1694 assert_template 'form' 1715 assert_template :partial => '_form'
1695 assert_equal 'text/javascript', response.content_type 1716 assert_equal 'text/javascript', response.content_type
1696 1717
1697 issue = assigns(:issue) 1718 issue = assigns(:issue)
1698 assert_kind_of Issue, issue 1719 assert_kind_of Issue, issue
1699 assert_equal 1, issue.project_id 1720 assert_equal 1, issue.project_id
1814 post :create, :project_id => 1, 1835 post :create, :project_id => 1,
1815 :issue => {:tracker_id => 3, :subject => 'This is first issue', :priority_id => 5}, 1836 :issue => {:tracker_id => 3, :subject => 'This is first issue', :priority_id => 5},
1816 :continue => '' 1837 :continue => ''
1817 end 1838 end
1818 1839
1819 issue = Issue.first(:order => 'id DESC') 1840 issue = Issue.order('id DESC').first
1820 assert_redirected_to :controller => 'issues', :action => 'new', :project_id => 'ecookbook', :issue => {:tracker_id => 3} 1841 assert_redirected_to :controller => 'issues', :action => 'new', :project_id => 'ecookbook', :issue => {:tracker_id => 3}
1821 assert_not_nil flash[:notice], "flash was not set" 1842 assert_not_nil flash[:notice], "flash was not set"
1822 assert_include %|<a href="/issues/#{issue.id}" title="This is first issue">##{issue.id}</a>|, flash[:notice], "issue link not found in the flash message" 1843 assert_include %|<a href="/issues/#{issue.id}" title="This is first issue">##{issue.id}</a>|, flash[:notice], "issue link not found in the flash message"
1823 end 1844 end
1824 1845
1846 :description => 'This is the description', 1867 :description => 'This is the description',
1847 :priority_id => 5, 1868 :priority_id => 5,
1848 :custom_field_values => {'1' => ['', 'MySQL', 'Oracle']}} 1869 :custom_field_values => {'1' => ['', 'MySQL', 'Oracle']}}
1849 end 1870 end
1850 assert_response 302 1871 assert_response 302
1851 issue = Issue.first(:order => 'id DESC') 1872 issue = Issue.order('id DESC').first
1852 assert_equal ['MySQL', 'Oracle'], issue.custom_field_value(1).sort 1873 assert_equal ['MySQL', 'Oracle'], issue.custom_field_value(1).sort
1853 end 1874 end
1854 1875
1855 def test_post_create_with_empty_multi_custom_field 1876 def test_post_create_with_empty_multi_custom_field
1856 field = IssueCustomField.find_by_name('Database') 1877 field = IssueCustomField.find_by_name('Database')
1864 :description => 'This is the description', 1885 :description => 'This is the description',
1865 :priority_id => 5, 1886 :priority_id => 5,
1866 :custom_field_values => {'1' => ['']}} 1887 :custom_field_values => {'1' => ['']}}
1867 end 1888 end
1868 assert_response 302 1889 assert_response 302
1869 issue = Issue.first(:order => 'id DESC') 1890 issue = Issue.order('id DESC').first
1870 assert_equal [''], issue.custom_field_value(1).sort 1891 assert_equal [''], issue.custom_field_value(1).sort
1871 end 1892 end
1872 1893
1873 def test_post_create_with_multi_user_custom_field 1894 def test_post_create_with_multi_user_custom_field
1874 field = IssueCustomField.create!(:name => 'Multi user', :field_format => 'user', :multiple => true, 1895 field = IssueCustomField.create!(:name => 'Multi user', :field_format => 'user', :multiple => true,
1882 :description => 'This is the description', 1903 :description => 'This is the description',
1883 :priority_id => 5, 1904 :priority_id => 5,
1884 :custom_field_values => {field.id.to_s => ['', '2', '3']}} 1905 :custom_field_values => {field.id.to_s => ['', '2', '3']}}
1885 end 1906 end
1886 assert_response 302 1907 assert_response 302
1887 issue = Issue.first(:order => 'id DESC') 1908 issue = Issue.order('id DESC').first
1888 assert_equal ['2', '3'], issue.custom_field_value(field).sort 1909 assert_equal ['2', '3'], issue.custom_field_value(field).sort
1889 end 1910 end
1890 1911
1891 def test_post_create_with_required_custom_field_and_without_custom_fields_param 1912 def test_post_create_with_required_custom_field_and_without_custom_fields_param
1892 field = IssueCustomField.find_by_name('Database') 1913 field = IssueCustomField.find_by_name('Database')
1902 end 1923 end
1903 assert_response :success 1924 assert_response :success
1904 assert_template 'new' 1925 assert_template 'new'
1905 issue = assigns(:issue) 1926 issue = assigns(:issue)
1906 assert_not_nil issue 1927 assert_not_nil issue
1907 assert_error_tag :content => /Database can&#x27;t be blank/ 1928 assert_error_tag :content => /Database #{ESCAPED_CANT} be blank/
1908 end 1929 end
1909 1930
1910 def test_create_should_validate_required_fields 1931 def test_create_should_validate_required_fields
1911 cf1 = IssueCustomField.create!(:name => 'Foo', :field_format => 'string', :is_for_all => true, :tracker_ids => [1, 2]) 1932 cf1 = IssueCustomField.create!(:name => 'Foo', :field_format => 'string', :is_for_all => true, :tracker_ids => [1, 2])
1912 cf2 = IssueCustomField.create!(:name => 'Bar', :field_format => 'string', :is_for_all => true, :tracker_ids => [1, 2]) 1933 cf2 = IssueCustomField.create!(:name => 'Bar', :field_format => 'string', :is_for_all => true, :tracker_ids => [1, 2])
1926 } 1947 }
1927 assert_response :success 1948 assert_response :success
1928 assert_template 'new' 1949 assert_template 'new'
1929 end 1950 end
1930 1951
1931 assert_error_tag :content => /Due date can&#x27;t be blank/i 1952 assert_error_tag :content => /Due date #{ESCAPED_CANT} be blank/i
1932 assert_error_tag :content => /Bar can&#x27;t be blank/i 1953 assert_error_tag :content => /Bar #{ESCAPED_CANT} be blank/i
1933 end 1954 end
1934 1955
1935 def test_create_should_ignore_readonly_fields 1956 def test_create_should_ignore_readonly_fields
1936 cf1 = IssueCustomField.create!(:name => 'Foo', :field_format => 'string', :is_for_all => true, :tracker_ids => [1, 2]) 1957 cf1 = IssueCustomField.create!(:name => 'Foo', :field_format => 'string', :is_for_all => true, :tracker_ids => [1, 2])
1937 cf2 = IssueCustomField.create!(:name => 'Bar', :field_format => 'string', :is_for_all => true, :tracker_ids => [1, 2]) 1958 cf2 = IssueCustomField.create!(:name => 'Bar', :field_format => 'string', :is_for_all => true, :tracker_ids => [1, 2])
1950 :custom_field_values => {cf1.id.to_s => 'value1', cf2.id.to_s => 'value2'} 1971 :custom_field_values => {cf1.id.to_s => 'value1', cf2.id.to_s => 'value2'}
1951 } 1972 }
1952 assert_response 302 1973 assert_response 302
1953 end 1974 end
1954 1975
1955 issue = Issue.first(:order => 'id DESC') 1976 issue = Issue.order('id DESC').first
1956 assert_equal Date.parse('2012-07-14'), issue.start_date 1977 assert_equal Date.parse('2012-07-14'), issue.start_date
1957 assert_nil issue.due_date 1978 assert_nil issue.due_date
1958 assert_equal 'value1', issue.custom_field_value(cf1) 1979 assert_equal 'value1', issue.custom_field_value(cf1)
1959 assert_nil issue.custom_field_value(cf2) 1980 assert_nil issue.custom_field_value(cf2)
1960 end 1981 end
2049 post :create, :project_id => 1, 2070 post :create, :project_id => 1,
2050 :issue => {:tracker_id => 1, 2071 :issue => {:tracker_id => 1,
2051 :subject => 'This is a private issue', 2072 :subject => 'This is a private issue',
2052 :is_private => '1'} 2073 :is_private => '1'}
2053 end 2074 end
2054 issue = Issue.first(:order => 'id DESC') 2075 issue = Issue.order('id DESC').first
2055 assert issue.is_private? 2076 assert issue.is_private?
2056 end 2077 end
2057 2078
2058 def test_post_create_private_with_set_own_issues_private_permission 2079 def test_post_create_private_with_set_own_issues_private_permission
2059 role = Role.find(1) 2080 role = Role.find(1)
2066 post :create, :project_id => 1, 2087 post :create, :project_id => 1,
2067 :issue => {:tracker_id => 1, 2088 :issue => {:tracker_id => 1,
2068 :subject => 'This is a private issue', 2089 :subject => 'This is a private issue',
2069 :is_private => '1'} 2090 :is_private => '1'}
2070 end 2091 end
2071 issue = Issue.first(:order => 'id DESC') 2092 issue = Issue.order('id DESC').first
2072 assert issue.is_private? 2093 assert issue.is_private?
2073 end 2094 end
2074 2095
2075 def test_post_create_should_send_a_notification 2096 def test_post_create_should_send_a_notification
2076 ActionMailer::Base.deliveries.clear 2097 ActionMailer::Base.deliveries.clear
2144 :issue => { :tracker_id => '1', :subject => 'With attachment' }, 2165 :issue => { :tracker_id => '1', :subject => 'With attachment' },
2145 :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain'), 'description' => 'test file'}} 2166 :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain'), 'description' => 'test file'}}
2146 end 2167 end
2147 end 2168 end
2148 2169
2149 issue = Issue.first(:order => 'id DESC') 2170 issue = Issue.order('id DESC').first
2150 attachment = Attachment.first(:order => 'id DESC') 2171 attachment = Attachment.order('id DESC').first
2151 2172
2152 assert_equal issue, attachment.container 2173 assert_equal issue, attachment.container
2153 assert_equal 2, attachment.author_id 2174 assert_equal 2, attachment.author_id
2154 assert_equal 'testfile.txt', attachment.filename 2175 assert_equal 'testfile.txt', attachment.filename
2155 assert_equal 'text/plain', attachment.content_type 2176 assert_equal 'text/plain', attachment.content_type
2190 assert_response :success 2211 assert_response :success
2191 assert_template 'new' 2212 assert_template 'new'
2192 end 2213 end
2193 end 2214 end
2194 2215
2195 attachment = Attachment.first(:order => 'id DESC') 2216 attachment = Attachment.order('id DESC').first
2196 assert_equal 'testfile.txt', attachment.filename 2217 assert_equal 'testfile.txt', attachment.filename
2197 assert File.exists?(attachment.diskfile) 2218 assert File.exists?(attachment.diskfile)
2198 assert_nil attachment.container 2219 assert_nil attachment.container
2199 2220
2200 assert_select 'input[name=?][value=?]', 'attachments[p0][token]', attachment.token 2221 assert_select 'input[name=?][value=?]', 'attachments[p0][token]', attachment.token
2232 :attachments => {'p0' => {'token' => attachment.token}} 2253 :attachments => {'p0' => {'token' => attachment.token}}
2233 assert_response 302 2254 assert_response 302
2234 end 2255 end
2235 end 2256 end
2236 2257
2237 issue = Issue.first(:order => 'id DESC') 2258 issue = Issue.order('id DESC').first
2238 assert_equal 1, issue.attachments.count 2259 assert_equal 1, issue.attachments.count
2239 2260
2240 attachment.reload 2261 attachment.reload
2241 assert_equal issue, attachment.container 2262 assert_equal issue, attachment.container
2242 end 2263 end
2243 2264
2244 context "without workflow privilege" do 2265 def setup_without_workflow_privilege
2245 setup do 2266 WorkflowTransition.delete_all(["role_id = ?", Role.anonymous.id])
2246 WorkflowTransition.delete_all(["role_id = ?", Role.anonymous.id]) 2267 Role.anonymous.add_permission! :add_issues, :add_issue_notes
2247 Role.anonymous.add_permission! :add_issues, :add_issue_notes 2268 end
2248 end 2269 private :setup_without_workflow_privilege
2249 2270
2250 context "#new" do 2271 test "without workflow privilege #new should propose default status only" do
2251 should "propose default status only" do 2272 setup_without_workflow_privilege
2252 get :new, :project_id => 1 2273 get :new, :project_id => 1
2253 assert_response :success 2274 assert_response :success
2254 assert_template 'new' 2275 assert_template 'new'
2255 assert_select 'select[name=?]', 'issue[status_id]' do 2276 assert_select 'select[name=?]', 'issue[status_id]' do
2256 assert_select 'option', 1 2277 assert_select 'option', 1
2257 assert_select 'option[value=?]', IssueStatus.default.id.to_s 2278 assert_select 'option[value=?]', IssueStatus.default.id.to_s
2258 end 2279 end
2259 end 2280 end
2260 2281
2261 should "accept default status" do 2282 test "without workflow privilege #new should accept default status" do
2262 assert_difference 'Issue.count' do 2283 setup_without_workflow_privilege
2263 post :create, :project_id => 1, 2284 assert_difference 'Issue.count' do
2264 :issue => {:tracker_id => 1, 2285 post :create, :project_id => 1,
2286 :issue => {:tracker_id => 1,
2265 :subject => 'This is an issue', 2287 :subject => 'This is an issue',
2266 :status_id => 1} 2288 :status_id => 1}
2267 end 2289 end
2268 issue = Issue.last(:order => 'id') 2290 issue = Issue.order('id').last
2269 assert_equal IssueStatus.default, issue.status 2291 assert_equal IssueStatus.default, issue.status
2270 end 2292 end
2271 2293
2272 should "ignore unauthorized status" do 2294 test "without workflow privilege #new should ignore unauthorized status" do
2273 assert_difference 'Issue.count' do 2295 setup_without_workflow_privilege
2274 post :create, :project_id => 1, 2296 assert_difference 'Issue.count' do
2297 post :create, :project_id => 1,
2275 :issue => {:tracker_id => 1, 2298 :issue => {:tracker_id => 1,
2276 :subject => 'This is an issue', 2299 :subject => 'This is an issue',
2277 :status_id => 3} 2300 :status_id => 3}
2278 end 2301 end
2279 issue = Issue.last(:order => 'id') 2302 issue = Issue.order('id').last
2280 assert_equal IssueStatus.default, issue.status 2303 assert_equal IssueStatus.default, issue.status
2281 end 2304 end
2282 end 2305
2283 2306 test "without workflow privilege #update should ignore status change" do
2284 context "#update" do 2307 setup_without_workflow_privilege
2285 should "ignore status change" do 2308 assert_difference 'Journal.count' do
2286 assert_difference 'Journal.count' do 2309 put :update, :id => 1, :issue => {:status_id => 3, :notes => 'just trying'}
2287 put :update, :id => 1, :issue => {:status_id => 3, :notes => 'just trying'} 2310 end
2288 end 2311 assert_equal 1, Issue.find(1).status_id
2289 assert_equal 1, Issue.find(1).status_id 2312 end
2290 end 2313
2291 2314 test "without workflow privilege #update ignore attributes changes" do
2292 should "ignore attributes changes" do 2315 setup_without_workflow_privilege
2293 assert_difference 'Journal.count' do 2316 assert_difference 'Journal.count' do
2294 put :update, :id => 1, :issue => {:subject => 'changed', :assigned_to_id => 2, :notes => 'just trying'} 2317 put :update, :id => 1,
2295 end 2318 :issue => {:subject => 'changed', :assigned_to_id => 2,
2296 issue = Issue.find(1) 2319 :notes => 'just trying'}
2297 assert_equal "Can't print recipes", issue.subject 2320 end
2298 assert_nil issue.assigned_to 2321 issue = Issue.find(1)
2299 end 2322 assert_equal "Can't print recipes", issue.subject
2300 end 2323 assert_nil issue.assigned_to
2301 end 2324 end
2302 2325
2303 context "with workflow privilege" do 2326 def setup_with_workflow_privilege
2304 setup do 2327 WorkflowTransition.delete_all(["role_id = ?", Role.anonymous.id])
2305 WorkflowTransition.delete_all(["role_id = ?", Role.anonymous.id]) 2328 WorkflowTransition.create!(:role => Role.anonymous, :tracker_id => 1,
2306 WorkflowTransition.create!(:role => Role.anonymous, :tracker_id => 1, :old_status_id => 1, :new_status_id => 3) 2329 :old_status_id => 1, :new_status_id => 3)
2307 WorkflowTransition.create!(:role => Role.anonymous, :tracker_id => 1, :old_status_id => 1, :new_status_id => 4) 2330 WorkflowTransition.create!(:role => Role.anonymous, :tracker_id => 1,
2308 Role.anonymous.add_permission! :add_issues, :add_issue_notes 2331 :old_status_id => 1, :new_status_id => 4)
2309 end 2332 Role.anonymous.add_permission! :add_issues, :add_issue_notes
2310 2333 end
2311 context "#update" do 2334 private :setup_with_workflow_privilege
2312 should "accept authorized status" do 2335
2313 assert_difference 'Journal.count' do 2336 test "with workflow privilege #update should accept authorized status" do
2314 put :update, :id => 1, :issue => {:status_id => 3, :notes => 'just trying'} 2337 setup_with_workflow_privilege
2315 end 2338 assert_difference 'Journal.count' do
2316 assert_equal 3, Issue.find(1).status_id 2339 put :update, :id => 1, :issue => {:status_id => 3, :notes => 'just trying'}
2317 end 2340 end
2318 2341 assert_equal 3, Issue.find(1).status_id
2319 should "ignore unauthorized status" do 2342 end
2320 assert_difference 'Journal.count' do 2343
2321 put :update, :id => 1, :issue => {:status_id => 2, :notes => 'just trying'} 2344 test "with workflow privilege #update should ignore unauthorized status" do
2322 end 2345 setup_with_workflow_privilege
2323 assert_equal 1, Issue.find(1).status_id 2346 assert_difference 'Journal.count' do
2324 end 2347 put :update, :id => 1, :issue => {:status_id => 2, :notes => 'just trying'}
2325 2348 end
2326 should "accept authorized attributes changes" do 2349 assert_equal 1, Issue.find(1).status_id
2327 assert_difference 'Journal.count' do 2350 end
2328 put :update, :id => 1, :issue => {:assigned_to_id => 2, :notes => 'just trying'} 2351
2329 end 2352 test "with workflow privilege #update should accept authorized attributes changes" do
2330 issue = Issue.find(1) 2353 setup_with_workflow_privilege
2331 assert_equal 2, issue.assigned_to_id 2354 assert_difference 'Journal.count' do
2332 end 2355 put :update, :id => 1, :issue => {:assigned_to_id => 2, :notes => 'just trying'}
2333 2356 end
2334 should "ignore unauthorized attributes changes" do 2357 issue = Issue.find(1)
2335 assert_difference 'Journal.count' do 2358 assert_equal 2, issue.assigned_to_id
2336 put :update, :id => 1, :issue => {:subject => 'changed', :notes => 'just trying'} 2359 end
2337 end 2360
2338 issue = Issue.find(1) 2361 test "with workflow privilege #update should ignore unauthorized attributes changes" do
2339 assert_equal "Can't print recipes", issue.subject 2362 setup_with_workflow_privilege
2340 end 2363 assert_difference 'Journal.count' do
2341 end 2364 put :update, :id => 1, :issue => {:subject => 'changed', :notes => 'just trying'}
2342 2365 end
2343 context "and :edit_issues permission" do 2366 issue = Issue.find(1)
2344 setup do 2367 assert_equal "Can't print recipes", issue.subject
2345 Role.anonymous.add_permission! :add_issues, :edit_issues 2368 end
2346 end 2369
2347 2370 def setup_with_workflow_privilege_and_edit_issues_permission
2348 should "accept authorized status" do 2371 setup_with_workflow_privilege
2349 assert_difference 'Journal.count' do 2372 Role.anonymous.add_permission! :add_issues, :edit_issues
2350 put :update, :id => 1, :issue => {:status_id => 3, :notes => 'just trying'} 2373 end
2351 end 2374 private :setup_with_workflow_privilege_and_edit_issues_permission
2352 assert_equal 3, Issue.find(1).status_id 2375
2353 end 2376 test "with workflow privilege and :edit_issues permission should accept authorized status" do
2354 2377 setup_with_workflow_privilege_and_edit_issues_permission
2355 should "ignore unauthorized status" do 2378 assert_difference 'Journal.count' do
2356 assert_difference 'Journal.count' do 2379 put :update, :id => 1, :issue => {:status_id => 3, :notes => 'just trying'}
2357 put :update, :id => 1, :issue => {:status_id => 2, :notes => 'just trying'} 2380 end
2358 end 2381 assert_equal 3, Issue.find(1).status_id
2359 assert_equal 1, Issue.find(1).status_id 2382 end
2360 end 2383
2361 2384 test "with workflow privilege and :edit_issues permission should ignore unauthorized status" do
2362 should "accept authorized attributes changes" do 2385 setup_with_workflow_privilege_and_edit_issues_permission
2363 assert_difference 'Journal.count' do 2386 assert_difference 'Journal.count' do
2364 put :update, :id => 1, :issue => {:subject => 'changed', :assigned_to_id => 2, :notes => 'just trying'} 2387 put :update, :id => 1, :issue => {:status_id => 2, :notes => 'just trying'}
2365 end 2388 end
2366 issue = Issue.find(1) 2389 assert_equal 1, Issue.find(1).status_id
2367 assert_equal "changed", issue.subject 2390 end
2368 assert_equal 2, issue.assigned_to_id 2391
2369 end 2392 test "with workflow privilege and :edit_issues permission should accept authorized attributes changes" do
2370 end 2393 setup_with_workflow_privilege_and_edit_issues_permission
2394 assert_difference 'Journal.count' do
2395 put :update, :id => 1,
2396 :issue => {:subject => 'changed', :assigned_to_id => 2,
2397 :notes => 'just trying'}
2398 end
2399 issue = Issue.find(1)
2400 assert_equal "changed", issue.subject
2401 assert_equal 2, issue.assigned_to_id
2371 end 2402 end
2372 2403
2373 def test_new_as_copy 2404 def test_new_as_copy
2374 @request.session[:user_id] = 2 2405 @request.session[:user_id] = 2
2375 get :new, :project_id => 1, :copy_from => 1 2406 get :new, :project_id => 1, :copy_from => 1
2434 :issue => {:project_id => '2', :tracker_id => '3', :status_id => '1', :subject => 'Copy'} 2465 :issue => {:project_id => '2', :tracker_id => '3', :status_id => '1', :subject => 'Copy'}
2435 2466
2436 assert_not_nil assigns(:issue) 2467 assert_not_nil assigns(:issue)
2437 assert assigns(:issue).copy? 2468 assert assigns(:issue).copy?
2438 end 2469 end
2439 issue = Issue.first(:order => 'id DESC') 2470 issue = Issue.order('id DESC').first
2440 assert_redirected_to "/issues/#{issue.id}" 2471 assert_redirected_to "/issues/#{issue.id}"
2441 2472
2442 assert_equal 2, issue.project_id 2473 assert_equal 2, issue.project_id
2443 assert_equal 3, issue.tracker_id 2474 assert_equal 3, issue.tracker_id
2444 assert_equal 'Copy', issue.subject 2475 assert_equal 'Copy', issue.subject
2457 :status_id => '1', :subject => 'Copy with attachments'}, 2488 :status_id => '1', :subject => 'Copy with attachments'},
2458 :copy_attachments => '1' 2489 :copy_attachments => '1'
2459 end 2490 end
2460 end 2491 end
2461 end 2492 end
2462 copy = Issue.first(:order => 'id DESC') 2493 copy = Issue.order('id DESC').first
2463 assert_equal count, copy.attachments.count 2494 assert_equal count, copy.attachments.count
2464 assert_equal issue.attachments.map(&:filename).sort, copy.attachments.map(&:filename).sort 2495 assert_equal issue.attachments.map(&:filename).sort, copy.attachments.map(&:filename).sort
2465 end 2496 end
2466 2497
2467 def test_create_as_copy_without_copy_attachments_option_should_not_copy_attachments 2498 def test_create_as_copy_without_copy_attachments_option_should_not_copy_attachments
2476 :issue => {:project_id => '1', :tracker_id => '3', 2507 :issue => {:project_id => '1', :tracker_id => '3',
2477 :status_id => '1', :subject => 'Copy with attachments'} 2508 :status_id => '1', :subject => 'Copy with attachments'}
2478 end 2509 end
2479 end 2510 end
2480 end 2511 end
2481 copy = Issue.first(:order => 'id DESC') 2512 copy = Issue.order('id DESC').first
2482 assert_equal 0, copy.attachments.count 2513 assert_equal 0, copy.attachments.count
2483 end 2514 end
2484 2515
2485 def test_create_as_copy_with_attachments_should_add_new_files 2516 def test_create_as_copy_with_attachments_should_add_new_files
2486 @request.session[:user_id] = 2 2517 @request.session[:user_id] = 2
2498 {'file' => uploaded_test_file('testfile.txt', 'text/plain'), 2529 {'file' => uploaded_test_file('testfile.txt', 'text/plain'),
2499 'description' => 'test file'}} 2530 'description' => 'test file'}}
2500 end 2531 end
2501 end 2532 end
2502 end 2533 end
2503 copy = Issue.first(:order => 'id DESC') 2534 copy = Issue.order('id DESC').first
2504 assert_equal count + 1, copy.attachments.count 2535 assert_equal count + 1, copy.attachments.count
2505 end 2536 end
2506 2537
2507 def test_create_as_copy_should_add_relation_with_copied_issue 2538 def test_create_as_copy_should_add_relation_with_copied_issue
2508 @request.session[:user_id] = 2 2539 @request.session[:user_id] = 2
2511 post :create, :project_id => 1, :copy_from => 1, 2542 post :create, :project_id => 1, :copy_from => 1,
2512 :issue => {:project_id => '1', :tracker_id => '3', 2543 :issue => {:project_id => '1', :tracker_id => '3',
2513 :status_id => '1', :subject => 'Copy'} 2544 :status_id => '1', :subject => 'Copy'}
2514 end 2545 end
2515 end 2546 end
2516 copy = Issue.first(:order => 'id DESC') 2547 copy = Issue.order('id DESC').first
2517 assert_equal 1, copy.relations.size 2548 assert_equal 1, copy.relations.size
2518 end 2549 end
2519 2550
2520 def test_create_as_copy_should_copy_subtasks 2551 def test_create_as_copy_should_copy_subtasks
2521 @request.session[:user_id] = 2 2552 @request.session[:user_id] = 2
2527 :issue => {:project_id => '1', :tracker_id => '3', 2558 :issue => {:project_id => '1', :tracker_id => '3',
2528 :status_id => '1', :subject => 'Copy with subtasks'}, 2559 :status_id => '1', :subject => 'Copy with subtasks'},
2529 :copy_subtasks => '1' 2560 :copy_subtasks => '1'
2530 end 2561 end
2531 end 2562 end
2532 copy = Issue.where(:parent_id => nil).first(:order => 'id DESC') 2563 copy = Issue.where(:parent_id => nil).order('id DESC').first
2533 assert_equal count, copy.descendants.count 2564 assert_equal count, copy.descendants.count
2534 assert_equal issue.descendants.map(&:subject).sort, copy.descendants.map(&:subject).sort 2565 assert_equal issue.descendants.map(&:subject).sort, copy.descendants.map(&:subject).sort
2535 end 2566 end
2536 2567
2537 def test_create_as_copy_without_copy_subtasks_option_should_not_copy_subtasks 2568 def test_create_as_copy_without_copy_subtasks_option_should_not_copy_subtasks
2542 post :create, :project_id => 1, :copy_from => 3, 2573 post :create, :project_id => 1, :copy_from => 3,
2543 :issue => {:project_id => '1', :tracker_id => '3', 2574 :issue => {:project_id => '1', :tracker_id => '3',
2544 :status_id => '1', :subject => 'Copy with subtasks'} 2575 :status_id => '1', :subject => 'Copy with subtasks'}
2545 end 2576 end
2546 end 2577 end
2547 copy = Issue.where(:parent_id => nil).first(:order => 'id DESC') 2578 copy = Issue.where(:parent_id => nil).order('id DESC').first
2548 assert_equal 0, copy.descendants.count 2579 assert_equal 0, copy.descendants.count
2549 end 2580 end
2550 2581
2551 def test_create_as_copy_with_failure 2582 def test_create_as_copy_with_failure
2552 @request.session[:user_id] = 2 2583 @request.session[:user_id] = 2
2574 2605
2575 assert_difference 'Issue.count' do 2606 assert_difference 'Issue.count' do
2576 post :create, :project_id => 1, :copy_from => 1, 2607 post :create, :project_id => 1, :copy_from => 1,
2577 :issue => {:project_id => '4', :tracker_id => '3', :status_id => '1', :subject => 'Copy'} 2608 :issue => {:project_id => '4', :tracker_id => '3', :status_id => '1', :subject => 'Copy'}
2578 end 2609 end
2579 issue = Issue.first(:order => 'id DESC') 2610 issue = Issue.order('id DESC').first
2580 assert_equal 1, issue.project_id 2611 assert_equal 1, issue.project_id
2581 end 2612 end
2582 2613
2583 def test_get_edit 2614 def test_get_edit
2584 @request.session[:user_id] = 2 2615 @request.session[:user_id] = 2
2667 :description => 'This is the description', 2698 :description => 'This is the description',
2668 :priority_id => 5} 2699 :priority_id => 5}
2669 assert_response :success 2700 assert_response :success
2670 assert_equal 'text/javascript', response.content_type 2701 assert_equal 'text/javascript', response.content_type
2671 assert_template 'update_form' 2702 assert_template 'update_form'
2672 assert_template 'form' 2703 assert_template :partial => '_form'
2673 2704
2674 issue = assigns(:issue) 2705 issue = assigns(:issue)
2675 assert_kind_of Issue, issue 2706 assert_kind_of Issue, issue
2676 assert_equal 1, issue.id 2707 assert_equal 1, issue.id
2677 assert_equal 1, issue.project_id 2708 assert_equal 1, issue.project_id
2716 :tracker_id => 2, 2747 :tracker_id => 2,
2717 :subject => 'This is the test_new issue', 2748 :subject => 'This is the test_new issue',
2718 :description => 'This is the description', 2749 :description => 'This is the description',
2719 :priority_id => 5} 2750 :priority_id => 5}
2720 assert_response :success 2751 assert_response :success
2721 assert_template 'form' 2752 assert_template :partial => '_form'
2722 2753
2723 issue = assigns(:issue) 2754 issue = assigns(:issue)
2724 assert_kind_of Issue, issue 2755 assert_kind_of Issue, issue
2725 assert_equal 1, issue.id 2756 assert_equal 1, issue.id
2726 assert_equal 2, issue.project_id 2757 assert_equal 2, issue.project_id
2991 assert j.notes.blank? 3022 assert j.notes.blank?
2992 assert_equal 1, j.details.size 3023 assert_equal 1, j.details.size
2993 assert_equal 'testfile.txt', j.details.first.value 3024 assert_equal 'testfile.txt', j.details.first.value
2994 assert_equal User.anonymous, j.user 3025 assert_equal User.anonymous, j.user
2995 3026
2996 attachment = Attachment.first(:order => 'id DESC') 3027 attachment = Attachment.order('id DESC').first
2997 assert_equal Issue.find(1), attachment.container 3028 assert_equal Issue.find(1), attachment.container
2998 assert_equal User.anonymous, attachment.author 3029 assert_equal User.anonymous, attachment.author
2999 assert_equal 'testfile.txt', attachment.filename 3030 assert_equal 'testfile.txt', attachment.filename
3000 assert_equal 'text/plain', attachment.content_type 3031 assert_equal 'text/plain', attachment.content_type
3001 assert_equal 'test file', attachment.description 3032 assert_equal 'test file', attachment.description
3019 assert_response :success 3050 assert_response :success
3020 assert_template 'edit' 3051 assert_template 'edit'
3021 end 3052 end
3022 end 3053 end
3023 3054
3024 attachment = Attachment.first(:order => 'id DESC') 3055 attachment = Attachment.order('id DESC').first
3025 assert_equal 'testfile.txt', attachment.filename 3056 assert_equal 'testfile.txt', attachment.filename
3026 assert File.exists?(attachment.diskfile) 3057 assert File.exists?(attachment.diskfile)
3027 assert_nil attachment.container 3058 assert_nil attachment.container
3028 3059
3029 assert_select 'input[name=?][value=?]', 'attachments[p0][token]', attachment.token 3060 assert_select 'input[name=?][value=?]', 'attachments[p0][token]', attachment.token
3066 end 3097 end
3067 3098
3068 attachment.reload 3099 attachment.reload
3069 assert_equal Issue.find(1), attachment.container 3100 assert_equal Issue.find(1), attachment.container
3070 3101
3071 journal = Journal.first(:order => 'id DESC') 3102 journal = Journal.order('id DESC').first
3072 assert_equal 1, journal.details.size 3103 assert_equal 1, journal.details.size
3073 assert_equal 'testfile.txt', journal.details.first.value 3104 assert_equal 'testfile.txt', journal.details.first.value
3074 end 3105 end
3075 3106
3076 def test_put_update_with_attachment_that_fails_to_save 3107 def test_put_update_with_attachment_that_fails_to_save
3133 :time_entry => {"comments"=>"", "activity_id"=>"", "hours"=>"2z"} 3164 :time_entry => {"comments"=>"", "activity_id"=>"", "hours"=>"2z"}
3134 end 3165 end
3135 assert_response :success 3166 assert_response :success
3136 assert_template 'edit' 3167 assert_template 'edit'
3137 3168
3138 assert_error_tag :descendant => {:content => /Activity can&#x27;t be blank/} 3169 assert_error_tag :descendant => {:content => /Activity #{ESCAPED_CANT} be blank/}
3139 assert_select 'textarea[name=?]', 'issue[notes]', :text => notes 3170 assert_select 'textarea[name=?]', 'issue[notes]', :text => notes
3140 assert_select 'input[name=?][value=?]', 'time_entry[hours]', '2z' 3171 assert_select 'input[name=?][value=?]', 'time_entry[hours]', '2z'
3141 end 3172 end
3142 3173
3143 def test_put_update_with_invalid_spent_time_comments_only 3174 def test_put_update_with_invalid_spent_time_comments_only
3151 :time_entry => {"comments"=>"this is my comment", "activity_id"=>"", "hours"=>""} 3182 :time_entry => {"comments"=>"this is my comment", "activity_id"=>"", "hours"=>""}
3152 end 3183 end
3153 assert_response :success 3184 assert_response :success
3154 assert_template 'edit' 3185 assert_template 'edit'
3155 3186
3156 assert_error_tag :descendant => {:content => /Activity can&#x27;t be blank/} 3187 assert_error_tag :descendant => {:content => /Activity #{ESCAPED_CANT} be blank/}
3157 assert_error_tag :descendant => {:content => /Hours can&#x27;t be blank/} 3188 assert_error_tag :descendant => {:content => /Hours #{ESCAPED_CANT} be blank/}
3158 assert_select 'textarea[name=?]', 'issue[notes]', :text => notes 3189 assert_select 'textarea[name=?]', 'issue[notes]', :text => notes
3159 assert_select 'input[name=?][value=?]', 'time_entry[comments]', 'this is my comment' 3190 assert_select 'input[name=?][value=?]', 'time_entry[comments]', 'this is my comment'
3160 end 3191 end
3161 3192
3162 def test_put_update_should_allow_fixed_version_to_be_set_to_a_subproject 3193 def test_put_update_should_allow_fixed_version_to_be_set_to_a_subproject
3362 :assigned_to_id => '', 3393 :assigned_to_id => '',
3363 :custom_field_values => {'2' => ''}} 3394 :custom_field_values => {'2' => ''}}
3364 3395
3365 assert_response 302 3396 assert_response 302
3366 # check that the issues were updated 3397 # check that the issues were updated
3367 assert_equal [7, 7], Issue.find_all_by_id([1, 2]).collect {|i| i.priority.id} 3398 assert_equal [7, 7], Issue.where(:id =>[1, 2]).collect {|i| i.priority.id}
3368 3399
3369 issue = Issue.find(1) 3400 issue = Issue.find(1)
3370 journal = issue.journals.reorder('created_on DESC').first 3401 journal = issue.journals.reorder('created_on DESC').first
3371 assert_equal '125', issue.custom_value_for(2).value 3402 assert_equal '125', issue.custom_value_for(2).value
3372 assert_equal 'Bulk editing', journal.notes 3403 assert_equal 'Bulk editing', journal.notes
3384 :issue => {:priority_id => '', 3415 :issue => {:priority_id => '',
3385 :assigned_to_id => group.id, 3416 :assigned_to_id => group.id,
3386 :custom_field_values => {'2' => ''}} 3417 :custom_field_values => {'2' => ''}}
3387 3418
3388 assert_response 302 3419 assert_response 302
3389 assert_equal [group, group], Issue.find_all_by_id([1, 2]).collect {|i| i.assigned_to} 3420 assert_equal [group, group], Issue.where(:id => [1, 2]).collect {|i| i.assigned_to}
3390 end 3421 end
3391 3422
3392 def test_bulk_update_on_different_projects 3423 def test_bulk_update_on_different_projects
3393 @request.session[:user_id] = 2 3424 @request.session[:user_id] = 2
3394 # update issues priority 3425 # update issues priority
3677 post :bulk_update, :ids => [1, 2], :issue => {:project_id => '2'}, :copy => '1' 3708 post :bulk_update, :ids => [1, 2], :issue => {:project_id => '2'}, :copy => '1'
3678 end 3709 end
3679 end 3710 end
3680 assert_redirected_to '/projects/ecookbook/issues' 3711 assert_redirected_to '/projects/ecookbook/issues'
3681 3712
3682 copies = Issue.all(:order => 'id DESC', :limit => issues.size) 3713 copies = Issue.order('id DESC').limit(issues.size)
3683 copies.each do |copy| 3714 copies.each do |copy|
3684 assert_equal 2, copy.project_id 3715 assert_equal 2, copy.project_id
3685 end 3716 end
3686 end 3717 end
3687 3718
3701 :project_id => '', :tracker_id => '', :assigned_to_id => '', 3732 :project_id => '', :tracker_id => '', :assigned_to_id => '',
3702 :status_id => '', :start_date => '', :due_date => '' 3733 :status_id => '', :start_date => '', :due_date => ''
3703 } 3734 }
3704 end 3735 end
3705 3736
3706 copies = Issue.all(:order => 'id DESC', :limit => issues.size) 3737 copies = Issue.order('id DESC').limit(issues.size)
3707 issues.each do |orig| 3738 issues.each do |orig|
3708 copy = copies.detect {|c| c.subject == orig.subject} 3739 copy = copies.detect {|c| c.subject == orig.subject}
3709 assert_not_nil copy 3740 assert_not_nil copy
3710 assert_equal orig.project_id, copy.project_id 3741 assert_equal orig.project_id, copy.project_id
3711 assert_equal orig.tracker_id, copy.tracker_id 3742 assert_equal orig.tracker_id, copy.tracker_id
3751 :issue => { 3782 :issue => {
3752 :project_id => '', :tracker_id => '', :assigned_to_id => '4', 3783 :project_id => '', :tracker_id => '', :assigned_to_id => '4',
3753 :status_id => '3', :start_date => '2009-12-01', :due_date => '2009-12-31' 3784 :status_id => '3', :start_date => '2009-12-01', :due_date => '2009-12-31'
3754 } 3785 }
3755 end 3786 end
3756 issue = Issue.first(:order => 'id DESC') 3787 issue = Issue.order('id DESC').first
3757 assert_equal 1, issue.journals.size 3788 assert_equal 1, issue.journals.size
3758 journal = issue.journals.first 3789 journal = issue.journals.first
3759 assert_equal 1, journal.details.size 3790 assert_equal 1, journal.details.size
3760 assert_equal 'Copying one issue', journal.notes 3791 assert_equal 'Copying one issue', journal.notes
3761 end 3792 end
3846 end 3877 end
3847 3878
3848 def test_bulk_copy_to_another_project_should_follow_when_needed 3879 def test_bulk_copy_to_another_project_should_follow_when_needed
3849 @request.session[:user_id] = 2 3880 @request.session[:user_id] = 2
3850 post :bulk_update, :ids => [1], :copy => '1', :issue => {:project_id => 2}, :follow => '1' 3881 post :bulk_update, :ids => [1], :copy => '1', :issue => {:project_id => 2}, :follow => '1'
3851 issue = Issue.first(:order => 'id DESC') 3882 issue = Issue.order('id DESC').first
3852 assert_redirected_to :controller => 'issues', :action => 'show', :id => issue 3883 assert_redirected_to :controller => 'issues', :action => 'show', :id => issue
3853 end 3884 end
3854 3885
3855 def test_bulk_copy_with_all_failures_should_display_errors 3886 def test_bulk_copy_with_all_failures_should_display_errors
3856 @request.session[:user_id] = 2 3887 @request.session[:user_id] = 2