Mercurial > hg > soundsoftware-site
comparison test/functional/.svn/text-base/issues_controller_test.rb.svn-base @ 441:cbce1fd3b1b7 redmine-1.2
Update to Redmine 1.2-stable branch (Redmine SVN rev 6000)
author | Chris Cannam |
---|---|
date | Mon, 06 Jun 2011 14:24:13 +0100 |
parents | 8661b858af72 |
children | 0c939c159af4 |
comparison
equal
deleted
inserted
replaced
245:051f544170fe | 441:cbce1fd3b1b7 |
---|---|
1 # Redmine - project management software | 1 # Redmine - project management software |
2 # Copyright (C) 2006-2008 Jean-Philippe Lang | 2 # Copyright (C) 2006-2011 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. |
8 # | 8 # |
9 # This program is distributed in the hope that it will be useful, | 9 # This program is distributed in the hope that it will be useful, |
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 # GNU General Public License for more details. | 12 # GNU General Public License for more details. |
13 # | 13 # |
14 # You should have received a copy of the GNU General Public License | 14 # You should have received a copy of the GNU General Public License |
15 # along with this program; if not, write to the Free Software | 15 # along with this program; if not, write to the Free Software |
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
17 | 17 |
18 require File.expand_path('../../test_helper', __FILE__) | 18 require File.expand_path('../../test_helper', __FILE__) |
43 :custom_fields_trackers, | 43 :custom_fields_trackers, |
44 :time_entries, | 44 :time_entries, |
45 :journals, | 45 :journals, |
46 :journal_details, | 46 :journal_details, |
47 :queries | 47 :queries |
48 | 48 |
49 def setup | 49 def setup |
50 @controller = IssuesController.new | 50 @controller = IssuesController.new |
51 @request = ActionController::TestRequest.new | 51 @request = ActionController::TestRequest.new |
52 @response = ActionController::TestResponse.new | 52 @response = ActionController::TestResponse.new |
53 User.current = nil | 53 User.current = nil |
54 end | 54 end |
55 | 55 |
56 def test_index | 56 def test_index |
57 Setting.default_language = 'en' | 57 Setting.default_language = 'en' |
58 | 58 |
59 get :index | 59 get :index |
60 assert_response :success | 60 assert_response :success |
61 assert_template 'index.rhtml' | 61 assert_template 'index.rhtml' |
62 assert_not_nil assigns(:issues) | 62 assert_not_nil assigns(:issues) |
63 assert_nil assigns(:project) | 63 assert_nil assigns(:project) |
67 assert_no_tag :tag => 'a', :content => /Issue of a private subproject/ | 67 assert_no_tag :tag => 'a', :content => /Issue of a private subproject/ |
68 assert_no_tag :tag => 'a', :content => /Issue on project 2/ | 68 assert_no_tag :tag => 'a', :content => /Issue on project 2/ |
69 # project column | 69 # project column |
70 assert_tag :tag => 'th', :content => /Project/ | 70 assert_tag :tag => 'th', :content => /Project/ |
71 end | 71 end |
72 | 72 |
73 def test_index_should_not_list_issues_when_module_disabled | 73 def test_index_should_not_list_issues_when_module_disabled |
74 EnabledModule.delete_all("name = 'issue_tracking' AND project_id = 1") | 74 EnabledModule.delete_all("name = 'issue_tracking' AND project_id = 1") |
75 get :index | 75 get :index |
76 assert_response :success | 76 assert_response :success |
77 assert_template 'index.rhtml' | 77 assert_template 'index.rhtml' |
89 assert_not_nil assigns(:issues) | 89 assert_not_nil assigns(:issues) |
90 assert_nil assigns(:project) | 90 assert_nil assigns(:project) |
91 assert_no_tag :tag => 'a', :content => /Can't print recipes/ | 91 assert_no_tag :tag => 'a', :content => /Can't print recipes/ |
92 assert_tag :tag => 'a', :content => /Subproject issue/ | 92 assert_tag :tag => 'a', :content => /Subproject issue/ |
93 end | 93 end |
94 | 94 |
95 def test_index_should_list_visible_issues_only | |
96 get :index, :per_page => 100 | |
97 assert_response :success | |
98 assert_not_nil assigns(:issues) | |
99 assert_nil assigns(:issues).detect {|issue| !issue.visible?} | |
100 end | |
101 | |
95 def test_index_with_project | 102 def test_index_with_project |
96 Setting.display_subprojects_issues = 0 | 103 Setting.display_subprojects_issues = 0 |
97 get :index, :project_id => 1 | 104 get :index, :project_id => 1 |
98 assert_response :success | 105 assert_response :success |
99 assert_template 'index.rhtml' | 106 assert_template 'index.rhtml' |
100 assert_not_nil assigns(:issues) | 107 assert_not_nil assigns(:issues) |
101 assert_tag :tag => 'a', :content => /Can't print recipes/ | 108 assert_tag :tag => 'a', :content => /Can't print recipes/ |
102 assert_no_tag :tag => 'a', :content => /Subproject issue/ | 109 assert_no_tag :tag => 'a', :content => /Subproject issue/ |
103 end | 110 end |
104 | 111 |
105 def test_index_with_project_and_subprojects | 112 def test_index_with_project_and_subprojects |
106 Setting.display_subprojects_issues = 1 | 113 Setting.display_subprojects_issues = 1 |
107 get :index, :project_id => 1 | 114 get :index, :project_id => 1 |
108 assert_response :success | 115 assert_response :success |
109 assert_template 'index.rhtml' | 116 assert_template 'index.rhtml' |
110 assert_not_nil assigns(:issues) | 117 assert_not_nil assigns(:issues) |
111 assert_tag :tag => 'a', :content => /Can't print recipes/ | 118 assert_tag :tag => 'a', :content => /Can't print recipes/ |
112 assert_tag :tag => 'a', :content => /Subproject issue/ | 119 assert_tag :tag => 'a', :content => /Subproject issue/ |
113 assert_no_tag :tag => 'a', :content => /Issue of a private subproject/ | 120 assert_no_tag :tag => 'a', :content => /Issue of a private subproject/ |
114 end | 121 end |
115 | 122 |
116 def test_index_with_project_and_subprojects_should_show_private_subprojects | 123 def test_index_with_project_and_subprojects_should_show_private_subprojects |
117 @request.session[:user_id] = 2 | 124 @request.session[:user_id] = 2 |
118 Setting.display_subprojects_issues = 1 | 125 Setting.display_subprojects_issues = 1 |
119 get :index, :project_id => 1 | 126 get :index, :project_id => 1 |
120 assert_response :success | 127 assert_response :success |
122 assert_not_nil assigns(:issues) | 129 assert_not_nil assigns(:issues) |
123 assert_tag :tag => 'a', :content => /Can't print recipes/ | 130 assert_tag :tag => 'a', :content => /Can't print recipes/ |
124 assert_tag :tag => 'a', :content => /Subproject issue/ | 131 assert_tag :tag => 'a', :content => /Subproject issue/ |
125 assert_tag :tag => 'a', :content => /Issue of a private subproject/ | 132 assert_tag :tag => 'a', :content => /Issue of a private subproject/ |
126 end | 133 end |
127 | 134 |
128 def test_index_with_project_and_default_filter | 135 def test_index_with_project_and_default_filter |
129 get :index, :project_id => 1, :set_filter => 1 | 136 get :index, :project_id => 1, :set_filter => 1 |
130 assert_response :success | 137 assert_response :success |
131 assert_template 'index.rhtml' | 138 assert_template 'index.rhtml' |
132 assert_not_nil assigns(:issues) | 139 assert_not_nil assigns(:issues) |
133 | 140 |
134 query = assigns(:query) | 141 query = assigns(:query) |
135 assert_not_nil query | 142 assert_not_nil query |
136 # default filter | 143 # default filter |
137 assert_equal({'status_id' => {:operator => 'o', :values => ['']}}, query.filters) | 144 assert_equal({'status_id' => {:operator => 'o', :values => ['']}}, query.filters) |
138 end | 145 end |
139 | 146 |
140 def test_index_with_project_and_filter | 147 def test_index_with_project_and_filter |
141 get :index, :project_id => 1, :set_filter => 1, | 148 get :index, :project_id => 1, :set_filter => 1, |
142 :fields => ['tracker_id'], | 149 :f => ['tracker_id'], |
143 :operators => {'tracker_id' => '='}, | 150 :op => {'tracker_id' => '='}, |
144 :values => {'tracker_id' => ['1']} | 151 :v => {'tracker_id' => ['1']} |
145 assert_response :success | 152 assert_response :success |
146 assert_template 'index.rhtml' | 153 assert_template 'index.rhtml' |
147 assert_not_nil assigns(:issues) | 154 assert_not_nil assigns(:issues) |
148 | 155 |
149 query = assigns(:query) | 156 query = assigns(:query) |
150 assert_not_nil query | 157 assert_not_nil query |
151 assert_equal({'tracker_id' => {:operator => '=', :values => ['1']}}, query.filters) | 158 assert_equal({'tracker_id' => {:operator => '=', :values => ['1']}}, query.filters) |
152 end | 159 end |
153 | 160 |
154 def test_index_with_project_and_empty_filters | 161 def test_index_with_project_and_empty_filters |
155 get :index, :project_id => 1, :set_filter => 1, :fields => [''] | 162 get :index, :project_id => 1, :set_filter => 1, :fields => [''] |
156 assert_response :success | 163 assert_response :success |
157 assert_template 'index.rhtml' | 164 assert_template 'index.rhtml' |
158 assert_not_nil assigns(:issues) | 165 assert_not_nil assigns(:issues) |
159 | 166 |
160 query = assigns(:query) | 167 query = assigns(:query) |
161 assert_not_nil query | 168 assert_not_nil query |
162 # no filter | 169 # no filter |
163 assert_equal({}, query.filters) | 170 assert_equal({}, query.filters) |
164 end | 171 end |
165 | 172 |
166 def test_index_with_query | 173 def test_index_with_query |
167 get :index, :project_id => 1, :query_id => 5 | 174 get :index, :project_id => 1, :query_id => 5 |
168 assert_response :success | 175 assert_response :success |
169 assert_template 'index.rhtml' | 176 assert_template 'index.rhtml' |
170 assert_not_nil assigns(:issues) | 177 assert_not_nil assigns(:issues) |
171 assert_nil assigns(:issue_count_by_group) | 178 assert_nil assigns(:issue_count_by_group) |
172 end | 179 end |
173 | 180 |
174 def test_index_with_query_grouped_by_tracker | 181 def test_index_with_query_grouped_by_tracker |
175 get :index, :project_id => 1, :query_id => 6 | 182 get :index, :project_id => 1, :query_id => 6 |
176 assert_response :success | 183 assert_response :success |
177 assert_template 'index.rhtml' | 184 assert_template 'index.rhtml' |
178 assert_not_nil assigns(:issues) | 185 assert_not_nil assigns(:issues) |
179 assert_not_nil assigns(:issue_count_by_group) | 186 assert_not_nil assigns(:issue_count_by_group) |
180 end | 187 end |
181 | 188 |
182 def test_index_with_query_grouped_by_list_custom_field | 189 def test_index_with_query_grouped_by_list_custom_field |
183 get :index, :project_id => 1, :query_id => 9 | 190 get :index, :project_id => 1, :query_id => 9 |
184 assert_response :success | 191 assert_response :success |
185 assert_template 'index.rhtml' | 192 assert_template 'index.rhtml' |
186 assert_not_nil assigns(:issues) | 193 assert_not_nil assigns(:issues) |
187 assert_not_nil assigns(:issue_count_by_group) | 194 assert_not_nil assigns(:issue_count_by_group) |
188 end | 195 end |
189 | 196 |
190 def test_index_sort_by_field_not_included_in_columns | 197 def test_index_sort_by_field_not_included_in_columns |
191 Setting.issue_list_default_columns = %w(subject author) | 198 Setting.issue_list_default_columns = %w(subject author) |
192 get :index, :sort => 'tracker' | 199 get :index, :sort => 'tracker' |
193 end | 200 end |
194 | 201 |
195 def test_index_csv_with_project | 202 def test_index_csv_with_project |
196 Setting.default_language = 'en' | 203 Setting.default_language = 'en' |
197 | 204 |
198 get :index, :format => 'csv' | 205 get :index, :format => 'csv' |
199 assert_response :success | 206 assert_response :success |
200 assert_not_nil assigns(:issues) | 207 assert_not_nil assigns(:issues) |
201 assert_equal 'text/csv', @response.content_type | 208 assert_equal 'text/csv', @response.content_type |
202 assert @response.body.starts_with?("#,") | 209 assert @response.body.starts_with?("#,") |
204 get :index, :project_id => 1, :format => 'csv' | 211 get :index, :project_id => 1, :format => 'csv' |
205 assert_response :success | 212 assert_response :success |
206 assert_not_nil assigns(:issues) | 213 assert_not_nil assigns(:issues) |
207 assert_equal 'text/csv', @response.content_type | 214 assert_equal 'text/csv', @response.content_type |
208 end | 215 end |
209 | 216 |
210 def test_index_pdf | 217 def test_index_pdf |
211 get :index, :format => 'pdf' | 218 get :index, :format => 'pdf' |
212 assert_response :success | 219 assert_response :success |
213 assert_not_nil assigns(:issues) | 220 assert_not_nil assigns(:issues) |
214 assert_equal 'application/pdf', @response.content_type | 221 assert_equal 'application/pdf', @response.content_type |
215 | 222 |
216 get :index, :project_id => 1, :format => 'pdf' | 223 get :index, :project_id => 1, :format => 'pdf' |
217 assert_response :success | 224 assert_response :success |
218 assert_not_nil assigns(:issues) | 225 assert_not_nil assigns(:issues) |
219 assert_equal 'application/pdf', @response.content_type | 226 assert_equal 'application/pdf', @response.content_type |
220 | 227 |
221 get :index, :project_id => 1, :query_id => 6, :format => 'pdf' | 228 get :index, :project_id => 1, :query_id => 6, :format => 'pdf' |
222 assert_response :success | 229 assert_response :success |
223 assert_not_nil assigns(:issues) | 230 assert_not_nil assigns(:issues) |
224 assert_equal 'application/pdf', @response.content_type | 231 assert_equal 'application/pdf', @response.content_type |
225 end | 232 end |
226 | 233 |
227 def test_index_pdf_with_query_grouped_by_list_custom_field | 234 def test_index_pdf_with_query_grouped_by_list_custom_field |
228 get :index, :project_id => 1, :query_id => 9, :format => 'pdf' | 235 get :index, :project_id => 1, :query_id => 9, :format => 'pdf' |
229 assert_response :success | 236 assert_response :success |
230 assert_not_nil assigns(:issues) | 237 assert_not_nil assigns(:issues) |
231 assert_not_nil assigns(:issue_count_by_group) | 238 assert_not_nil assigns(:issue_count_by_group) |
232 assert_equal 'application/pdf', @response.content_type | 239 assert_equal 'application/pdf', @response.content_type |
233 end | 240 end |
234 | 241 |
235 def test_index_sort | 242 def test_index_sort |
236 get :index, :sort => 'tracker,id:desc' | 243 get :index, :sort => 'tracker,id:desc' |
237 assert_response :success | 244 assert_response :success |
238 | 245 |
239 sort_params = @request.session['issues_index_sort'] | 246 sort_params = @request.session['issues_index_sort'] |
240 assert sort_params.is_a?(String) | 247 assert sort_params.is_a?(String) |
241 assert_equal 'tracker,id:desc', sort_params | 248 assert_equal 'tracker,id:desc', sort_params |
242 | 249 |
243 issues = assigns(:issues) | 250 issues = assigns(:issues) |
244 assert_not_nil issues | 251 assert_not_nil issues |
245 assert !issues.empty? | 252 assert !issues.empty? |
246 assert_equal issues.sort {|a,b| a.tracker == b.tracker ? b.id <=> a.id : a.tracker <=> b.tracker }.collect(&:id), issues.collect(&:id) | 253 assert_equal issues.sort {|a,b| a.tracker == b.tracker ? b.id <=> a.id : a.tracker <=> b.tracker }.collect(&:id), issues.collect(&:id) |
247 end | 254 end |
248 | 255 |
249 def test_index_with_columns | 256 def test_index_with_columns |
250 columns = ['tracker', 'subject', 'assigned_to'] | 257 columns = ['tracker', 'subject', 'assigned_to'] |
251 get :index, :set_filter => 1, :query => { 'column_names' => columns} | 258 get :index, :set_filter => 1, :c => columns |
252 assert_response :success | 259 assert_response :success |
253 | 260 |
254 # query should use specified columns | 261 # query should use specified columns |
255 query = assigns(:query) | 262 query = assigns(:query) |
256 assert_kind_of Query, query | 263 assert_kind_of Query, query |
257 assert_equal columns, query.column_names.map(&:to_s) | 264 assert_equal columns, query.column_names.map(&:to_s) |
258 | 265 |
259 # columns should be stored in session | 266 # columns should be stored in session |
260 assert_kind_of Hash, session[:query] | 267 assert_kind_of Hash, session[:query] |
261 assert_kind_of Array, session[:query][:column_names] | 268 assert_kind_of Array, session[:query][:column_names] |
262 assert_equal columns, session[:query][:column_names].map(&:to_s) | 269 assert_equal columns, session[:query][:column_names].map(&:to_s) |
263 end | 270 end |
264 | 271 |
272 def test_index_with_custom_field_column | |
273 columns = %w(tracker subject cf_2) | |
274 get :index, :set_filter => 1, :c => columns | |
275 assert_response :success | |
276 | |
277 # query should use specified columns | |
278 query = assigns(:query) | |
279 assert_kind_of Query, query | |
280 assert_equal columns, query.column_names.map(&:to_s) | |
281 | |
282 assert_tag :td, | |
283 :attributes => {:class => 'cf_2 string'}, | |
284 :ancestor => {:tag => 'table', :attributes => {:class => /issues/}} | |
285 end | |
286 | |
265 def test_show_by_anonymous | 287 def test_show_by_anonymous |
266 get :show, :id => 1 | 288 get :show, :id => 1 |
267 assert_response :success | 289 assert_response :success |
268 assert_template 'show.rhtml' | 290 assert_template 'show.rhtml' |
269 assert_not_nil assigns(:issue) | 291 assert_not_nil assigns(:issue) |
270 assert_equal Issue.find(1), assigns(:issue) | 292 assert_equal Issue.find(1), assigns(:issue) |
271 | 293 |
272 # anonymous role is allowed to add a note | 294 # anonymous role is allowed to add a note |
273 assert_tag :tag => 'form', | 295 assert_tag :tag => 'form', |
274 :descendant => { :tag => 'fieldset', | 296 :descendant => { :tag => 'fieldset', |
275 :child => { :tag => 'legend', | 297 :child => { :tag => 'legend', |
276 :content => /Notes/ } } | 298 :content => /Notes/ } } |
277 end | 299 end |
278 | 300 |
279 def test_show_by_manager | 301 def test_show_by_manager |
280 @request.session[:user_id] = 2 | 302 @request.session[:user_id] = 2 |
281 get :show, :id => 1 | 303 get :show, :id => 1 |
282 assert_response :success | 304 assert_response :success |
283 | 305 |
284 assert_tag :tag => 'a', | 306 assert_tag :tag => 'a', |
285 :content => /Quote/ | 307 :content => /Quote/ |
286 | 308 |
287 assert_tag :tag => 'form', | 309 assert_tag :tag => 'form', |
288 :descendant => { :tag => 'fieldset', | 310 :descendant => { :tag => 'fieldset', |
289 :child => { :tag => 'legend', | 311 :child => { :tag => 'legend', |
290 :content => /Change properties/ } }, | 312 :content => /Change properties/ } }, |
291 :descendant => { :tag => 'fieldset', | 313 :descendant => { :tag => 'fieldset', |
292 :child => { :tag => 'legend', | 314 :child => { :tag => 'legend', |
293 :content => /Log time/ } }, | 315 :content => /Log time/ } }, |
294 :descendant => { :tag => 'fieldset', | 316 :descendant => { :tag => 'fieldset', |
295 :child => { :tag => 'legend', | 317 :child => { :tag => 'legend', |
296 :content => /Notes/ } } | 318 :content => /Notes/ } } |
297 end | 319 end |
298 | 320 |
299 def test_show_should_deny_anonymous_access_without_permission | 321 def test_show_should_deny_anonymous_access_without_permission |
300 Role.anonymous.remove_permission!(:view_issues) | 322 Role.anonymous.remove_permission!(:view_issues) |
301 get :show, :id => 1 | 323 get :show, :id => 1 |
302 assert_response :redirect | 324 assert_response :redirect |
303 end | 325 end |
304 | 326 |
327 def test_show_should_deny_anonymous_access_to_private_issue | |
328 Issue.update_all(["is_private = ?", true], "id = 1") | |
329 get :show, :id => 1 | |
330 assert_response :redirect | |
331 end | |
332 | |
305 def test_show_should_deny_non_member_access_without_permission | 333 def test_show_should_deny_non_member_access_without_permission |
306 Role.non_member.remove_permission!(:view_issues) | 334 Role.non_member.remove_permission!(:view_issues) |
307 @request.session[:user_id] = 9 | 335 @request.session[:user_id] = 9 |
308 get :show, :id => 1 | 336 get :show, :id => 1 |
309 assert_response 403 | 337 assert_response 403 |
310 end | 338 end |
311 | 339 |
340 def test_show_should_deny_non_member_access_to_private_issue | |
341 Issue.update_all(["is_private = ?", true], "id = 1") | |
342 @request.session[:user_id] = 9 | |
343 get :show, :id => 1 | |
344 assert_response 403 | |
345 end | |
346 | |
312 def test_show_should_deny_member_access_without_permission | 347 def test_show_should_deny_member_access_without_permission |
313 Role.find(1).remove_permission!(:view_issues) | 348 Role.find(1).remove_permission!(:view_issues) |
314 @request.session[:user_id] = 2 | 349 @request.session[:user_id] = 2 |
315 get :show, :id => 1 | 350 get :show, :id => 1 |
316 assert_response 403 | 351 assert_response 403 |
317 end | 352 end |
318 | 353 |
354 def test_show_should_deny_member_access_to_private_issue_without_permission | |
355 Issue.update_all(["is_private = ?", true], "id = 1") | |
356 @request.session[:user_id] = 3 | |
357 get :show, :id => 1 | |
358 assert_response 403 | |
359 end | |
360 | |
361 def test_show_should_allow_author_access_to_private_issue | |
362 Issue.update_all(["is_private = ?, author_id = 3", true], "id = 1") | |
363 @request.session[:user_id] = 3 | |
364 get :show, :id => 1 | |
365 assert_response :success | |
366 end | |
367 | |
368 def test_show_should_allow_assignee_access_to_private_issue | |
369 Issue.update_all(["is_private = ?, assigned_to_id = 3", true], "id = 1") | |
370 @request.session[:user_id] = 3 | |
371 get :show, :id => 1 | |
372 assert_response :success | |
373 end | |
374 | |
375 def test_show_should_allow_member_access_to_private_issue_with_permission | |
376 Issue.update_all(["is_private = ?", true], "id = 1") | |
377 User.find(3).roles_for_project(Project.find(1)).first.update_attribute :issues_visibility, 'all' | |
378 @request.session[:user_id] = 3 | |
379 get :show, :id => 1 | |
380 assert_response :success | |
381 end | |
382 | |
319 def test_show_should_not_disclose_relations_to_invisible_issues | 383 def test_show_should_not_disclose_relations_to_invisible_issues |
320 Setting.cross_project_issue_relations = '1' | 384 Setting.cross_project_issue_relations = '1' |
321 IssueRelation.create!(:issue_from => Issue.find(1), :issue_to => Issue.find(2), :relation_type => 'relates') | 385 IssueRelation.create!(:issue_from => Issue.find(1), :issue_to => Issue.find(2), :relation_type => 'relates') |
322 # Relation to a private project issue | 386 # Relation to a private project issue |
323 IssueRelation.create!(:issue_from => Issue.find(1), :issue_to => Issue.find(4), :relation_type => 'relates') | 387 IssueRelation.create!(:issue_from => Issue.find(1), :issue_to => Issue.find(4), :relation_type => 'relates') |
324 | 388 |
325 get :show, :id => 1 | 389 get :show, :id => 1 |
326 assert_response :success | 390 assert_response :success |
327 | 391 |
328 assert_tag :div, :attributes => { :id => 'relations' }, | 392 assert_tag :div, :attributes => { :id => 'relations' }, |
329 :descendant => { :tag => 'a', :content => /#2$/ } | 393 :descendant => { :tag => 'a', :content => /#2$/ } |
330 assert_no_tag :div, :attributes => { :id => 'relations' }, | 394 assert_no_tag :div, :attributes => { :id => 'relations' }, |
331 :descendant => { :tag => 'a', :content => /#4$/ } | 395 :descendant => { :tag => 'a', :content => /#4$/ } |
332 end | 396 end |
333 | 397 |
334 def test_show_atom | 398 def test_show_atom |
335 get :show, :id => 2, :format => 'atom' | 399 get :show, :id => 2, :format => 'atom' |
336 assert_response :success | 400 assert_response :success |
337 assert_template 'journals/index.rxml' | 401 assert_template 'journals/index.rxml' |
338 # Inline image | 402 # Inline image |
339 assert_select 'content', :text => Regexp.new(Regexp.quote('http://test.host/attachments/download/10')) | 403 assert_select 'content', :text => Regexp.new(Regexp.quote('http://test.host/attachments/download/10')) |
340 end | 404 end |
341 | 405 |
342 def test_show_export_to_pdf | 406 def test_show_export_to_pdf |
343 get :show, :id => 3, :format => 'pdf' | 407 get :show, :id => 3, :format => 'pdf' |
344 assert_response :success | 408 assert_response :success |
345 assert_equal 'application/pdf', @response.content_type | 409 assert_equal 'application/pdf', @response.content_type |
346 assert @response.body.starts_with?('%PDF') | 410 assert @response.body.starts_with?('%PDF') |
350 def test_get_new | 414 def test_get_new |
351 @request.session[:user_id] = 2 | 415 @request.session[:user_id] = 2 |
352 get :new, :project_id => 1, :tracker_id => 1 | 416 get :new, :project_id => 1, :tracker_id => 1 |
353 assert_response :success | 417 assert_response :success |
354 assert_template 'new' | 418 assert_template 'new' |
355 | 419 |
356 assert_tag :tag => 'input', :attributes => { :name => 'issue[custom_field_values][2]', | 420 assert_tag :tag => 'input', :attributes => { :name => 'issue[custom_field_values][2]', |
357 :value => 'Default string' } | 421 :value => 'Default string' } |
358 end | 422 end |
359 | 423 |
360 def test_get_new_without_tracker_id | 424 def test_get_new_without_tracker_id |
361 @request.session[:user_id] = 2 | 425 @request.session[:user_id] = 2 |
362 get :new, :project_id => 1 | 426 get :new, :project_id => 1 |
363 assert_response :success | 427 assert_response :success |
364 assert_template 'new' | 428 assert_template 'new' |
365 | 429 |
366 issue = assigns(:issue) | 430 issue = assigns(:issue) |
367 assert_not_nil issue | 431 assert_not_nil issue |
368 assert_equal Project.find(1).trackers.first, issue.tracker | 432 assert_equal Project.find(1).trackers.first, issue.tracker |
369 end | 433 end |
370 | 434 |
371 def test_get_new_with_no_default_status_should_display_an_error | 435 def test_get_new_with_no_default_status_should_display_an_error |
372 @request.session[:user_id] = 2 | 436 @request.session[:user_id] = 2 |
373 IssueStatus.delete_all | 437 IssueStatus.delete_all |
374 | 438 |
375 get :new, :project_id => 1 | 439 get :new, :project_id => 1 |
376 assert_response 500 | 440 assert_response 500 |
377 assert_error_tag :content => /No default issue/ | 441 assert_error_tag :content => /No default issue/ |
378 end | 442 end |
379 | 443 |
380 def test_get_new_with_no_tracker_should_display_an_error | 444 def test_get_new_with_no_tracker_should_display_an_error |
381 @request.session[:user_id] = 2 | 445 @request.session[:user_id] = 2 |
382 Tracker.delete_all | 446 Tracker.delete_all |
383 | 447 |
384 get :new, :project_id => 1 | 448 get :new, :project_id => 1 |
385 assert_response 500 | 449 assert_response 500 |
386 assert_error_tag :content => /No tracker/ | 450 assert_error_tag :content => /No tracker/ |
387 end | 451 end |
388 | 452 |
389 def test_update_new_form | 453 def test_update_new_form |
390 @request.session[:user_id] = 2 | 454 @request.session[:user_id] = 2 |
391 xhr :post, :new, :project_id => 1, | 455 xhr :post, :new, :project_id => 1, |
392 :issue => {:tracker_id => 2, | 456 :issue => {:tracker_id => 2, |
393 :subject => 'This is the test_new issue', | 457 :subject => 'This is the test_new issue', |
394 :description => 'This is the description', | 458 :description => 'This is the description', |
395 :priority_id => 5} | 459 :priority_id => 5} |
396 assert_response :success | 460 assert_response :success |
397 assert_template 'attributes' | 461 assert_template 'attributes' |
398 | 462 |
399 issue = assigns(:issue) | 463 issue = assigns(:issue) |
400 assert_kind_of Issue, issue | 464 assert_kind_of Issue, issue |
401 assert_equal 1, issue.project_id | 465 assert_equal 1, issue.project_id |
402 assert_equal 2, issue.tracker_id | 466 assert_equal 2, issue.tracker_id |
403 assert_equal 'This is the test_new issue', issue.subject | 467 assert_equal 'This is the test_new issue', issue.subject |
404 end | 468 end |
405 | 469 |
406 def test_post_create | 470 def test_post_create |
407 @request.session[:user_id] = 2 | 471 @request.session[:user_id] = 2 |
408 assert_difference 'Issue.count' do | 472 assert_difference 'Issue.count' do |
409 post :create, :project_id => 1, | 473 post :create, :project_id => 1, |
410 :issue => {:tracker_id => 3, | 474 :issue => {:tracker_id => 3, |
411 :status_id => 2, | 475 :status_id => 2, |
412 :subject => 'This is the test_new issue', | 476 :subject => 'This is the test_new issue', |
413 :description => 'This is the description', | 477 :description => 'This is the description', |
414 :priority_id => 5, | 478 :priority_id => 5, |
415 :start_date => '2010-11-07', | 479 :start_date => '2010-11-07', |
416 :estimated_hours => '', | 480 :estimated_hours => '', |
417 :custom_field_values => {'2' => 'Value for field 2'}} | 481 :custom_field_values => {'2' => 'Value for field 2'}} |
418 end | 482 end |
419 assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id | 483 assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id |
420 | 484 |
421 issue = Issue.find_by_subject('This is the test_new issue') | 485 issue = Issue.find_by_subject('This is the test_new issue') |
422 assert_not_nil issue | 486 assert_not_nil issue |
423 assert_equal 2, issue.author_id | 487 assert_equal 2, issue.author_id |
424 assert_equal 3, issue.tracker_id | 488 assert_equal 3, issue.tracker_id |
425 assert_equal 2, issue.status_id | 489 assert_equal 2, issue.status_id |
427 assert_nil issue.estimated_hours | 491 assert_nil issue.estimated_hours |
428 v = issue.custom_values.find(:first, :conditions => {:custom_field_id => 2}) | 492 v = issue.custom_values.find(:first, :conditions => {:custom_field_id => 2}) |
429 assert_not_nil v | 493 assert_not_nil v |
430 assert_equal 'Value for field 2', v.value | 494 assert_equal 'Value for field 2', v.value |
431 end | 495 end |
432 | 496 |
433 def test_post_create_without_start_date | 497 def test_post_create_without_start_date |
434 @request.session[:user_id] = 2 | 498 @request.session[:user_id] = 2 |
435 assert_difference 'Issue.count' do | 499 assert_difference 'Issue.count' do |
436 post :create, :project_id => 1, | 500 post :create, :project_id => 1, |
437 :issue => {:tracker_id => 3, | 501 :issue => {:tracker_id => 3, |
438 :status_id => 2, | 502 :status_id => 2, |
439 :subject => 'This is the test_new issue', | 503 :subject => 'This is the test_new issue', |
440 :description => 'This is the description', | 504 :description => 'This is the description', |
441 :priority_id => 5, | 505 :priority_id => 5, |
442 :start_date => '', | 506 :start_date => '', |
443 :estimated_hours => '', | 507 :estimated_hours => '', |
444 :custom_field_values => {'2' => 'Value for field 2'}} | 508 :custom_field_values => {'2' => 'Value for field 2'}} |
445 end | 509 end |
446 assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id | 510 assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id |
447 | 511 |
448 issue = Issue.find_by_subject('This is the test_new issue') | 512 issue = Issue.find_by_subject('This is the test_new issue') |
449 assert_not_nil issue | 513 assert_not_nil issue |
450 assert_nil issue.start_date | 514 assert_nil issue.start_date |
451 end | 515 end |
452 | 516 |
453 def test_post_create_and_continue | 517 def test_post_create_and_continue |
454 @request.session[:user_id] = 2 | 518 @request.session[:user_id] = 2 |
455 post :create, :project_id => 1, | 519 post :create, :project_id => 1, |
456 :issue => {:tracker_id => 3, | 520 :issue => {:tracker_id => 3, |
457 :subject => 'This is first issue', | 521 :subject => 'This is first issue', |
458 :priority_id => 5}, | 522 :priority_id => 5}, |
459 :continue => '' | 523 :continue => '' |
460 assert_redirected_to :controller => 'issues', :action => 'new', :project_id => 'ecookbook', | 524 assert_redirected_to :controller => 'issues', :action => 'new', :project_id => 'ecookbook', |
461 :issue => {:tracker_id => 3} | 525 :issue => {:tracker_id => 3} |
462 end | 526 end |
463 | 527 |
464 def test_post_create_without_custom_fields_param | 528 def test_post_create_without_custom_fields_param |
465 @request.session[:user_id] = 2 | 529 @request.session[:user_id] = 2 |
466 assert_difference 'Issue.count' do | 530 assert_difference 'Issue.count' do |
467 post :create, :project_id => 1, | 531 post :create, :project_id => 1, |
468 :issue => {:tracker_id => 1, | 532 :issue => {:tracker_id => 1, |
469 :subject => 'This is the test_new issue', | 533 :subject => 'This is the test_new issue', |
470 :description => 'This is the description', | 534 :description => 'This is the description', |
471 :priority_id => 5} | 535 :priority_id => 5} |
472 end | 536 end |
476 def test_post_create_with_required_custom_field_and_without_custom_fields_param | 540 def test_post_create_with_required_custom_field_and_without_custom_fields_param |
477 field = IssueCustomField.find_by_name('Database') | 541 field = IssueCustomField.find_by_name('Database') |
478 field.update_attribute(:is_required, true) | 542 field.update_attribute(:is_required, true) |
479 | 543 |
480 @request.session[:user_id] = 2 | 544 @request.session[:user_id] = 2 |
481 post :create, :project_id => 1, | 545 post :create, :project_id => 1, |
482 :issue => {:tracker_id => 1, | 546 :issue => {:tracker_id => 1, |
483 :subject => 'This is the test_new issue', | 547 :subject => 'This is the test_new issue', |
484 :description => 'This is the description', | 548 :description => 'This is the description', |
485 :priority_id => 5} | 549 :priority_id => 5} |
486 assert_response :success | 550 assert_response :success |
487 assert_template 'new' | 551 assert_template 'new' |
488 issue = assigns(:issue) | 552 issue = assigns(:issue) |
489 assert_not_nil issue | 553 assert_not_nil issue |
490 assert_equal I18n.translate('activerecord.errors.messages.invalid'), issue.errors.on(:custom_values) | 554 assert_equal I18n.translate('activerecord.errors.messages.invalid'), issue.errors.on(:custom_values) |
491 end | 555 end |
492 | 556 |
493 def test_post_create_with_watchers | 557 def test_post_create_with_watchers |
494 @request.session[:user_id] = 2 | 558 @request.session[:user_id] = 2 |
495 ActionMailer::Base.deliveries.clear | 559 ActionMailer::Base.deliveries.clear |
496 | 560 |
497 assert_difference 'Watcher.count', 2 do | 561 assert_difference 'Watcher.count', 2 do |
498 post :create, :project_id => 1, | 562 post :create, :project_id => 1, |
499 :issue => {:tracker_id => 1, | 563 :issue => {:tracker_id => 1, |
500 :subject => 'This is a new issue with watchers', | 564 :subject => 'This is a new issue with watchers', |
501 :description => 'This is the description', | 565 :description => 'This is the description', |
502 :priority_id => 5, | 566 :priority_id => 5, |
503 :watcher_user_ids => ['2', '3']} | 567 :watcher_user_ids => ['2', '3']} |
504 end | 568 end |
505 issue = Issue.find_by_subject('This is a new issue with watchers') | 569 issue = Issue.find_by_subject('This is a new issue with watchers') |
506 assert_not_nil issue | 570 assert_not_nil issue |
507 assert_redirected_to :controller => 'issues', :action => 'show', :id => issue | 571 assert_redirected_to :controller => 'issues', :action => 'show', :id => issue |
508 | 572 |
509 # Watchers added | 573 # Watchers added |
510 assert_equal [2, 3], issue.watcher_user_ids.sort | 574 assert_equal [2, 3], issue.watcher_user_ids.sort |
511 assert issue.watched_by?(User.find(3)) | 575 assert issue.watched_by?(User.find(3)) |
512 # Watchers notified | 576 # Watchers notified |
513 mail = ActionMailer::Base.deliveries.last | 577 mail = ActionMailer::Base.deliveries.last |
514 assert_kind_of TMail::Mail, mail | 578 assert_kind_of TMail::Mail, mail |
515 assert [mail.bcc, mail.cc].flatten.include?(User.find(3).mail) | 579 assert [mail.bcc, mail.cc].flatten.include?(User.find(3).mail) |
516 end | 580 end |
517 | 581 |
518 def test_post_create_subissue | 582 def test_post_create_subissue |
519 @request.session[:user_id] = 2 | 583 @request.session[:user_id] = 2 |
520 | 584 |
521 assert_difference 'Issue.count' do | 585 assert_difference 'Issue.count' do |
522 post :create, :project_id => 1, | 586 post :create, :project_id => 1, |
523 :issue => {:tracker_id => 1, | 587 :issue => {:tracker_id => 1, |
524 :subject => 'This is a child issue', | 588 :subject => 'This is a child issue', |
525 :parent_issue_id => 2} | 589 :parent_issue_id => 2} |
526 end | 590 end |
527 issue = Issue.find_by_subject('This is a child issue') | 591 issue = Issue.find_by_subject('This is a child issue') |
529 assert_equal Issue.find(2), issue.parent | 593 assert_equal Issue.find(2), issue.parent |
530 end | 594 end |
531 | 595 |
532 def test_post_create_subissue_with_non_numeric_parent_id | 596 def test_post_create_subissue_with_non_numeric_parent_id |
533 @request.session[:user_id] = 2 | 597 @request.session[:user_id] = 2 |
534 | 598 |
535 assert_difference 'Issue.count' do | 599 assert_difference 'Issue.count' do |
536 post :create, :project_id => 1, | 600 post :create, :project_id => 1, |
537 :issue => {:tracker_id => 1, | 601 :issue => {:tracker_id => 1, |
538 :subject => 'This is a child issue', | 602 :subject => 'This is a child issue', |
539 :parent_issue_id => 'ABC'} | 603 :parent_issue_id => 'ABC'} |
540 end | 604 end |
541 issue = Issue.find_by_subject('This is a child issue') | 605 issue = Issue.find_by_subject('This is a child issue') |
542 assert_not_nil issue | 606 assert_not_nil issue |
543 assert_nil issue.parent | 607 assert_nil issue.parent |
544 end | 608 end |
545 | 609 |
546 def test_post_create_should_send_a_notification | 610 def test_post_create_should_send_a_notification |
547 ActionMailer::Base.deliveries.clear | 611 ActionMailer::Base.deliveries.clear |
548 @request.session[:user_id] = 2 | 612 @request.session[:user_id] = 2 |
549 assert_difference 'Issue.count' do | 613 assert_difference 'Issue.count' do |
550 post :create, :project_id => 1, | 614 post :create, :project_id => 1, |
551 :issue => {:tracker_id => 3, | 615 :issue => {:tracker_id => 3, |
552 :subject => 'This is the test_new issue', | 616 :subject => 'This is the test_new issue', |
553 :description => 'This is the description', | 617 :description => 'This is the description', |
554 :priority_id => 5, | 618 :priority_id => 5, |
555 :estimated_hours => '', | 619 :estimated_hours => '', |
556 :custom_field_values => {'2' => 'Value for field 2'}} | 620 :custom_field_values => {'2' => 'Value for field 2'}} |
557 end | 621 end |
558 assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id | 622 assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id |
559 | 623 |
560 assert_equal 1, ActionMailer::Base.deliveries.size | 624 assert_equal 1, ActionMailer::Base.deliveries.size |
561 end | 625 end |
562 | 626 |
563 def test_post_create_should_preserve_fields_values_on_validation_failure | 627 def test_post_create_should_preserve_fields_values_on_validation_failure |
564 @request.session[:user_id] = 2 | 628 @request.session[:user_id] = 2 |
565 post :create, :project_id => 1, | 629 post :create, :project_id => 1, |
566 :issue => {:tracker_id => 1, | 630 :issue => {:tracker_id => 1, |
567 # empty subject | 631 # empty subject |
568 :subject => '', | 632 :subject => '', |
569 :description => 'This is a description', | 633 :description => 'This is a description', |
570 :priority_id => 6, | 634 :priority_id => 6, |
571 :custom_field_values => {'1' => 'Oracle', '2' => 'Value for field 2'}} | 635 :custom_field_values => {'1' => 'Oracle', '2' => 'Value for field 2'}} |
572 assert_response :success | 636 assert_response :success |
573 assert_template 'new' | 637 assert_template 'new' |
574 | 638 |
575 assert_tag :textarea, :attributes => { :name => 'issue[description]' }, | 639 assert_tag :textarea, :attributes => { :name => 'issue[description]' }, |
576 :content => 'This is a description' | 640 :content => 'This is a description' |
577 assert_tag :select, :attributes => { :name => 'issue[priority_id]' }, | 641 assert_tag :select, :attributes => { :name => 'issue[priority_id]' }, |
578 :child => { :tag => 'option', :attributes => { :selected => 'selected', | 642 :child => { :tag => 'option', :attributes => { :selected => 'selected', |
579 :value => '6' }, | 643 :value => '6' }, |
580 :content => 'High' } | 644 :content => 'High' } |
581 # Custom fields | 645 # Custom fields |
582 assert_tag :select, :attributes => { :name => 'issue[custom_field_values][1]' }, | 646 assert_tag :select, :attributes => { :name => 'issue[custom_field_values][1]' }, |
583 :child => { :tag => 'option', :attributes => { :selected => 'selected', | 647 :child => { :tag => 'option', :attributes => { :selected => 'selected', |
584 :value => 'Oracle' }, | 648 :value => 'Oracle' }, |
585 :content => 'Oracle' } | 649 :content => 'Oracle' } |
586 assert_tag :input, :attributes => { :name => 'issue[custom_field_values][2]', | 650 assert_tag :input, :attributes => { :name => 'issue[custom_field_values][2]', |
587 :value => 'Value for field 2'} | 651 :value => 'Value for field 2'} |
588 end | 652 end |
589 | 653 |
590 def test_post_create_should_ignore_non_safe_attributes | 654 def test_post_create_should_ignore_non_safe_attributes |
591 @request.session[:user_id] = 2 | 655 @request.session[:user_id] = 2 |
592 assert_nothing_raised do | 656 assert_nothing_raised do |
593 post :create, :project_id => 1, :issue => { :tracker => "A param can not be a Tracker" } | 657 post :create, :project_id => 1, :issue => { :tracker => "A param can not be a Tracker" } |
594 end | 658 end |
595 end | 659 end |
596 | 660 |
597 context "without workflow privilege" do | 661 context "without workflow privilege" do |
598 setup do | 662 setup do |
599 Workflow.delete_all(["role_id = ?", Role.anonymous.id]) | 663 Workflow.delete_all(["role_id = ?", Role.anonymous.id]) |
600 Role.anonymous.add_permission! :add_issues, :add_issue_notes | 664 Role.anonymous.add_permission! :add_issues, :add_issue_notes |
601 end | 665 end |
602 | 666 |
603 context "#new" do | 667 context "#new" do |
604 should "propose default status only" do | 668 should "propose default status only" do |
605 get :new, :project_id => 1 | 669 get :new, :project_id => 1 |
606 assert_response :success | 670 assert_response :success |
607 assert_template 'new' | 671 assert_template 'new' |
608 assert_tag :tag => 'select', | 672 assert_tag :tag => 'select', |
609 :attributes => {:name => 'issue[status_id]'}, | 673 :attributes => {:name => 'issue[status_id]'}, |
610 :children => {:count => 1}, | 674 :children => {:count => 1}, |
611 :child => {:tag => 'option', :attributes => {:value => IssueStatus.default.id.to_s}} | 675 :child => {:tag => 'option', :attributes => {:value => IssueStatus.default.id.to_s}} |
612 end | 676 end |
613 | 677 |
614 should "accept default status" do | 678 should "accept default status" do |
615 assert_difference 'Issue.count' do | 679 assert_difference 'Issue.count' do |
616 post :create, :project_id => 1, | 680 post :create, :project_id => 1, |
617 :issue => {:tracker_id => 1, | 681 :issue => {:tracker_id => 1, |
618 :subject => 'This is an issue', | 682 :subject => 'This is an issue', |
619 :status_id => 1} | 683 :status_id => 1} |
620 end | 684 end |
621 issue = Issue.last(:order => 'id') | 685 issue = Issue.last(:order => 'id') |
622 assert_equal IssueStatus.default, issue.status | 686 assert_equal IssueStatus.default, issue.status |
623 end | 687 end |
624 | 688 |
625 should "accept default status" do | |
626 assert_difference 'Issue.count' do | |
627 post :create, :project_id => 1, | |
628 :issue => {:tracker_id => 1, | |
629 :subject => 'This is an issue', | |
630 :status_id => 1} | |
631 end | |
632 issue = Issue.last(:order => 'id') | |
633 assert_equal IssueStatus.default, issue.status | |
634 end | |
635 | |
636 should "ignore unauthorized status" do | 689 should "ignore unauthorized status" do |
637 assert_difference 'Issue.count' do | 690 assert_difference 'Issue.count' do |
638 post :create, :project_id => 1, | 691 post :create, :project_id => 1, |
639 :issue => {:tracker_id => 1, | 692 :issue => {:tracker_id => 1, |
640 :subject => 'This is an issue', | 693 :subject => 'This is an issue', |
641 :status_id => 3} | 694 :status_id => 3} |
642 end | 695 end |
643 issue = Issue.last(:order => 'id') | 696 issue = Issue.last(:order => 'id') |
644 assert_equal IssueStatus.default, issue.status | 697 assert_equal IssueStatus.default, issue.status |
645 end | 698 end |
646 end | 699 end |
647 | 700 |
648 context "#update" do | 701 context "#update" do |
649 should "ignore status change" do | 702 should "ignore status change" do |
650 assert_difference 'Journal.count' do | 703 assert_difference 'Journal.count' do |
651 put :update, :id => 1, :notes => 'just trying', :issue => {:status_id => 3} | 704 put :update, :id => 1, :notes => 'just trying', :issue => {:status_id => 3} |
652 end | 705 end |
653 assert_equal 1, Issue.find(1).status_id | 706 assert_equal 1, Issue.find(1).status_id |
654 end | 707 end |
655 | 708 |
656 should "ignore attributes changes" do | 709 should "ignore attributes changes" do |
657 assert_difference 'Journal.count' do | 710 assert_difference 'Journal.count' do |
658 put :update, :id => 1, :notes => 'just trying', :issue => {:subject => 'changed', :assigned_to_id => 2} | 711 put :update, :id => 1, :notes => 'just trying', :issue => {:subject => 'changed', :assigned_to_id => 2} |
659 end | 712 end |
660 issue = Issue.find(1) | 713 issue = Issue.find(1) |
661 assert_equal "Can't print recipes", issue.subject | 714 assert_equal "Can't print recipes", issue.subject |
662 assert_nil issue.assigned_to | 715 assert_nil issue.assigned_to |
663 end | 716 end |
664 end | 717 end |
665 end | 718 end |
666 | 719 |
667 context "with workflow privilege" do | 720 context "with workflow privilege" do |
668 setup do | 721 setup do |
669 Workflow.delete_all(["role_id = ?", Role.anonymous.id]) | 722 Workflow.delete_all(["role_id = ?", Role.anonymous.id]) |
670 Workflow.create!(:role => Role.anonymous, :tracker_id => 1, :old_status_id => 1, :new_status_id => 3) | 723 Workflow.create!(:role => Role.anonymous, :tracker_id => 1, :old_status_id => 1, :new_status_id => 3) |
671 Workflow.create!(:role => Role.anonymous, :tracker_id => 1, :old_status_id => 1, :new_status_id => 4) | 724 Workflow.create!(:role => Role.anonymous, :tracker_id => 1, :old_status_id => 1, :new_status_id => 4) |
672 Role.anonymous.add_permission! :add_issues, :add_issue_notes | 725 Role.anonymous.add_permission! :add_issues, :add_issue_notes |
673 end | 726 end |
674 | 727 |
675 context "#update" do | 728 context "#update" do |
676 should "accept authorized status" do | 729 should "accept authorized status" do |
677 assert_difference 'Journal.count' do | 730 assert_difference 'Journal.count' do |
678 put :update, :id => 1, :notes => 'just trying', :issue => {:status_id => 3} | 731 put :update, :id => 1, :notes => 'just trying', :issue => {:status_id => 3} |
679 end | 732 end |
680 assert_equal 3, Issue.find(1).status_id | 733 assert_equal 3, Issue.find(1).status_id |
681 end | 734 end |
682 | 735 |
683 should "ignore unauthorized status" do | 736 should "ignore unauthorized status" do |
684 assert_difference 'Journal.count' do | 737 assert_difference 'Journal.count' do |
685 put :update, :id => 1, :notes => 'just trying', :issue => {:status_id => 2} | 738 put :update, :id => 1, :notes => 'just trying', :issue => {:status_id => 2} |
686 end | 739 end |
687 assert_equal 1, Issue.find(1).status_id | 740 assert_equal 1, Issue.find(1).status_id |
688 end | 741 end |
689 | 742 |
690 should "accept authorized attributes changes" do | 743 should "accept authorized attributes changes" do |
691 assert_difference 'Journal.count' do | 744 assert_difference 'Journal.count' do |
692 put :update, :id => 1, :notes => 'just trying', :issue => {:assigned_to_id => 2} | 745 put :update, :id => 1, :notes => 'just trying', :issue => {:assigned_to_id => 2} |
693 end | 746 end |
694 issue = Issue.find(1) | 747 issue = Issue.find(1) |
695 assert_equal 2, issue.assigned_to_id | 748 assert_equal 2, issue.assigned_to_id |
696 end | 749 end |
697 | 750 |
698 should "ignore unauthorized attributes changes" do | 751 should "ignore unauthorized attributes changes" do |
699 assert_difference 'Journal.count' do | 752 assert_difference 'Journal.count' do |
700 put :update, :id => 1, :notes => 'just trying', :issue => {:subject => 'changed'} | 753 put :update, :id => 1, :notes => 'just trying', :issue => {:subject => 'changed'} |
701 end | 754 end |
702 issue = Issue.find(1) | 755 issue = Issue.find(1) |
703 assert_equal "Can't print recipes", issue.subject | 756 assert_equal "Can't print recipes", issue.subject |
704 end | 757 end |
705 end | 758 end |
706 | 759 |
707 context "and :edit_issues permission" do | 760 context "and :edit_issues permission" do |
708 setup do | 761 setup do |
709 Role.anonymous.add_permission! :add_issues, :edit_issues | 762 Role.anonymous.add_permission! :add_issues, :edit_issues |
710 end | 763 end |
711 | 764 |
713 assert_difference 'Journal.count' do | 766 assert_difference 'Journal.count' do |
714 put :update, :id => 1, :notes => 'just trying', :issue => {:status_id => 3} | 767 put :update, :id => 1, :notes => 'just trying', :issue => {:status_id => 3} |
715 end | 768 end |
716 assert_equal 3, Issue.find(1).status_id | 769 assert_equal 3, Issue.find(1).status_id |
717 end | 770 end |
718 | 771 |
719 should "ignore unauthorized status" do | 772 should "ignore unauthorized status" do |
720 assert_difference 'Journal.count' do | 773 assert_difference 'Journal.count' do |
721 put :update, :id => 1, :notes => 'just trying', :issue => {:status_id => 2} | 774 put :update, :id => 1, :notes => 'just trying', :issue => {:status_id => 2} |
722 end | 775 end |
723 assert_equal 1, Issue.find(1).status_id | 776 assert_equal 1, Issue.find(1).status_id |
724 end | 777 end |
725 | 778 |
726 should "accept authorized attributes changes" do | 779 should "accept authorized attributes changes" do |
727 assert_difference 'Journal.count' do | 780 assert_difference 'Journal.count' do |
728 put :update, :id => 1, :notes => 'just trying', :issue => {:subject => 'changed', :assigned_to_id => 2} | 781 put :update, :id => 1, :notes => 'just trying', :issue => {:subject => 'changed', :assigned_to_id => 2} |
729 end | 782 end |
730 issue = Issue.find(1) | 783 issue = Issue.find(1) |
731 assert_equal "changed", issue.subject | 784 assert_equal "changed", issue.subject |
732 assert_equal 2, issue.assigned_to_id | 785 assert_equal 2, issue.assigned_to_id |
733 end | 786 end |
734 end | 787 end |
735 end | 788 end |
736 | 789 |
737 def test_copy_issue | 790 def test_copy_issue |
738 @request.session[:user_id] = 2 | 791 @request.session[:user_id] = 2 |
739 get :new, :project_id => 1, :copy_from => 1 | 792 get :new, :project_id => 1, :copy_from => 1 |
740 assert_template 'new' | 793 assert_template 'new' |
741 assert_not_nil assigns(:issue) | 794 assert_not_nil assigns(:issue) |
742 orig = Issue.find(1) | 795 orig = Issue.find(1) |
743 assert_equal orig.subject, assigns(:issue).subject | 796 assert_equal orig.subject, assigns(:issue).subject |
744 end | 797 end |
745 | 798 |
746 def test_get_edit | 799 def test_get_edit |
747 @request.session[:user_id] = 2 | 800 @request.session[:user_id] = 2 |
748 get :edit, :id => 1 | 801 get :edit, :id => 1 |
749 assert_response :success | 802 assert_response :success |
750 assert_template 'edit' | 803 assert_template 'edit' |
751 assert_not_nil assigns(:issue) | 804 assert_not_nil assigns(:issue) |
752 assert_equal Issue.find(1), assigns(:issue) | 805 assert_equal Issue.find(1), assigns(:issue) |
753 end | 806 end |
754 | 807 |
755 def test_get_edit_with_params | 808 def test_get_edit_with_params |
756 @request.session[:user_id] = 2 | 809 @request.session[:user_id] = 2 |
757 get :edit, :id => 1, :issue => { :status_id => 5, :priority_id => 7 }, | 810 get :edit, :id => 1, :issue => { :status_id => 5, :priority_id => 7 }, |
758 :time_entry => { :hours => '2.5', :comments => 'test_get_edit_with_params', :activity_id => TimeEntryActivity.first.id } | 811 :time_entry => { :hours => '2.5', :comments => 'test_get_edit_with_params', :activity_id => TimeEntryActivity.first.id } |
759 assert_response :success | 812 assert_response :success |
760 assert_template 'edit' | 813 assert_template 'edit' |
761 | 814 |
762 issue = assigns(:issue) | 815 issue = assigns(:issue) |
763 assert_not_nil issue | 816 assert_not_nil issue |
764 | 817 |
765 assert_equal 5, issue.status_id | 818 assert_equal 5, issue.status_id |
766 assert_tag :select, :attributes => { :name => 'issue[status_id]' }, | 819 assert_tag :select, :attributes => { :name => 'issue[status_id]' }, |
767 :child => { :tag => 'option', | 820 :child => { :tag => 'option', |
768 :content => 'Closed', | 821 :content => 'Closed', |
769 :attributes => { :selected => 'selected' } } | 822 :attributes => { :selected => 'selected' } } |
770 | 823 |
771 assert_equal 7, issue.priority_id | 824 assert_equal 7, issue.priority_id |
772 assert_tag :select, :attributes => { :name => 'issue[priority_id]' }, | 825 assert_tag :select, :attributes => { :name => 'issue[priority_id]' }, |
773 :child => { :tag => 'option', | 826 :child => { :tag => 'option', |
774 :content => 'Urgent', | 827 :content => 'Urgent', |
775 :attributes => { :selected => 'selected' } } | 828 :attributes => { :selected => 'selected' } } |
776 | 829 |
777 assert_tag :input, :attributes => { :name => 'time_entry[hours]', :value => '2.5' } | 830 assert_tag :input, :attributes => { :name => 'time_entry[hours]', :value => '2.5' } |
778 assert_tag :select, :attributes => { :name => 'time_entry[activity_id]' }, | 831 assert_tag :select, :attributes => { :name => 'time_entry[activity_id]' }, |
783 | 836 |
784 def test_update_edit_form | 837 def test_update_edit_form |
785 @request.session[:user_id] = 2 | 838 @request.session[:user_id] = 2 |
786 xhr :post, :new, :project_id => 1, | 839 xhr :post, :new, :project_id => 1, |
787 :id => 1, | 840 :id => 1, |
788 :issue => {:tracker_id => 2, | 841 :issue => {:tracker_id => 2, |
789 :subject => 'This is the test_new issue', | 842 :subject => 'This is the test_new issue', |
790 :description => 'This is the description', | 843 :description => 'This is the description', |
791 :priority_id => 5} | 844 :priority_id => 5} |
792 assert_response :success | 845 assert_response :success |
793 assert_template 'attributes' | 846 assert_template 'attributes' |
794 | 847 |
795 issue = assigns(:issue) | 848 issue = assigns(:issue) |
796 assert_kind_of Issue, issue | 849 assert_kind_of Issue, issue |
797 assert_equal 1, issue.id | 850 assert_equal 1, issue.id |
798 assert_equal 1, issue.project_id | 851 assert_equal 1, issue.project_id |
799 assert_equal 2, issue.tracker_id | 852 assert_equal 2, issue.tracker_id |
800 assert_equal 'This is the test_new issue', issue.subject | 853 assert_equal 'This is the test_new issue', issue.subject |
801 end | 854 end |
802 | 855 |
803 def test_update_using_invalid_http_verbs | 856 def test_update_using_invalid_http_verbs |
804 @request.session[:user_id] = 2 | 857 @request.session[:user_id] = 2 |
805 subject = 'Updated by an invalid http verb' | 858 subject = 'Updated by an invalid http verb' |
806 | 859 |
807 get :update, :id => 1, :issue => {:subject => subject} | 860 get :update, :id => 1, :issue => {:subject => subject} |
815 end | 868 end |
816 | 869 |
817 def test_put_update_without_custom_fields_param | 870 def test_put_update_without_custom_fields_param |
818 @request.session[:user_id] = 2 | 871 @request.session[:user_id] = 2 |
819 ActionMailer::Base.deliveries.clear | 872 ActionMailer::Base.deliveries.clear |
820 | 873 |
821 issue = Issue.find(1) | 874 issue = Issue.find(1) |
822 assert_equal '125', issue.custom_value_for(2).value | 875 assert_equal '125', issue.custom_value_for(2).value |
823 old_subject = issue.subject | 876 old_subject = issue.subject |
824 new_subject = 'Subject modified by IssuesControllerTest#test_post_edit' | 877 new_subject = 'Subject modified by IssuesControllerTest#test_post_edit' |
825 | 878 |
826 assert_difference('Journal.count') do | 879 assert_difference('Journal.count') do |
827 assert_difference('JournalDetail.count', 2) do | 880 assert_difference('JournalDetail.count', 2) do |
828 put :update, :id => 1, :issue => {:subject => new_subject, | 881 put :update, :id => 1, :issue => {:subject => new_subject, |
829 :priority_id => '6', | 882 :priority_id => '6', |
830 :category_id => '1' # no change | 883 :category_id => '1' # no change |
834 assert_redirected_to :action => 'show', :id => '1' | 887 assert_redirected_to :action => 'show', :id => '1' |
835 issue.reload | 888 issue.reload |
836 assert_equal new_subject, issue.subject | 889 assert_equal new_subject, issue.subject |
837 # Make sure custom fields were not cleared | 890 # Make sure custom fields were not cleared |
838 assert_equal '125', issue.custom_value_for(2).value | 891 assert_equal '125', issue.custom_value_for(2).value |
839 | 892 |
840 mail = ActionMailer::Base.deliveries.last | 893 mail = ActionMailer::Base.deliveries.last |
841 assert_kind_of TMail::Mail, mail | 894 assert_kind_of TMail::Mail, mail |
842 assert mail.subject.starts_with?("[#{issue.project.name} - #{issue.tracker.name} ##{issue.id}]") | 895 assert mail.subject.starts_with?("[#{issue.project.name} - #{issue.tracker.name} ##{issue.id}]") |
843 assert mail.body.include?("Subject changed from #{old_subject} to #{new_subject}") | 896 assert mail.body.include?("Subject changed from #{old_subject} to #{new_subject}") |
844 end | 897 end |
845 | 898 |
846 def test_put_update_with_custom_field_change | 899 def test_put_update_with_custom_field_change |
847 @request.session[:user_id] = 2 | 900 @request.session[:user_id] = 2 |
848 issue = Issue.find(1) | 901 issue = Issue.find(1) |
849 assert_equal '125', issue.custom_value_for(2).value | 902 assert_equal '125', issue.custom_value_for(2).value |
850 | 903 |
851 assert_difference('Journal.count') do | 904 assert_difference('Journal.count') do |
852 assert_difference('JournalDetail.count', 3) do | 905 assert_difference('JournalDetail.count', 3) do |
853 put :update, :id => 1, :issue => {:subject => 'Custom field change', | 906 put :update, :id => 1, :issue => {:subject => 'Custom field change', |
854 :priority_id => '6', | 907 :priority_id => '6', |
855 :category_id => '1', # no change | 908 :category_id => '1', # no change |
858 end | 911 end |
859 end | 912 end |
860 assert_redirected_to :action => 'show', :id => '1' | 913 assert_redirected_to :action => 'show', :id => '1' |
861 issue.reload | 914 issue.reload |
862 assert_equal 'New custom value', issue.custom_value_for(2).value | 915 assert_equal 'New custom value', issue.custom_value_for(2).value |
863 | 916 |
864 mail = ActionMailer::Base.deliveries.last | 917 mail = ActionMailer::Base.deliveries.last |
865 assert_kind_of TMail::Mail, mail | 918 assert_kind_of TMail::Mail, mail |
866 assert mail.body.include?("Searchable field changed from 125 to New custom value") | 919 assert mail.body.include?("Searchable field changed from 125 to New custom value") |
867 end | 920 end |
868 | 921 |
869 def test_put_update_with_status_and_assignee_change | 922 def test_put_update_with_status_and_assignee_change |
870 issue = Issue.find(1) | 923 issue = Issue.find(1) |
871 assert_equal 1, issue.status_id | 924 assert_equal 1, issue.status_id |
872 @request.session[:user_id] = 2 | 925 @request.session[:user_id] = 2 |
873 assert_difference('TimeEntry.count', 0) do | 926 assert_difference('TimeEntry.count', 0) do |
881 issue.reload | 934 issue.reload |
882 assert_equal 2, issue.status_id | 935 assert_equal 2, issue.status_id |
883 j = Journal.find(:first, :order => 'id DESC') | 936 j = Journal.find(:first, :order => 'id DESC') |
884 assert_equal 'Assigned to dlopper', j.notes | 937 assert_equal 'Assigned to dlopper', j.notes |
885 assert_equal 2, j.details.size | 938 assert_equal 2, j.details.size |
886 | 939 |
887 mail = ActionMailer::Base.deliveries.last | 940 mail = ActionMailer::Base.deliveries.last |
888 assert mail.body.include?("Status changed from New to Assigned") | 941 assert mail.body.include?("Status changed from New to Assigned") |
889 # subject should contain the new status | 942 # subject should contain the new status |
890 assert mail.subject.include?("(#{ IssueStatus.find(2).name })") | 943 assert mail.subject.include?("(#{ IssueStatus.find(2).name })") |
891 end | 944 end |
892 | 945 |
893 def test_put_update_with_note_only | 946 def test_put_update_with_note_only |
894 notes = 'Note added by IssuesControllerTest#test_update_with_note_only' | 947 notes = 'Note added by IssuesControllerTest#test_update_with_note_only' |
895 # anonymous user | 948 # anonymous user |
896 put :update, | 949 put :update, |
897 :id => 1, | 950 :id => 1, |
899 assert_redirected_to :action => 'show', :id => '1' | 952 assert_redirected_to :action => 'show', :id => '1' |
900 j = Journal.find(:first, :order => 'id DESC') | 953 j = Journal.find(:first, :order => 'id DESC') |
901 assert_equal notes, j.notes | 954 assert_equal notes, j.notes |
902 assert_equal 0, j.details.size | 955 assert_equal 0, j.details.size |
903 assert_equal User.anonymous, j.user | 956 assert_equal User.anonymous, j.user |
904 | 957 |
905 mail = ActionMailer::Base.deliveries.last | 958 mail = ActionMailer::Base.deliveries.last |
906 assert mail.body.include?(notes) | 959 assert mail.body.include?(notes) |
907 end | 960 end |
908 | 961 |
909 def test_put_update_with_note_and_spent_time | 962 def test_put_update_with_note_and_spent_time |
910 @request.session[:user_id] = 2 | 963 @request.session[:user_id] = 2 |
911 spent_hours_before = Issue.find(1).spent_hours | 964 spent_hours_before = Issue.find(1).spent_hours |
912 assert_difference('TimeEntry.count') do | 965 assert_difference('TimeEntry.count') do |
913 put :update, | 966 put :update, |
914 :id => 1, | 967 :id => 1, |
915 :notes => '2.5 hours added', | 968 :notes => '2.5 hours added', |
916 :time_entry => { :hours => '2.5', :comments => 'test_put_update_with_note_and_spent_time', :activity_id => TimeEntryActivity.first.id } | 969 :time_entry => { :hours => '2.5', :comments => 'test_put_update_with_note_and_spent_time', :activity_id => TimeEntryActivity.first.id } |
917 end | 970 end |
918 assert_redirected_to :action => 'show', :id => '1' | 971 assert_redirected_to :action => 'show', :id => '1' |
919 | 972 |
920 issue = Issue.find(1) | 973 issue = Issue.find(1) |
921 | 974 |
922 j = Journal.find(:first, :order => 'id DESC') | 975 j = Journal.find(:first, :order => 'id DESC') |
923 assert_equal '2.5 hours added', j.notes | 976 assert_equal '2.5 hours added', j.notes |
924 assert_equal 0, j.details.size | 977 assert_equal 0, j.details.size |
925 | 978 |
926 t = issue.time_entries.find_by_comments('test_put_update_with_note_and_spent_time') | 979 t = issue.time_entries.find_by_comments('test_put_update_with_note_and_spent_time') |
927 assert_not_nil t | 980 assert_not_nil t |
928 assert_equal 2.5, t.hours | 981 assert_equal 2.5, t.hours |
929 assert_equal spent_hours_before + 2.5, issue.spent_hours | 982 assert_equal spent_hours_before + 2.5, issue.spent_hours |
930 end | 983 end |
931 | 984 |
932 def test_put_update_with_attachment_only | 985 def test_put_update_with_attachment_only |
933 set_tmp_attachments_directory | 986 set_tmp_attachments_directory |
934 | 987 |
935 # Delete all fixtured journals, a race condition can occur causing the wrong | 988 # Delete all fixtured journals, a race condition can occur causing the wrong |
936 # journal to get fetched in the next find. | 989 # journal to get fetched in the next find. |
937 Journal.delete_all | 990 Journal.delete_all |
938 | 991 |
939 # anonymous user | 992 # anonymous user |
945 j = Issue.find(1).journals.find(:first, :order => 'id DESC') | 998 j = Issue.find(1).journals.find(:first, :order => 'id DESC') |
946 assert j.notes.blank? | 999 assert j.notes.blank? |
947 assert_equal 1, j.details.size | 1000 assert_equal 1, j.details.size |
948 assert_equal 'testfile.txt', j.details.first.value | 1001 assert_equal 'testfile.txt', j.details.first.value |
949 assert_equal User.anonymous, j.user | 1002 assert_equal User.anonymous, j.user |
950 | 1003 |
951 mail = ActionMailer::Base.deliveries.last | 1004 mail = ActionMailer::Base.deliveries.last |
952 assert mail.body.include?('testfile.txt') | 1005 assert mail.body.include?('testfile.txt') |
953 end | 1006 end |
954 | 1007 |
955 def test_put_update_with_attachment_that_fails_to_save | 1008 def test_put_update_with_attachment_that_fails_to_save |
956 set_tmp_attachments_directory | 1009 set_tmp_attachments_directory |
957 | 1010 |
958 # Delete all fixtured journals, a race condition can occur causing the wrong | 1011 # Delete all fixtured journals, a race condition can occur causing the wrong |
959 # journal to get fetched in the next find. | 1012 # journal to get fetched in the next find. |
960 Journal.delete_all | 1013 Journal.delete_all |
961 | 1014 |
962 # Mock out the unsaved attachment | 1015 # Mock out the unsaved attachment |
963 Attachment.any_instance.stubs(:create).returns(Attachment.new) | 1016 Attachment.any_instance.stubs(:create).returns(Attachment.new) |
964 | 1017 |
965 # anonymous user | 1018 # anonymous user |
966 put :update, | 1019 put :update, |
967 :id => 1, | 1020 :id => 1, |
968 :notes => '', | 1021 :notes => '', |
969 :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain')}} | 1022 :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain')}} |
974 | 1027 |
975 def test_put_update_with_no_change | 1028 def test_put_update_with_no_change |
976 issue = Issue.find(1) | 1029 issue = Issue.find(1) |
977 issue.journals.clear | 1030 issue.journals.clear |
978 ActionMailer::Base.deliveries.clear | 1031 ActionMailer::Base.deliveries.clear |
979 | 1032 |
980 put :update, | 1033 put :update, |
981 :id => 1, | 1034 :id => 1, |
982 :notes => '' | 1035 :notes => '' |
983 assert_redirected_to :action => 'show', :id => '1' | 1036 assert_redirected_to :action => 'show', :id => '1' |
984 | 1037 |
985 issue.reload | 1038 issue.reload |
986 assert issue.journals.empty? | 1039 assert issue.journals.empty? |
987 # No email should be sent | 1040 # No email should be sent |
988 assert ActionMailer::Base.deliveries.empty? | 1041 assert ActionMailer::Base.deliveries.empty? |
989 end | 1042 end |
992 @request.session[:user_id] = 2 | 1045 @request.session[:user_id] = 2 |
993 ActionMailer::Base.deliveries.clear | 1046 ActionMailer::Base.deliveries.clear |
994 issue = Issue.find(1) | 1047 issue = Issue.find(1) |
995 old_subject = issue.subject | 1048 old_subject = issue.subject |
996 new_subject = 'Subject modified by IssuesControllerTest#test_post_edit' | 1049 new_subject = 'Subject modified by IssuesControllerTest#test_post_edit' |
997 | 1050 |
998 put :update, :id => 1, :issue => {:subject => new_subject, | 1051 put :update, :id => 1, :issue => {:subject => new_subject, |
999 :priority_id => '6', | 1052 :priority_id => '6', |
1000 :category_id => '1' # no change | 1053 :category_id => '1' # no change |
1001 } | 1054 } |
1002 assert_equal 1, ActionMailer::Base.deliveries.size | 1055 assert_equal 1, ActionMailer::Base.deliveries.size |
1003 end | 1056 end |
1004 | 1057 |
1005 def test_put_update_with_invalid_spent_time | 1058 def test_put_update_with_invalid_spent_time_hours_only |
1006 @request.session[:user_id] = 2 | 1059 @request.session[:user_id] = 2 |
1007 notes = 'Note added by IssuesControllerTest#test_post_edit_with_invalid_spent_time' | 1060 notes = 'Note added by IssuesControllerTest#test_post_edit_with_invalid_spent_time' |
1008 | 1061 |
1009 assert_no_difference('Journal.count') do | 1062 assert_no_difference('Journal.count') do |
1010 put :update, | 1063 put :update, |
1011 :id => 1, | 1064 :id => 1, |
1012 :notes => notes, | 1065 :notes => notes, |
1013 :time_entry => {"comments"=>"", "activity_id"=>"", "hours"=>"2z"} | 1066 :time_entry => {"comments"=>"", "activity_id"=>"", "hours"=>"2z"} |
1014 end | 1067 end |
1015 assert_response :success | 1068 assert_response :success |
1016 assert_template 'edit' | 1069 assert_template 'edit' |
1017 | 1070 |
1018 assert_tag :textarea, :attributes => { :name => 'notes' }, | 1071 assert_error_tag :descendant => {:content => /Activity can't be blank/} |
1019 :content => notes | 1072 assert_tag :textarea, :attributes => { :name => 'notes' }, :content => notes |
1020 assert_tag :input, :attributes => { :name => 'time_entry[hours]', :value => "2z" } | 1073 assert_tag :input, :attributes => { :name => 'time_entry[hours]', :value => "2z" } |
1021 end | 1074 end |
1022 | 1075 |
1076 def test_put_update_with_invalid_spent_time_comments_only | |
1077 @request.session[:user_id] = 2 | |
1078 notes = 'Note added by IssuesControllerTest#test_post_edit_with_invalid_spent_time' | |
1079 | |
1080 assert_no_difference('Journal.count') do | |
1081 put :update, | |
1082 :id => 1, | |
1083 :notes => notes, | |
1084 :time_entry => {"comments"=>"this is my comment", "activity_id"=>"", "hours"=>""} | |
1085 end | |
1086 assert_response :success | |
1087 assert_template 'edit' | |
1088 | |
1089 assert_error_tag :descendant => {:content => /Activity can't be blank/} | |
1090 assert_error_tag :descendant => {:content => /Hours can't be blank/} | |
1091 assert_tag :textarea, :attributes => { :name => 'notes' }, :content => notes | |
1092 assert_tag :input, :attributes => { :name => 'time_entry[comments]', :value => "this is my comment" } | |
1093 end | |
1094 | |
1023 def test_put_update_should_allow_fixed_version_to_be_set_to_a_subproject | 1095 def test_put_update_should_allow_fixed_version_to_be_set_to_a_subproject |
1024 issue = Issue.find(2) | 1096 issue = Issue.find(2) |
1025 @request.session[:user_id] = 2 | 1097 @request.session[:user_id] = 2 |
1026 | 1098 |
1027 put :update, | 1099 put :update, |
1048 :back_url => '/issues' | 1120 :back_url => '/issues' |
1049 | 1121 |
1050 assert_response :redirect | 1122 assert_response :redirect |
1051 assert_redirected_to '/issues' | 1123 assert_redirected_to '/issues' |
1052 end | 1124 end |
1053 | 1125 |
1054 def test_put_update_should_not_redirect_back_using_the_back_url_parameter_off_the_host | 1126 def test_put_update_should_not_redirect_back_using_the_back_url_parameter_off_the_host |
1055 issue = Issue.find(2) | 1127 issue = Issue.find(2) |
1056 @request.session[:user_id] = 2 | 1128 @request.session[:user_id] = 2 |
1057 | 1129 |
1058 put :update, | 1130 put :update, |
1063 :back_url => 'http://google.com' | 1135 :back_url => 'http://google.com' |
1064 | 1136 |
1065 assert_response :redirect | 1137 assert_response :redirect |
1066 assert_redirected_to :controller => 'issues', :action => 'show', :id => issue.id | 1138 assert_redirected_to :controller => 'issues', :action => 'show', :id => issue.id |
1067 end | 1139 end |
1068 | 1140 |
1069 def test_get_bulk_edit | 1141 def test_get_bulk_edit |
1070 @request.session[:user_id] = 2 | 1142 @request.session[:user_id] = 2 |
1071 get :bulk_edit, :ids => [1, 2] | 1143 get :bulk_edit, :ids => [1, 2] |
1072 assert_response :success | 1144 assert_response :success |
1073 assert_template 'bulk_edit' | 1145 assert_template 'bulk_edit' |
1074 | 1146 |
1147 assert_tag :input, :attributes => {:name => 'issue[parent_issue_id]'} | |
1148 | |
1075 # Project specific custom field, date type | 1149 # Project specific custom field, date type |
1076 field = CustomField.find(9) | 1150 field = CustomField.find(9) |
1077 assert !field.is_for_all? | 1151 assert !field.is_for_all? |
1078 assert_equal 'date', field.field_format | 1152 assert_equal 'date', field.field_format |
1079 assert_tag :input, :attributes => {:name => 'issue[custom_field_values][9]'} | 1153 assert_tag :input, :attributes => {:name => 'issue[custom_field_values][9]'} |
1080 | 1154 |
1081 # System wide custom field | 1155 # System wide custom field |
1082 assert CustomField.find(1).is_for_all? | 1156 assert CustomField.find(1).is_for_all? |
1083 assert_tag :select, :attributes => {:name => 'issue[custom_field_values][1]'} | 1157 assert_tag :select, :attributes => {:name => 'issue[custom_field_values][1]'} |
1084 end | 1158 end |
1085 | 1159 |
1086 def test_get_bulk_edit_on_different_projects | 1160 def test_get_bulk_edit_on_different_projects |
1087 @request.session[:user_id] = 2 | 1161 @request.session[:user_id] = 2 |
1088 get :bulk_edit, :ids => [1, 2, 6] | 1162 get :bulk_edit, :ids => [1, 2, 6] |
1089 assert_response :success | 1163 assert_response :success |
1090 assert_template 'bulk_edit' | 1164 assert_template 'bulk_edit' |
1091 | 1165 |
1166 # Can not set issues from different projects as children of an issue | |
1167 assert_no_tag :input, :attributes => {:name => 'issue[parent_issue_id]'} | |
1168 | |
1092 # Project specific custom field, date type | 1169 # Project specific custom field, date type |
1093 field = CustomField.find(9) | 1170 field = CustomField.find(9) |
1094 assert !field.is_for_all? | 1171 assert !field.is_for_all? |
1095 assert !field.project_ids.include?(Issue.find(6).project_id) | 1172 assert !field.project_ids.include?(Issue.find(6).project_id) |
1096 assert_no_tag :input, :attributes => {:name => 'issue[custom_field_values][9]'} | 1173 assert_no_tag :input, :attributes => {:name => 'issue[custom_field_values][9]'} |
1097 end | 1174 end |
1098 | 1175 |
1176 def test_get_bulk_edit_with_user_custom_field | |
1177 field = IssueCustomField.create!(:name => 'Tester', :field_format => 'user', :is_for_all => true) | |
1178 | |
1179 @request.session[:user_id] = 2 | |
1180 get :bulk_edit, :ids => [1, 2] | |
1181 assert_response :success | |
1182 assert_template 'bulk_edit' | |
1183 | |
1184 assert_tag :select, | |
1185 :attributes => {:name => "issue[custom_field_values][#{field.id}]"}, | |
1186 :children => { | |
1187 :only => {:tag => 'option'}, | |
1188 :count => Project.find(1).users.count + 1 | |
1189 } | |
1190 end | |
1191 | |
1192 def test_get_bulk_edit_with_version_custom_field | |
1193 field = IssueCustomField.create!(:name => 'Affected version', :field_format => 'version', :is_for_all => true) | |
1194 | |
1195 @request.session[:user_id] = 2 | |
1196 get :bulk_edit, :ids => [1, 2] | |
1197 assert_response :success | |
1198 assert_template 'bulk_edit' | |
1199 | |
1200 assert_tag :select, | |
1201 :attributes => {:name => "issue[custom_field_values][#{field.id}]"}, | |
1202 :children => { | |
1203 :only => {:tag => 'option'}, | |
1204 :count => Project.find(1).versions.count + 1 | |
1205 } | |
1206 end | |
1207 | |
1099 def test_bulk_update | 1208 def test_bulk_update |
1100 @request.session[:user_id] = 2 | 1209 @request.session[:user_id] = 2 |
1101 # update issues priority | 1210 # update issues priority |
1102 post :bulk_update, :ids => [1, 2], :notes => 'Bulk editing', | 1211 post :bulk_update, :ids => [1, 2], :notes => 'Bulk editing', |
1103 :issue => {:priority_id => 7, | 1212 :issue => {:priority_id => 7, |
1104 :assigned_to_id => '', | 1213 :assigned_to_id => '', |
1105 :custom_field_values => {'2' => ''}} | 1214 :custom_field_values => {'2' => ''}} |
1106 | 1215 |
1107 assert_response 302 | 1216 assert_response 302 |
1108 # check that the issues were updated | 1217 # check that the issues were updated |
1109 assert_equal [7, 7], Issue.find_all_by_id([1, 2]).collect {|i| i.priority.id} | 1218 assert_equal [7, 7], Issue.find_all_by_id([1, 2]).collect {|i| i.priority.id} |
1110 | 1219 |
1111 issue = Issue.find(1) | 1220 issue = Issue.find(1) |
1112 journal = issue.journals.find(:first, :order => 'created_on DESC') | 1221 journal = issue.journals.find(:first, :order => 'created_on DESC') |
1113 assert_equal '125', issue.custom_value_for(2).value | 1222 assert_equal '125', issue.custom_value_for(2).value |
1114 assert_equal 'Bulk editing', journal.notes | 1223 assert_equal 'Bulk editing', journal.notes |
1115 assert_equal 1, journal.details.size | 1224 assert_equal 1, journal.details.size |
1120 # update issues priority | 1229 # update issues priority |
1121 post :bulk_update, :ids => [1, 2, 6], :notes => 'Bulk editing', | 1230 post :bulk_update, :ids => [1, 2, 6], :notes => 'Bulk editing', |
1122 :issue => {:priority_id => 7, | 1231 :issue => {:priority_id => 7, |
1123 :assigned_to_id => '', | 1232 :assigned_to_id => '', |
1124 :custom_field_values => {'2' => ''}} | 1233 :custom_field_values => {'2' => ''}} |
1125 | 1234 |
1126 assert_response 302 | 1235 assert_response 302 |
1127 # check that the issues were updated | 1236 # check that the issues were updated |
1128 assert_equal [7, 7, 7], Issue.find([1,2,6]).map(&:priority_id) | 1237 assert_equal [7, 7, 7], Issue.find([1,2,6]).map(&:priority_id) |
1129 | 1238 |
1130 issue = Issue.find(1) | 1239 issue = Issue.find(1) |
1131 journal = issue.journals.find(:first, :order => 'created_on DESC') | 1240 journal = issue.journals.find(:first, :order => 'created_on DESC') |
1132 assert_equal '125', issue.custom_value_for(2).value | 1241 assert_equal '125', issue.custom_value_for(2).value |
1133 assert_equal 'Bulk editing', journal.notes | 1242 assert_equal 'Bulk editing', journal.notes |
1134 assert_equal 1, journal.details.size | 1243 assert_equal 1, journal.details.size |
1145 :assigned_to_id => '', | 1254 :assigned_to_id => '', |
1146 :custom_field_values => {'2' => ''}} | 1255 :custom_field_values => {'2' => ''}} |
1147 assert_response 403 | 1256 assert_response 403 |
1148 assert_not_equal "Bulk should fail", Journal.last.notes | 1257 assert_not_equal "Bulk should fail", Journal.last.notes |
1149 end | 1258 end |
1150 | 1259 |
1151 def test_bullk_update_should_send_a_notification | 1260 def test_bullk_update_should_send_a_notification |
1152 @request.session[:user_id] = 2 | 1261 @request.session[:user_id] = 2 |
1153 ActionMailer::Base.deliveries.clear | 1262 ActionMailer::Base.deliveries.clear |
1154 post(:bulk_update, | 1263 post(:bulk_update, |
1155 { | 1264 { |
1171 # update issues priority | 1280 # update issues priority |
1172 post :bulk_update, :ids => [1, 2], :notes => 'Bulk editing status', | 1281 post :bulk_update, :ids => [1, 2], :notes => 'Bulk editing status', |
1173 :issue => {:priority_id => '', | 1282 :issue => {:priority_id => '', |
1174 :assigned_to_id => '', | 1283 :assigned_to_id => '', |
1175 :status_id => '5'} | 1284 :status_id => '5'} |
1176 | 1285 |
1177 assert_response 302 | 1286 assert_response 302 |
1178 issue = Issue.find(1) | 1287 issue = Issue.find(1) |
1179 assert issue.closed? | 1288 assert issue.closed? |
1289 end | |
1290 | |
1291 def test_bulk_update_parent_id | |
1292 @request.session[:user_id] = 2 | |
1293 post :bulk_update, :ids => [1, 3], | |
1294 :notes => 'Bulk editing parent', | |
1295 :issue => {:priority_id => '', :assigned_to_id => '', :status_id => '', :parent_issue_id => '2'} | |
1296 | |
1297 assert_response 302 | |
1298 parent = Issue.find(2) | |
1299 assert_equal parent.id, Issue.find(1).parent_id | |
1300 assert_equal parent.id, Issue.find(3).parent_id | |
1301 assert_equal [1, 3], parent.children.collect(&:id).sort | |
1180 end | 1302 end |
1181 | 1303 |
1182 def test_bulk_update_custom_field | 1304 def test_bulk_update_custom_field |
1183 @request.session[:user_id] = 2 | 1305 @request.session[:user_id] = 2 |
1184 # update issues priority | 1306 # update issues priority |
1185 post :bulk_update, :ids => [1, 2], :notes => 'Bulk editing custom field', | 1307 post :bulk_update, :ids => [1, 2], :notes => 'Bulk editing custom field', |
1186 :issue => {:priority_id => '', | 1308 :issue => {:priority_id => '', |
1187 :assigned_to_id => '', | 1309 :assigned_to_id => '', |
1188 :custom_field_values => {'2' => '777'}} | 1310 :custom_field_values => {'2' => '777'}} |
1189 | 1311 |
1190 assert_response 302 | 1312 assert_response 302 |
1191 | 1313 |
1192 issue = Issue.find(1) | 1314 issue = Issue.find(1) |
1193 journal = issue.journals.find(:first, :order => 'created_on DESC') | 1315 journal = issue.journals.find(:first, :order => 'created_on DESC') |
1194 assert_equal '777', issue.custom_value_for(2).value | 1316 assert_equal '777', issue.custom_value_for(2).value |
1195 assert_equal 1, journal.details.size | 1317 assert_equal 1, journal.details.size |
1196 assert_equal '125', journal.details.first.old_value | 1318 assert_equal '125', journal.details.first.old_value |
1204 post :bulk_update, :ids => [1, 2], :notes => 'Bulk unassigning', :issue => {:assigned_to_id => 'none'} | 1326 post :bulk_update, :ids => [1, 2], :notes => 'Bulk unassigning', :issue => {:assigned_to_id => 'none'} |
1205 assert_response 302 | 1327 assert_response 302 |
1206 # check that the issues were updated | 1328 # check that the issues were updated |
1207 assert_nil Issue.find(2).assigned_to | 1329 assert_nil Issue.find(2).assigned_to |
1208 end | 1330 end |
1209 | 1331 |
1210 def test_post_bulk_update_should_allow_fixed_version_to_be_set_to_a_subproject | 1332 def test_post_bulk_update_should_allow_fixed_version_to_be_set_to_a_subproject |
1211 @request.session[:user_id] = 2 | 1333 @request.session[:user_id] = 2 |
1212 | 1334 |
1213 post :bulk_update, :ids => [1,2], :issue => {:fixed_version_id => 4} | 1335 post :bulk_update, :ids => [1,2], :issue => {:fixed_version_id => 4} |
1214 | 1336 |
1233 post :bulk_update, :ids => [1,2], :back_url => 'http://google.com' | 1355 post :bulk_update, :ids => [1,2], :back_url => 'http://google.com' |
1234 | 1356 |
1235 assert_response :redirect | 1357 assert_response :redirect |
1236 assert_redirected_to :controller => 'issues', :action => 'index', :project_id => Project.find(1).identifier | 1358 assert_redirected_to :controller => 'issues', :action => 'index', :project_id => Project.find(1).identifier |
1237 end | 1359 end |
1238 | 1360 |
1239 def test_destroy_issue_with_no_time_entries | 1361 def test_destroy_issue_with_no_time_entries |
1240 assert_nil TimeEntry.find_by_issue_id(2) | 1362 assert_nil TimeEntry.find_by_issue_id(2) |
1241 @request.session[:user_id] = 2 | 1363 @request.session[:user_id] = 2 |
1242 post :destroy, :id => 2 | 1364 post :destroy, :id => 2 |
1243 assert_redirected_to :action => 'index', :project_id => 'ecookbook' | 1365 assert_redirected_to :action => 'index', :project_id => 'ecookbook' |
1267 assert_redirected_to :action => 'index', :project_id => 'ecookbook' | 1389 assert_redirected_to :action => 'index', :project_id => 'ecookbook' |
1268 assert !(Issue.find_by_id(1) || Issue.find_by_id(3)) | 1390 assert !(Issue.find_by_id(1) || Issue.find_by_id(3)) |
1269 assert_nil TimeEntry.find(1).issue_id | 1391 assert_nil TimeEntry.find(1).issue_id |
1270 assert_nil TimeEntry.find(2).issue_id | 1392 assert_nil TimeEntry.find(2).issue_id |
1271 end | 1393 end |
1272 | 1394 |
1273 def test_destroy_issues_and_reassign_time_entries_to_another_issue | 1395 def test_destroy_issues_and_reassign_time_entries_to_another_issue |
1274 @request.session[:user_id] = 2 | 1396 @request.session[:user_id] = 2 |
1275 post :destroy, :ids => [1, 3], :todo => 'reassign', :reassign_to_id => 2 | 1397 post :destroy, :ids => [1, 3], :todo => 'reassign', :reassign_to_id => 2 |
1276 assert_redirected_to :action => 'index', :project_id => 'ecookbook' | 1398 assert_redirected_to :action => 'index', :project_id => 'ecookbook' |
1277 assert !(Issue.find_by_id(1) || Issue.find_by_id(3)) | 1399 assert !(Issue.find_by_id(1) || Issue.find_by_id(3)) |
1278 assert_equal 2, TimeEntry.find(1).issue_id | 1400 assert_equal 2, TimeEntry.find(1).issue_id |
1279 assert_equal 2, TimeEntry.find(2).issue_id | 1401 assert_equal 2, TimeEntry.find(2).issue_id |
1280 end | 1402 end |
1281 | 1403 |
1282 def test_destroy_issues_from_different_projects | 1404 def test_destroy_issues_from_different_projects |
1283 @request.session[:user_id] = 2 | 1405 @request.session[:user_id] = 2 |
1284 post :destroy, :ids => [1, 2, 6], :todo => 'destroy' | 1406 post :destroy, :ids => [1, 2, 6], :todo => 'destroy' |
1285 assert_redirected_to :controller => 'issues', :action => 'index' | 1407 assert_redirected_to :controller => 'issues', :action => 'index' |
1286 assert !(Issue.find_by_id(1) || Issue.find_by_id(2) || Issue.find_by_id(6)) | 1408 assert !(Issue.find_by_id(1) || Issue.find_by_id(2) || Issue.find_by_id(6)) |
1287 end | 1409 end |
1288 | 1410 |
1411 def test_destroy_parent_and_child_issues | |
1412 parent = Issue.generate!(:project_id => 1, :tracker_id => 1) | |
1413 child = Issue.generate!(:project_id => 1, :tracker_id => 1, :parent_issue_id => parent.id) | |
1414 assert child.is_descendant_of?(parent.reload) | |
1415 | |
1416 @request.session[:user_id] = 2 | |
1417 assert_difference 'Issue.count', -2 do | |
1418 post :destroy, :ids => [parent.id, child.id], :todo => 'destroy' | |
1419 end | |
1420 assert_response 302 | |
1421 end | |
1422 | |
1289 def test_default_search_scope | 1423 def test_default_search_scope |
1290 get :index | 1424 get :index |
1291 assert_tag :div, :attributes => {:id => 'quick-search'}, | 1425 assert_tag :div, :attributes => {:id => 'quick-search'}, |
1292 :child => {:tag => 'form', | 1426 :child => {:tag => 'form', |
1293 :child => {:tag => 'input', :attributes => {:name => 'issues', :type => 'hidden', :value => '1'}}} | 1427 :child => {:tag => 'input', :attributes => {:name => 'issues', :type => 'hidden', :value => '1'}}} |