##// END OF EJS Templates
Adds tests for when showing/deleting an invalid issue....
Jean-Philippe Lang -
r10710:46fe61d51e8b
parent child
Show More
@@ -1,3822 +1,3835
1 1 # Redmine - project management software
2 2 # Copyright (C) 2006-2012 Jean-Philippe Lang
3 3 #
4 4 # This program is free software; you can redistribute it and/or
5 5 # modify it under the terms of the GNU General Public License
6 6 # as published by the Free Software Foundation; either version 2
7 7 # of the License, or (at your option) any later version.
8 8 #
9 9 # This program is distributed in the hope that it will be useful,
10 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 12 # GNU General Public License for more details.
13 13 #
14 14 # You should have received a copy of the GNU General Public License
15 15 # along with this program; if not, write to the Free Software
16 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 17
18 18 require File.expand_path('../../test_helper', __FILE__)
19 19
20 20 class IssuesControllerTest < ActionController::TestCase
21 21 fixtures :projects,
22 22 :users,
23 23 :roles,
24 24 :members,
25 25 :member_roles,
26 26 :issues,
27 27 :issue_statuses,
28 28 :versions,
29 29 :trackers,
30 30 :projects_trackers,
31 31 :issue_categories,
32 32 :enabled_modules,
33 33 :enumerations,
34 34 :attachments,
35 35 :workflows,
36 36 :custom_fields,
37 37 :custom_values,
38 38 :custom_fields_projects,
39 39 :custom_fields_trackers,
40 40 :time_entries,
41 41 :journals,
42 42 :journal_details,
43 43 :queries,
44 44 :repositories,
45 45 :changesets
46 46
47 47 include Redmine::I18n
48 48
49 49 def setup
50 50 User.current = nil
51 51 end
52 52
53 53 def test_index
54 54 with_settings :default_language => "en" do
55 55 get :index
56 56 assert_response :success
57 57 assert_template 'index'
58 58 assert_not_nil assigns(:issues)
59 59 assert_nil assigns(:project)
60 60
61 61 # links to visible issues
62 62 assert_select 'a[href=/issues/1]', :text => /Can&#x27;t print recipes/
63 63 assert_select 'a[href=/issues/5]', :text => /Subproject issue/
64 64 # private projects hidden
65 65 assert_select 'a[href=/issues/6]', 0
66 66 assert_select 'a[href=/issues/4]', 0
67 67 # project column
68 68 assert_select 'th', :text => /Project/
69 69 end
70 70 end
71 71
72 72 def test_index_should_not_list_issues_when_module_disabled
73 73 EnabledModule.delete_all("name = 'issue_tracking' AND project_id = 1")
74 74 get :index
75 75 assert_response :success
76 76 assert_template 'index'
77 77 assert_not_nil assigns(:issues)
78 78 assert_nil assigns(:project)
79 79
80 80 assert_select 'a[href=/issues/1]', 0
81 81 assert_select 'a[href=/issues/5]', :text => /Subproject issue/
82 82 end
83 83
84 84 def test_index_should_list_visible_issues_only
85 85 get :index, :per_page => 100
86 86 assert_response :success
87 87 assert_not_nil assigns(:issues)
88 88 assert_nil assigns(:issues).detect {|issue| !issue.visible?}
89 89 end
90 90
91 91 def test_index_with_project
92 92 Setting.display_subprojects_issues = 0
93 93 get :index, :project_id => 1
94 94 assert_response :success
95 95 assert_template 'index'
96 96 assert_not_nil assigns(:issues)
97 97
98 98 assert_select 'a[href=/issues/1]', :text => /Can&#x27;t print recipes/
99 99 assert_select 'a[href=/issues/5]', 0
100 100 end
101 101
102 102 def test_index_with_project_and_subprojects
103 103 Setting.display_subprojects_issues = 1
104 104 get :index, :project_id => 1
105 105 assert_response :success
106 106 assert_template 'index'
107 107 assert_not_nil assigns(:issues)
108 108
109 109 assert_select 'a[href=/issues/1]', :text => /Can&#x27;t print recipes/
110 110 assert_select 'a[href=/issues/5]', :text => /Subproject issue/
111 111 assert_select 'a[href=/issues/6]', 0
112 112 end
113 113
114 114 def test_index_with_project_and_subprojects_should_show_private_subprojects_with_permission
115 115 @request.session[:user_id] = 2
116 116 Setting.display_subprojects_issues = 1
117 117 get :index, :project_id => 1
118 118 assert_response :success
119 119 assert_template 'index'
120 120 assert_not_nil assigns(:issues)
121 121
122 122 assert_select 'a[href=/issues/1]', :text => /Can&#x27;t print recipes/
123 123 assert_select 'a[href=/issues/5]', :text => /Subproject issue/
124 124 assert_select 'a[href=/issues/6]', :text => /Issue of a private subproject/
125 125 end
126 126
127 127 def test_index_with_project_and_default_filter
128 128 get :index, :project_id => 1, :set_filter => 1
129 129 assert_response :success
130 130 assert_template 'index'
131 131 assert_not_nil assigns(:issues)
132 132
133 133 query = assigns(:query)
134 134 assert_not_nil query
135 135 # default filter
136 136 assert_equal({'status_id' => {:operator => 'o', :values => ['']}}, query.filters)
137 137 end
138 138
139 139 def test_index_with_project_and_filter
140 140 get :index, :project_id => 1, :set_filter => 1,
141 141 :f => ['tracker_id'],
142 142 :op => {'tracker_id' => '='},
143 143 :v => {'tracker_id' => ['1']}
144 144 assert_response :success
145 145 assert_template 'index'
146 146 assert_not_nil assigns(:issues)
147 147
148 148 query = assigns(:query)
149 149 assert_not_nil query
150 150 assert_equal({'tracker_id' => {:operator => '=', :values => ['1']}}, query.filters)
151 151 end
152 152
153 153 def test_index_with_short_filters
154 154 to_test = {
155 155 'status_id' => {
156 156 'o' => { :op => 'o', :values => [''] },
157 157 'c' => { :op => 'c', :values => [''] },
158 158 '7' => { :op => '=', :values => ['7'] },
159 159 '7|3|4' => { :op => '=', :values => ['7', '3', '4'] },
160 160 '=7' => { :op => '=', :values => ['7'] },
161 161 '!3' => { :op => '!', :values => ['3'] },
162 162 '!7|3|4' => { :op => '!', :values => ['7', '3', '4'] }},
163 163 'subject' => {
164 164 'This is a subject' => { :op => '=', :values => ['This is a subject'] },
165 165 'o' => { :op => '=', :values => ['o'] },
166 166 '~This is part of a subject' => { :op => '~', :values => ['This is part of a subject'] },
167 167 '!~This is part of a subject' => { :op => '!~', :values => ['This is part of a subject'] }},
168 168 'tracker_id' => {
169 169 '3' => { :op => '=', :values => ['3'] },
170 170 '=3' => { :op => '=', :values => ['3'] }},
171 171 'start_date' => {
172 172 '2011-10-12' => { :op => '=', :values => ['2011-10-12'] },
173 173 '=2011-10-12' => { :op => '=', :values => ['2011-10-12'] },
174 174 '>=2011-10-12' => { :op => '>=', :values => ['2011-10-12'] },
175 175 '<=2011-10-12' => { :op => '<=', :values => ['2011-10-12'] },
176 176 '><2011-10-01|2011-10-30' => { :op => '><', :values => ['2011-10-01', '2011-10-30'] },
177 177 '<t+2' => { :op => '<t+', :values => ['2'] },
178 178 '>t+2' => { :op => '>t+', :values => ['2'] },
179 179 't+2' => { :op => 't+', :values => ['2'] },
180 180 't' => { :op => 't', :values => [''] },
181 181 'w' => { :op => 'w', :values => [''] },
182 182 '>t-2' => { :op => '>t-', :values => ['2'] },
183 183 '<t-2' => { :op => '<t-', :values => ['2'] },
184 184 't-2' => { :op => 't-', :values => ['2'] }},
185 185 'created_on' => {
186 186 '>=2011-10-12' => { :op => '>=', :values => ['2011-10-12'] },
187 187 '<t-2' => { :op => '<t-', :values => ['2'] },
188 188 '>t-2' => { :op => '>t-', :values => ['2'] },
189 189 't-2' => { :op => 't-', :values => ['2'] }},
190 190 'cf_1' => {
191 191 'c' => { :op => '=', :values => ['c'] },
192 192 '!c' => { :op => '!', :values => ['c'] },
193 193 '!*' => { :op => '!*', :values => [''] },
194 194 '*' => { :op => '*', :values => [''] }},
195 195 'estimated_hours' => {
196 196 '=13.4' => { :op => '=', :values => ['13.4'] },
197 197 '>=45' => { :op => '>=', :values => ['45'] },
198 198 '<=125' => { :op => '<=', :values => ['125'] },
199 199 '><10.5|20.5' => { :op => '><', :values => ['10.5', '20.5'] },
200 200 '!*' => { :op => '!*', :values => [''] },
201 201 '*' => { :op => '*', :values => [''] }}
202 202 }
203 203
204 204 default_filter = { 'status_id' => {:operator => 'o', :values => [''] }}
205 205
206 206 to_test.each do |field, expression_and_expected|
207 207 expression_and_expected.each do |filter_expression, expected|
208 208
209 209 get :index, :set_filter => 1, field => filter_expression
210 210
211 211 assert_response :success
212 212 assert_template 'index'
213 213 assert_not_nil assigns(:issues)
214 214
215 215 query = assigns(:query)
216 216 assert_not_nil query
217 217 assert query.has_filter?(field)
218 218 assert_equal(default_filter.merge({field => {:operator => expected[:op], :values => expected[:values]}}), query.filters)
219 219 end
220 220 end
221 221 end
222 222
223 223 def test_index_with_project_and_empty_filters
224 224 get :index, :project_id => 1, :set_filter => 1, :fields => ['']
225 225 assert_response :success
226 226 assert_template 'index'
227 227 assert_not_nil assigns(:issues)
228 228
229 229 query = assigns(:query)
230 230 assert_not_nil query
231 231 # no filter
232 232 assert_equal({}, query.filters)
233 233 end
234 234
235 235 def test_index_with_project_custom_field_filter
236 236 field = ProjectCustomField.create!(:name => 'Client', :is_filter => true, :field_format => 'string')
237 237 CustomValue.create!(:custom_field => field, :customized => Project.find(3), :value => 'Foo')
238 238 CustomValue.create!(:custom_field => field, :customized => Project.find(5), :value => 'Foo')
239 239 filter_name = "project.cf_#{field.id}"
240 240 @request.session[:user_id] = 1
241 241
242 242 get :index, :set_filter => 1,
243 243 :f => [filter_name],
244 244 :op => {filter_name => '='},
245 245 :v => {filter_name => ['Foo']}
246 246 assert_response :success
247 247 assert_template 'index'
248 248 assert_equal [3, 5], assigns(:issues).map(&:project_id).uniq.sort
249 249 end
250 250
251 251 def test_index_with_query
252 252 get :index, :project_id => 1, :query_id => 5
253 253 assert_response :success
254 254 assert_template 'index'
255 255 assert_not_nil assigns(:issues)
256 256 assert_nil assigns(:issue_count_by_group)
257 257 end
258 258
259 259 def test_index_with_query_grouped_by_tracker
260 260 get :index, :project_id => 1, :query_id => 6
261 261 assert_response :success
262 262 assert_template 'index'
263 263 assert_not_nil assigns(:issues)
264 264 assert_not_nil assigns(:issue_count_by_group)
265 265 end
266 266
267 267 def test_index_with_query_grouped_by_list_custom_field
268 268 get :index, :project_id => 1, :query_id => 9
269 269 assert_response :success
270 270 assert_template 'index'
271 271 assert_not_nil assigns(:issues)
272 272 assert_not_nil assigns(:issue_count_by_group)
273 273 end
274 274
275 275 def test_index_with_query_grouped_by_user_custom_field
276 276 cf = IssueCustomField.create!(:name => 'User', :is_for_all => true, :tracker_ids => [1,2,3], :field_format => 'user')
277 277 CustomValue.create!(:custom_field => cf, :customized => Issue.find(1), :value => '2')
278 278 CustomValue.create!(:custom_field => cf, :customized => Issue.find(2), :value => '3')
279 279 CustomValue.create!(:custom_field => cf, :customized => Issue.find(3), :value => '3')
280 280 CustomValue.create!(:custom_field => cf, :customized => Issue.find(5), :value => '')
281 281
282 282 get :index, :project_id => 1, :set_filter => 1, :group_by => "cf_#{cf.id}"
283 283 assert_response :success
284 284
285 285 assert_select 'tr.group', 3
286 286 assert_select 'tr.group' do
287 287 assert_select 'a', :text => 'John Smith'
288 288 assert_select 'span.count', :text => '1'
289 289 end
290 290 assert_select 'tr.group' do
291 291 assert_select 'a', :text => 'Dave Lopper'
292 292 assert_select 'span.count', :text => '2'
293 293 end
294 294 end
295 295
296 296 def test_index_with_query_grouped_by_tracker
297 297 3.times {|i| Issue.generate!(:tracker_id => (i + 1))}
298 298
299 299 get :index, :set_filter => 1, :group_by => 'tracker', :sort => 'id:desc'
300 300 assert_response :success
301 301
302 302 trackers = assigns(:issues).map(&:tracker).uniq
303 303 assert_equal [1, 2, 3], trackers.map(&:id)
304 304 end
305 305
306 306 def test_index_with_query_grouped_by_tracker_in_reverse_order
307 307 3.times {|i| Issue.generate!(:tracker_id => (i + 1))}
308 308
309 309 get :index, :set_filter => 1, :group_by => 'tracker', :sort => 'id:desc,tracker:desc'
310 310 assert_response :success
311 311
312 312 trackers = assigns(:issues).map(&:tracker).uniq
313 313 assert_equal [3, 2, 1], trackers.map(&:id)
314 314 end
315 315
316 316 def test_index_with_query_id_and_project_id_should_set_session_query
317 317 get :index, :project_id => 1, :query_id => 4
318 318 assert_response :success
319 319 assert_kind_of Hash, session[:query]
320 320 assert_equal 4, session[:query][:id]
321 321 assert_equal 1, session[:query][:project_id]
322 322 end
323 323
324 324 def test_index_with_invalid_query_id_should_respond_404
325 325 get :index, :project_id => 1, :query_id => 999
326 326 assert_response 404
327 327 end
328 328
329 329 def test_index_with_cross_project_query_in_session_should_show_project_issues
330 330 q = Query.create!(:name => "test", :user_id => 2, :is_public => false, :project => nil)
331 331 @request.session[:query] = {:id => q.id, :project_id => 1}
332 332
333 333 with_settings :display_subprojects_issues => '0' do
334 334 get :index, :project_id => 1
335 335 end
336 336 assert_response :success
337 337 assert_not_nil assigns(:query)
338 338 assert_equal q.id, assigns(:query).id
339 339 assert_equal 1, assigns(:query).project_id
340 340 assert_equal [1], assigns(:issues).map(&:project_id).uniq
341 341 end
342 342
343 343 def test_private_query_should_not_be_available_to_other_users
344 344 q = Query.create!(:name => "private", :user => User.find(2), :is_public => false, :project => nil)
345 345 @request.session[:user_id] = 3
346 346
347 347 get :index, :query_id => q.id
348 348 assert_response 403
349 349 end
350 350
351 351 def test_private_query_should_be_available_to_its_user
352 352 q = Query.create!(:name => "private", :user => User.find(2), :is_public => false, :project => nil)
353 353 @request.session[:user_id] = 2
354 354
355 355 get :index, :query_id => q.id
356 356 assert_response :success
357 357 end
358 358
359 359 def test_public_query_should_be_available_to_other_users
360 360 q = Query.create!(:name => "private", :user => User.find(2), :is_public => true, :project => nil)
361 361 @request.session[:user_id] = 3
362 362
363 363 get :index, :query_id => q.id
364 364 assert_response :success
365 365 end
366 366
367 367 def test_index_should_omit_page_param_in_export_links
368 368 get :index, :page => 2
369 369 assert_response :success
370 370 assert_select 'a.atom[href=/issues.atom]'
371 371 assert_select 'a.csv[href=/issues.csv]'
372 372 assert_select 'a.pdf[href=/issues.pdf]'
373 373 assert_select 'form#csv-export-form[action=/issues.csv]'
374 374 end
375 375
376 376 def test_index_csv
377 377 get :index, :format => 'csv'
378 378 assert_response :success
379 379 assert_not_nil assigns(:issues)
380 380 assert_equal 'text/csv; header=present', @response.content_type
381 381 assert @response.body.starts_with?("#,")
382 382 lines = @response.body.chomp.split("\n")
383 383 assert_equal assigns(:query).columns.size + 1, lines[0].split(',').size
384 384 end
385 385
386 386 def test_index_csv_with_project
387 387 get :index, :project_id => 1, :format => 'csv'
388 388 assert_response :success
389 389 assert_not_nil assigns(:issues)
390 390 assert_equal 'text/csv; header=present', @response.content_type
391 391 end
392 392
393 393 def test_index_csv_with_description
394 394 get :index, :format => 'csv', :description => '1'
395 395 assert_response :success
396 396 assert_not_nil assigns(:issues)
397 397 assert_equal 'text/csv; header=present', @response.content_type
398 398 assert @response.body.starts_with?("#,")
399 399 lines = @response.body.chomp.split("\n")
400 400 assert_equal assigns(:query).columns.size + 2, lines[0].split(',').size
401 401 end
402 402
403 403 def test_index_csv_with_spent_time_column
404 404 issue = Issue.create!(:project_id => 1, :tracker_id => 1, :subject => 'test_index_csv_with_spent_time_column', :author_id => 2)
405 405 TimeEntry.create!(:project => issue.project, :issue => issue, :hours => 7.33, :user => User.find(2), :spent_on => Date.today)
406 406
407 407 get :index, :format => 'csv', :set_filter => '1', :c => %w(subject spent_hours)
408 408 assert_response :success
409 409 assert_equal 'text/csv; header=present', @response.content_type
410 410 lines = @response.body.chomp.split("\n")
411 411 assert_include "#{issue.id},#{issue.subject},7.33", lines
412 412 end
413 413
414 414 def test_index_csv_with_all_columns
415 415 get :index, :format => 'csv', :columns => 'all'
416 416 assert_response :success
417 417 assert_not_nil assigns(:issues)
418 418 assert_equal 'text/csv; header=present', @response.content_type
419 419 assert @response.body.starts_with?("#,")
420 420 lines = @response.body.chomp.split("\n")
421 421 assert_equal assigns(:query).available_columns.size + 1, lines[0].split(',').size
422 422 end
423 423
424 424 def test_index_csv_with_multi_column_field
425 425 CustomField.find(1).update_attribute :multiple, true
426 426 issue = Issue.find(1)
427 427 issue.custom_field_values = {1 => ['MySQL', 'Oracle']}
428 428 issue.save!
429 429
430 430 get :index, :format => 'csv', :columns => 'all'
431 431 assert_response :success
432 432 lines = @response.body.chomp.split("\n")
433 433 assert lines.detect {|line| line.include?('"MySQL, Oracle"')}
434 434 end
435 435
436 436 def test_index_csv_big_5
437 437 with_settings :default_language => "zh-TW" do
438 438 str_utf8 = "\xe4\xb8\x80\xe6\x9c\x88"
439 439 str_big5 = "\xa4@\xa4\xeb"
440 440 if str_utf8.respond_to?(:force_encoding)
441 441 str_utf8.force_encoding('UTF-8')
442 442 str_big5.force_encoding('Big5')
443 443 end
444 444 issue = Issue.generate!(:subject => str_utf8)
445 445
446 446 get :index, :project_id => 1,
447 447 :f => ['subject'],
448 448 :op => '=', :values => [str_utf8],
449 449 :format => 'csv'
450 450 assert_equal 'text/csv; header=present', @response.content_type
451 451 lines = @response.body.chomp.split("\n")
452 452 s1 = "\xaa\xac\xbaA"
453 453 if str_utf8.respond_to?(:force_encoding)
454 454 s1.force_encoding('Big5')
455 455 end
456 456 assert lines[0].include?(s1)
457 457 assert lines[1].include?(str_big5)
458 458 end
459 459 end
460 460
461 461 def test_index_csv_cannot_convert_should_be_replaced_big_5
462 462 with_settings :default_language => "zh-TW" do
463 463 str_utf8 = "\xe4\xbb\xa5\xe5\x86\x85"
464 464 if str_utf8.respond_to?(:force_encoding)
465 465 str_utf8.force_encoding('UTF-8')
466 466 end
467 467 issue = Issue.generate!(:subject => str_utf8)
468 468
469 469 get :index, :project_id => 1,
470 470 :f => ['subject'],
471 471 :op => '=', :values => [str_utf8],
472 472 :c => ['status', 'subject'],
473 473 :format => 'csv',
474 474 :set_filter => 1
475 475 assert_equal 'text/csv; header=present', @response.content_type
476 476 lines = @response.body.chomp.split("\n")
477 477 s1 = "\xaa\xac\xbaA" # status
478 478 if str_utf8.respond_to?(:force_encoding)
479 479 s1.force_encoding('Big5')
480 480 end
481 481 assert lines[0].include?(s1)
482 482 s2 = lines[1].split(",")[2]
483 483 if s1.respond_to?(:force_encoding)
484 484 s3 = "\xa5H?" # subject
485 485 s3.force_encoding('Big5')
486 486 assert_equal s3, s2
487 487 elsif RUBY_PLATFORM == 'java'
488 488 assert_equal "??", s2
489 489 else
490 490 assert_equal "\xa5H???", s2
491 491 end
492 492 end
493 493 end
494 494
495 495 def test_index_csv_tw
496 496 with_settings :default_language => "zh-TW" do
497 497 str1 = "test_index_csv_tw"
498 498 issue = Issue.generate!(:subject => str1, :estimated_hours => '1234.5')
499 499
500 500 get :index, :project_id => 1,
501 501 :f => ['subject'],
502 502 :op => '=', :values => [str1],
503 503 :c => ['estimated_hours', 'subject'],
504 504 :format => 'csv',
505 505 :set_filter => 1
506 506 assert_equal 'text/csv; header=present', @response.content_type
507 507 lines = @response.body.chomp.split("\n")
508 508 assert_equal "#{issue.id},1234.50,#{str1}", lines[1]
509 509 end
510 510 end
511 511
512 512 def test_index_csv_fr
513 513 with_settings :default_language => "fr" do
514 514 str1 = "test_index_csv_fr"
515 515 issue = Issue.generate!(:subject => str1, :estimated_hours => '1234.5')
516 516
517 517 get :index, :project_id => 1,
518 518 :f => ['subject'],
519 519 :op => '=', :values => [str1],
520 520 :c => ['estimated_hours', 'subject'],
521 521 :format => 'csv',
522 522 :set_filter => 1
523 523 assert_equal 'text/csv; header=present', @response.content_type
524 524 lines = @response.body.chomp.split("\n")
525 525 assert_equal "#{issue.id};1234,50;#{str1}", lines[1]
526 526 end
527 527 end
528 528
529 529 def test_index_pdf
530 530 ["en", "zh", "zh-TW", "ja", "ko"].each do |lang|
531 531 with_settings :default_language => lang do
532 532
533 533 get :index
534 534 assert_response :success
535 535 assert_template 'index'
536 536
537 537 if lang == "ja"
538 538 if RUBY_PLATFORM != 'java'
539 539 assert_equal "CP932", l(:general_pdf_encoding)
540 540 end
541 541 if RUBY_PLATFORM == 'java' && l(:general_pdf_encoding) == "CP932"
542 542 next
543 543 end
544 544 end
545 545
546 546 get :index, :format => 'pdf'
547 547 assert_response :success
548 548 assert_not_nil assigns(:issues)
549 549 assert_equal 'application/pdf', @response.content_type
550 550
551 551 get :index, :project_id => 1, :format => 'pdf'
552 552 assert_response :success
553 553 assert_not_nil assigns(:issues)
554 554 assert_equal 'application/pdf', @response.content_type
555 555
556 556 get :index, :project_id => 1, :query_id => 6, :format => 'pdf'
557 557 assert_response :success
558 558 assert_not_nil assigns(:issues)
559 559 assert_equal 'application/pdf', @response.content_type
560 560 end
561 561 end
562 562 end
563 563
564 564 def test_index_pdf_with_query_grouped_by_list_custom_field
565 565 get :index, :project_id => 1, :query_id => 9, :format => 'pdf'
566 566 assert_response :success
567 567 assert_not_nil assigns(:issues)
568 568 assert_not_nil assigns(:issue_count_by_group)
569 569 assert_equal 'application/pdf', @response.content_type
570 570 end
571 571
572 572 def test_index_atom
573 573 get :index, :project_id => 'ecookbook', :format => 'atom'
574 574 assert_response :success
575 575 assert_template 'common/feed'
576 576 assert_equal 'application/atom+xml', response.content_type
577 577
578 578 assert_select 'feed' do
579 579 assert_select 'link[rel=self][href=?]', 'http://test.host/projects/ecookbook/issues.atom'
580 580 assert_select 'link[rel=alternate][href=?]', 'http://test.host/projects/ecookbook/issues'
581 581 assert_select 'entry link[href=?]', 'http://test.host/issues/1'
582 582 end
583 583 end
584 584
585 585 def test_index_sort
586 586 get :index, :sort => 'tracker,id:desc'
587 587 assert_response :success
588 588
589 589 sort_params = @request.session['issues_index_sort']
590 590 assert sort_params.is_a?(String)
591 591 assert_equal 'tracker,id:desc', sort_params
592 592
593 593 issues = assigns(:issues)
594 594 assert_not_nil issues
595 595 assert !issues.empty?
596 596 assert_equal issues.sort {|a,b| a.tracker == b.tracker ? b.id <=> a.id : a.tracker <=> b.tracker }.collect(&:id), issues.collect(&:id)
597 597 end
598 598
599 599 def test_index_sort_by_field_not_included_in_columns
600 600 Setting.issue_list_default_columns = %w(subject author)
601 601 get :index, :sort => 'tracker'
602 602 end
603 603
604 604 def test_index_sort_by_assigned_to
605 605 get :index, :sort => 'assigned_to'
606 606 assert_response :success
607 607 assignees = assigns(:issues).collect(&:assigned_to).compact
608 608 assert_equal assignees.sort, assignees
609 609 end
610 610
611 611 def test_index_sort_by_assigned_to_desc
612 612 get :index, :sort => 'assigned_to:desc'
613 613 assert_response :success
614 614 assignees = assigns(:issues).collect(&:assigned_to).compact
615 615 assert_equal assignees.sort.reverse, assignees
616 616 end
617 617
618 618 def test_index_group_by_assigned_to
619 619 get :index, :group_by => 'assigned_to', :sort => 'priority'
620 620 assert_response :success
621 621 end
622 622
623 623 def test_index_sort_by_author
624 624 get :index, :sort => 'author'
625 625 assert_response :success
626 626 authors = assigns(:issues).collect(&:author)
627 627 assert_equal authors.sort, authors
628 628 end
629 629
630 630 def test_index_sort_by_author_desc
631 631 get :index, :sort => 'author:desc'
632 632 assert_response :success
633 633 authors = assigns(:issues).collect(&:author)
634 634 assert_equal authors.sort.reverse, authors
635 635 end
636 636
637 637 def test_index_group_by_author
638 638 get :index, :group_by => 'author', :sort => 'priority'
639 639 assert_response :success
640 640 end
641 641
642 642 def test_index_sort_by_spent_hours
643 643 get :index, :sort => 'spent_hours:desc'
644 644 assert_response :success
645 645 hours = assigns(:issues).collect(&:spent_hours)
646 646 assert_equal hours.sort.reverse, hours
647 647 end
648 648
649 649 def test_index_sort_by_user_custom_field
650 650 cf = IssueCustomField.create!(:name => 'User', :is_for_all => true, :tracker_ids => [1,2,3], :field_format => 'user')
651 651 CustomValue.create!(:custom_field => cf, :customized => Issue.find(1), :value => '2')
652 652 CustomValue.create!(:custom_field => cf, :customized => Issue.find(2), :value => '3')
653 653 CustomValue.create!(:custom_field => cf, :customized => Issue.find(3), :value => '3')
654 654 CustomValue.create!(:custom_field => cf, :customized => Issue.find(5), :value => '')
655 655
656 656 get :index, :project_id => 1, :set_filter => 1, :sort => "cf_#{cf.id},id"
657 657 assert_response :success
658 658
659 659 assert_equal [2, 3, 1], assigns(:issues).select {|issue| issue.custom_field_value(cf).present?}.map(&:id)
660 660 end
661 661
662 662 def test_index_with_columns
663 663 columns = ['tracker', 'subject', 'assigned_to']
664 664 get :index, :set_filter => 1, :c => columns
665 665 assert_response :success
666 666
667 667 # query should use specified columns
668 668 query = assigns(:query)
669 669 assert_kind_of Query, query
670 670 assert_equal columns, query.column_names.map(&:to_s)
671 671
672 672 # columns should be stored in session
673 673 assert_kind_of Hash, session[:query]
674 674 assert_kind_of Array, session[:query][:column_names]
675 675 assert_equal columns, session[:query][:column_names].map(&:to_s)
676 676
677 677 # ensure only these columns are kept in the selected columns list
678 678 assert_select 'select#selected_columns option' do
679 679 assert_select 'option', 3
680 680 assert_select 'option[value=tracker]'
681 681 assert_select 'option[value=project]', 0
682 682 end
683 683 end
684 684
685 685 def test_index_without_project_should_implicitly_add_project_column_to_default_columns
686 686 Setting.issue_list_default_columns = ['tracker', 'subject', 'assigned_to']
687 687 get :index, :set_filter => 1
688 688
689 689 # query should use specified columns
690 690 query = assigns(:query)
691 691 assert_kind_of Query, query
692 692 assert_equal [:project, :tracker, :subject, :assigned_to], query.columns.map(&:name)
693 693 end
694 694
695 695 def test_index_without_project_and_explicit_default_columns_should_not_add_project_column
696 696 Setting.issue_list_default_columns = ['tracker', 'subject', 'assigned_to']
697 697 columns = ['tracker', 'subject', 'assigned_to']
698 698 get :index, :set_filter => 1, :c => columns
699 699
700 700 # query should use specified columns
701 701 query = assigns(:query)
702 702 assert_kind_of Query, query
703 703 assert_equal columns.map(&:to_sym), query.columns.map(&:name)
704 704 end
705 705
706 706 def test_index_with_custom_field_column
707 707 columns = %w(tracker subject cf_2)
708 708 get :index, :set_filter => 1, :c => columns
709 709 assert_response :success
710 710
711 711 # query should use specified columns
712 712 query = assigns(:query)
713 713 assert_kind_of Query, query
714 714 assert_equal columns, query.column_names.map(&:to_s)
715 715
716 716 assert_select 'table.issues td.cf_2.string'
717 717 end
718 718
719 719 def test_index_with_multi_custom_field_column
720 720 field = CustomField.find(1)
721 721 field.update_attribute :multiple, true
722 722 issue = Issue.find(1)
723 723 issue.custom_field_values = {1 => ['MySQL', 'Oracle']}
724 724 issue.save!
725 725
726 726 get :index, :set_filter => 1, :c => %w(tracker subject cf_1)
727 727 assert_response :success
728 728
729 729 assert_select 'table.issues td.cf_1', :text => 'MySQL, Oracle'
730 730 end
731 731
732 732 def test_index_with_multi_user_custom_field_column
733 733 field = IssueCustomField.create!(:name => 'Multi user', :field_format => 'user', :multiple => true,
734 734 :tracker_ids => [1], :is_for_all => true)
735 735 issue = Issue.find(1)
736 736 issue.custom_field_values = {field.id => ['2', '3']}
737 737 issue.save!
738 738
739 739 get :index, :set_filter => 1, :c => ['tracker', 'subject', "cf_#{field.id}"]
740 740 assert_response :success
741 741
742 742 assert_select "table.issues td.cf_#{field.id}" do
743 743 assert_select 'a', 2
744 744 assert_select 'a[href=?]', '/users/2', :text => 'John Smith'
745 745 assert_select 'a[href=?]', '/users/3', :text => 'Dave Lopper'
746 746 end
747 747 end
748 748
749 749 def test_index_with_date_column
750 750 with_settings :date_format => '%d/%m/%Y' do
751 751 Issue.find(1).update_attribute :start_date, '1987-08-24'
752 752
753 753 get :index, :set_filter => 1, :c => %w(start_date)
754 754
755 755 assert_select "table.issues td.start_date", :text => '24/08/1987'
756 756 end
757 757 end
758 758
759 759 def test_index_with_done_ratio_column
760 760 Issue.find(1).update_attribute :done_ratio, 40
761 761
762 762 get :index, :set_filter => 1, :c => %w(done_ratio)
763 763
764 764 assert_select 'table.issues td.done_ratio' do
765 765 assert_select 'table.progress' do
766 766 assert_select 'td.closed[style=?]', 'width: 40%;'
767 767 end
768 768 end
769 769 end
770 770
771 771 def test_index_with_spent_hours_column
772 772 get :index, :set_filter => 1, :c => %w(subject spent_hours)
773 773
774 774 assert_select 'table.issues tr#issue-3 td.spent_hours', :text => '1.00'
775 775 end
776 776
777 777 def test_index_should_not_show_spent_hours_column_without_permission
778 778 Role.anonymous.remove_permission! :view_time_entries
779 779 get :index, :set_filter => 1, :c => %w(subject spent_hours)
780 780
781 781 assert_select 'td.spent_hours', 0
782 782 end
783 783
784 784 def test_index_with_fixed_version_column
785 785 get :index, :set_filter => 1, :c => %w(fixed_version)
786 786
787 787 assert_select 'table.issues td.fixed_version' do
788 788 assert_select 'a[href=?]', '/versions/2', :text => '1.0'
789 789 end
790 790 end
791 791
792 792 def test_index_with_relations_column
793 793 IssueRelation.delete_all
794 794 IssueRelation.create!(:relation_type => "relates", :issue_from => Issue.find(1), :issue_to => Issue.find(7))
795 795 IssueRelation.create!(:relation_type => "relates", :issue_from => Issue.find(8), :issue_to => Issue.find(1))
796 796 IssueRelation.create!(:relation_type => "blocks", :issue_from => Issue.find(1), :issue_to => Issue.find(11))
797 797 IssueRelation.create!(:relation_type => "blocks", :issue_from => Issue.find(12), :issue_to => Issue.find(2))
798 798
799 799 get :index, :set_filter => 1, :c => %w(subject relations)
800 800 assert_response :success
801 801 assert_select "tr#issue-1 td.relations" do
802 802 assert_select "span", 3
803 803 assert_select "span", :text => "Related to #7"
804 804 assert_select "span", :text => "Related to #8"
805 805 assert_select "span", :text => "Blocks #11"
806 806 end
807 807 assert_select "tr#issue-2 td.relations" do
808 808 assert_select "span", 1
809 809 assert_select "span", :text => "Blocked by #12"
810 810 end
811 811 assert_select "tr#issue-3 td.relations" do
812 812 assert_select "span", 0
813 813 end
814 814
815 815 get :index, :set_filter => 1, :c => %w(relations), :format => 'csv'
816 816 assert_response :success
817 817 assert_equal 'text/csv; header=present', response.content_type
818 818 lines = response.body.chomp.split("\n")
819 819 assert_include '1,"Related to #7, Related to #8, Blocks #11"', lines
820 820 assert_include '2,Blocked by #12', lines
821 821 assert_include '3,""', lines
822 822
823 823 get :index, :set_filter => 1, :c => %w(subject relations), :format => 'pdf'
824 824 assert_response :success
825 825 assert_equal 'application/pdf', response.content_type
826 826 end
827 827
828 828 def test_index_send_html_if_query_is_invalid
829 829 get :index, :f => ['start_date'], :op => {:start_date => '='}
830 830 assert_equal 'text/html', @response.content_type
831 831 assert_template 'index'
832 832 end
833 833
834 834 def test_index_send_nothing_if_query_is_invalid
835 835 get :index, :f => ['start_date'], :op => {:start_date => '='}, :format => 'csv'
836 836 assert_equal 'text/csv', @response.content_type
837 837 assert @response.body.blank?
838 838 end
839 839
840 840 def test_show_by_anonymous
841 841 get :show, :id => 1
842 842 assert_response :success
843 843 assert_template 'show'
844 844 assert_equal Issue.find(1), assigns(:issue)
845 845
846 846 assert_select 'div.issue div.description', :text => /Unable to print recipes/
847 847
848 848 # anonymous role is allowed to add a note
849 849 assert_select 'form#issue-form' do
850 850 assert_select 'fieldset' do
851 851 assert_select 'legend', :text => 'Notes'
852 852 assert_select 'textarea[name=?]', 'issue[notes]'
853 853 end
854 854 end
855 855
856 856 assert_select 'title', :text => "Bug #1: Can&#x27;t print recipes - eCookbook - Redmine"
857 857 end
858 858
859 859 def test_show_by_manager
860 860 @request.session[:user_id] = 2
861 861 get :show, :id => 1
862 862 assert_response :success
863 863
864 864 assert_select 'a', :text => /Quote/
865 865
866 866 assert_select 'form#issue-form' do
867 867 assert_select 'fieldset' do
868 868 assert_select 'legend', :text => 'Change properties'
869 869 assert_select 'input[name=?]', 'issue[subject]'
870 870 end
871 871 assert_select 'fieldset' do
872 872 assert_select 'legend', :text => 'Log time'
873 873 assert_select 'input[name=?]', 'time_entry[hours]'
874 874 end
875 875 assert_select 'fieldset' do
876 876 assert_select 'legend', :text => 'Notes'
877 877 assert_select 'textarea[name=?]', 'issue[notes]'
878 878 end
879 879 end
880 880 end
881 881
882 882 def test_show_should_display_update_form
883 883 @request.session[:user_id] = 2
884 884 get :show, :id => 1
885 885 assert_response :success
886 886
887 887 assert_tag 'form', :attributes => {:id => 'issue-form'}
888 888 assert_tag 'input', :attributes => {:name => 'issue[is_private]'}
889 889 assert_tag 'select', :attributes => {:name => 'issue[project_id]'}
890 890 assert_tag 'select', :attributes => {:name => 'issue[tracker_id]'}
891 891 assert_tag 'input', :attributes => {:name => 'issue[subject]'}
892 892 assert_tag 'textarea', :attributes => {:name => 'issue[description]'}
893 893 assert_tag 'select', :attributes => {:name => 'issue[status_id]'}
894 894 assert_tag 'select', :attributes => {:name => 'issue[priority_id]'}
895 895 assert_tag 'select', :attributes => {:name => 'issue[assigned_to_id]'}
896 896 assert_tag 'select', :attributes => {:name => 'issue[category_id]'}
897 897 assert_tag 'select', :attributes => {:name => 'issue[fixed_version_id]'}
898 898 assert_tag 'input', :attributes => {:name => 'issue[parent_issue_id]'}
899 899 assert_tag 'input', :attributes => {:name => 'issue[start_date]'}
900 900 assert_tag 'input', :attributes => {:name => 'issue[due_date]'}
901 901 assert_tag 'select', :attributes => {:name => 'issue[done_ratio]'}
902 902 assert_tag 'input', :attributes => { :name => 'issue[custom_field_values][2]' }
903 903 assert_no_tag 'input', :attributes => {:name => 'issue[watcher_user_ids][]'}
904 904 assert_tag 'textarea', :attributes => {:name => 'issue[notes]'}
905 905 end
906 906
907 907 def test_show_should_display_update_form_with_minimal_permissions
908 908 Role.find(1).update_attribute :permissions, [:view_issues, :add_issue_notes]
909 909 WorkflowTransition.delete_all :role_id => 1
910 910
911 911 @request.session[:user_id] = 2
912 912 get :show, :id => 1
913 913 assert_response :success
914 914
915 915 assert_tag 'form', :attributes => {:id => 'issue-form'}
916 916 assert_no_tag 'input', :attributes => {:name => 'issue[is_private]'}
917 917 assert_no_tag 'select', :attributes => {:name => 'issue[project_id]'}
918 918 assert_no_tag 'select', :attributes => {:name => 'issue[tracker_id]'}
919 919 assert_no_tag 'input', :attributes => {:name => 'issue[subject]'}
920 920 assert_no_tag 'textarea', :attributes => {:name => 'issue[description]'}
921 921 assert_no_tag 'select', :attributes => {:name => 'issue[status_id]'}
922 922 assert_no_tag 'select', :attributes => {:name => 'issue[priority_id]'}
923 923 assert_no_tag 'select', :attributes => {:name => 'issue[assigned_to_id]'}
924 924 assert_no_tag 'select', :attributes => {:name => 'issue[category_id]'}
925 925 assert_no_tag 'select', :attributes => {:name => 'issue[fixed_version_id]'}
926 926 assert_no_tag 'input', :attributes => {:name => 'issue[parent_issue_id]'}
927 927 assert_no_tag 'input', :attributes => {:name => 'issue[start_date]'}
928 928 assert_no_tag 'input', :attributes => {:name => 'issue[due_date]'}
929 929 assert_no_tag 'select', :attributes => {:name => 'issue[done_ratio]'}
930 930 assert_no_tag 'input', :attributes => { :name => 'issue[custom_field_values][2]' }
931 931 assert_no_tag 'input', :attributes => {:name => 'issue[watcher_user_ids][]'}
932 932 assert_tag 'textarea', :attributes => {:name => 'issue[notes]'}
933 933 end
934 934
935 935 def test_show_should_display_update_form_with_workflow_permissions
936 936 Role.find(1).update_attribute :permissions, [:view_issues, :add_issue_notes]
937 937
938 938 @request.session[:user_id] = 2
939 939 get :show, :id => 1
940 940 assert_response :success
941 941
942 942 assert_tag 'form', :attributes => {:id => 'issue-form'}
943 943 assert_no_tag 'input', :attributes => {:name => 'issue[is_private]'}
944 944 assert_no_tag 'select', :attributes => {:name => 'issue[project_id]'}
945 945 assert_no_tag 'select', :attributes => {:name => 'issue[tracker_id]'}
946 946 assert_no_tag 'input', :attributes => {:name => 'issue[subject]'}
947 947 assert_no_tag 'textarea', :attributes => {:name => 'issue[description]'}
948 948 assert_tag 'select', :attributes => {:name => 'issue[status_id]'}
949 949 assert_no_tag 'select', :attributes => {:name => 'issue[priority_id]'}
950 950 assert_tag 'select', :attributes => {:name => 'issue[assigned_to_id]'}
951 951 assert_no_tag 'select', :attributes => {:name => 'issue[category_id]'}
952 952 assert_tag 'select', :attributes => {:name => 'issue[fixed_version_id]'}
953 953 assert_no_tag 'input', :attributes => {:name => 'issue[parent_issue_id]'}
954 954 assert_no_tag 'input', :attributes => {:name => 'issue[start_date]'}
955 955 assert_no_tag 'input', :attributes => {:name => 'issue[due_date]'}
956 956 assert_tag 'select', :attributes => {:name => 'issue[done_ratio]'}
957 957 assert_no_tag 'input', :attributes => { :name => 'issue[custom_field_values][2]' }
958 958 assert_no_tag 'input', :attributes => {:name => 'issue[watcher_user_ids][]'}
959 959 assert_tag 'textarea', :attributes => {:name => 'issue[notes]'}
960 960 end
961 961
962 962 def test_show_should_not_display_update_form_without_permissions
963 963 Role.find(1).update_attribute :permissions, [:view_issues]
964 964
965 965 @request.session[:user_id] = 2
966 966 get :show, :id => 1
967 967 assert_response :success
968 968
969 969 assert_select 'form#issue-form', 0
970 970 end
971 971
972 972 def test_update_form_should_not_display_inactive_enumerations
973 973 assert !IssuePriority.find(15).active?
974 974
975 975 @request.session[:user_id] = 2
976 976 get :show, :id => 1
977 977 assert_response :success
978 978
979 979 assert_select 'form#issue-form' do
980 980 assert_select 'select[name=?]', 'issue[priority_id]' do
981 981 assert_select 'option[value=4]'
982 982 assert_select 'option[value=15]', 0
983 983 end
984 984 end
985 985 end
986 986
987 987 def test_update_form_should_allow_attachment_upload
988 988 @request.session[:user_id] = 2
989 989 get :show, :id => 1
990 990
991 991 assert_select 'form#issue-form[method=post][enctype=multipart/form-data]' do
992 992 assert_select 'input[type=file][name=?]', 'attachments[1][file]'
993 993 end
994 994 end
995 995
996 996 def test_show_should_deny_anonymous_access_without_permission
997 997 Role.anonymous.remove_permission!(:view_issues)
998 998 get :show, :id => 1
999 999 assert_response :redirect
1000 1000 end
1001 1001
1002 1002 def test_show_should_deny_anonymous_access_to_private_issue
1003 1003 Issue.update_all(["is_private = ?", true], "id = 1")
1004 1004 get :show, :id => 1
1005 1005 assert_response :redirect
1006 1006 end
1007 1007
1008 1008 def test_show_should_deny_non_member_access_without_permission
1009 1009 Role.non_member.remove_permission!(:view_issues)
1010 1010 @request.session[:user_id] = 9
1011 1011 get :show, :id => 1
1012 1012 assert_response 403
1013 1013 end
1014 1014
1015 1015 def test_show_should_deny_non_member_access_to_private_issue
1016 1016 Issue.update_all(["is_private = ?", true], "id = 1")
1017 1017 @request.session[:user_id] = 9
1018 1018 get :show, :id => 1
1019 1019 assert_response 403
1020 1020 end
1021 1021
1022 1022 def test_show_should_deny_member_access_without_permission
1023 1023 Role.find(1).remove_permission!(:view_issues)
1024 1024 @request.session[:user_id] = 2
1025 1025 get :show, :id => 1
1026 1026 assert_response 403
1027 1027 end
1028 1028
1029 1029 def test_show_should_deny_member_access_to_private_issue_without_permission
1030 1030 Issue.update_all(["is_private = ?", true], "id = 1")
1031 1031 @request.session[:user_id] = 3
1032 1032 get :show, :id => 1
1033 1033 assert_response 403
1034 1034 end
1035 1035
1036 1036 def test_show_should_allow_author_access_to_private_issue
1037 1037 Issue.update_all(["is_private = ?, author_id = 3", true], "id = 1")
1038 1038 @request.session[:user_id] = 3
1039 1039 get :show, :id => 1
1040 1040 assert_response :success
1041 1041 end
1042 1042
1043 1043 def test_show_should_allow_assignee_access_to_private_issue
1044 1044 Issue.update_all(["is_private = ?, assigned_to_id = 3", true], "id = 1")
1045 1045 @request.session[:user_id] = 3
1046 1046 get :show, :id => 1
1047 1047 assert_response :success
1048 1048 end
1049 1049
1050 1050 def test_show_should_allow_member_access_to_private_issue_with_permission
1051 1051 Issue.update_all(["is_private = ?", true], "id = 1")
1052 1052 User.find(3).roles_for_project(Project.find(1)).first.update_attribute :issues_visibility, 'all'
1053 1053 @request.session[:user_id] = 3
1054 1054 get :show, :id => 1
1055 1055 assert_response :success
1056 1056 end
1057 1057
1058 1058 def test_show_should_not_disclose_relations_to_invisible_issues
1059 1059 Setting.cross_project_issue_relations = '1'
1060 1060 IssueRelation.create!(:issue_from => Issue.find(1), :issue_to => Issue.find(2), :relation_type => 'relates')
1061 1061 # Relation to a private project issue
1062 1062 IssueRelation.create!(:issue_from => Issue.find(1), :issue_to => Issue.find(4), :relation_type => 'relates')
1063 1063
1064 1064 get :show, :id => 1
1065 1065 assert_response :success
1066 1066
1067 1067 assert_select 'div#relations' do
1068 1068 assert_select 'a', :text => /#2$/
1069 1069 assert_select 'a', :text => /#4$/, :count => 0
1070 1070 end
1071 1071 end
1072 1072
1073 1073 def test_show_should_list_subtasks
1074 1074 Issue.create!(:project_id => 1, :author_id => 1, :tracker_id => 1, :parent_issue_id => 1, :subject => 'Child Issue')
1075 1075
1076 1076 get :show, :id => 1
1077 1077 assert_response :success
1078 1078
1079 1079 assert_select 'div#issue_tree' do
1080 1080 assert_select 'td.subject', :text => /Child Issue/
1081 1081 end
1082 1082 end
1083 1083
1084 1084 def test_show_should_list_parents
1085 1085 issue = Issue.create!(:project_id => 1, :author_id => 1, :tracker_id => 1, :parent_issue_id => 1, :subject => 'Child Issue')
1086 1086
1087 1087 get :show, :id => issue.id
1088 1088 assert_response :success
1089 1089
1090 1090 assert_select 'div.subject' do
1091 1091 assert_select 'h3', 'Child Issue'
1092 1092 assert_select 'a[href=/issues/1]'
1093 1093 end
1094 1094 end
1095 1095
1096 1096 def test_show_should_not_display_prev_next_links_without_query_in_session
1097 1097 get :show, :id => 1
1098 1098 assert_response :success
1099 1099 assert_nil assigns(:prev_issue_id)
1100 1100 assert_nil assigns(:next_issue_id)
1101 1101
1102 1102 assert_select 'div.next-prev-links', 0
1103 1103 end
1104 1104
1105 1105 def test_show_should_display_prev_next_links_with_query_in_session
1106 1106 @request.session[:query] = {:filters => {'status_id' => {:values => [''], :operator => 'o'}}, :project_id => nil}
1107 1107 @request.session['issues_index_sort'] = 'id'
1108 1108
1109 1109 with_settings :display_subprojects_issues => '0' do
1110 1110 get :show, :id => 3
1111 1111 end
1112 1112
1113 1113 assert_response :success
1114 1114 # Previous and next issues for all projects
1115 1115 assert_equal 2, assigns(:prev_issue_id)
1116 1116 assert_equal 5, assigns(:next_issue_id)
1117 1117
1118 1118 count = Issue.open.visible.count
1119 1119
1120 1120 assert_select 'div.next-prev-links' do
1121 1121 assert_select 'a[href=/issues/2]', :text => /Previous/
1122 1122 assert_select 'a[href=/issues/5]', :text => /Next/
1123 1123 assert_select 'span.position', :text => "3 of #{count}"
1124 1124 end
1125 1125 end
1126 1126
1127 1127 def test_show_should_display_prev_next_links_with_saved_query_in_session
1128 1128 query = Query.create!(:name => 'test', :is_public => true, :user_id => 1,
1129 1129 :filters => {'status_id' => {:values => ['5'], :operator => '='}},
1130 1130 :sort_criteria => [['id', 'asc']])
1131 1131 @request.session[:query] = {:id => query.id, :project_id => nil}
1132 1132
1133 1133 get :show, :id => 11
1134 1134
1135 1135 assert_response :success
1136 1136 assert_equal query, assigns(:query)
1137 1137 # Previous and next issues for all projects
1138 1138 assert_equal 8, assigns(:prev_issue_id)
1139 1139 assert_equal 12, assigns(:next_issue_id)
1140 1140
1141 1141 assert_select 'div.next-prev-links' do
1142 1142 assert_select 'a[href=/issues/8]', :text => /Previous/
1143 1143 assert_select 'a[href=/issues/12]', :text => /Next/
1144 1144 end
1145 1145 end
1146 1146
1147 1147 def test_show_should_display_prev_next_links_with_query_and_sort_on_association
1148 1148 @request.session[:query] = {:filters => {'status_id' => {:values => [''], :operator => 'o'}}, :project_id => nil}
1149 1149
1150 1150 %w(project tracker status priority author assigned_to category fixed_version).each do |assoc_sort|
1151 1151 @request.session['issues_index_sort'] = assoc_sort
1152 1152
1153 1153 get :show, :id => 3
1154 1154 assert_response :success, "Wrong response status for #{assoc_sort} sort"
1155 1155
1156 1156 assert_select 'div.next-prev-links' do
1157 1157 assert_select 'a', :text => /(Previous|Next)/
1158 1158 end
1159 1159 end
1160 1160 end
1161 1161
1162 1162 def test_show_should_display_prev_next_links_with_project_query_in_session
1163 1163 @request.session[:query] = {:filters => {'status_id' => {:values => [''], :operator => 'o'}}, :project_id => 1}
1164 1164 @request.session['issues_index_sort'] = 'id'
1165 1165
1166 1166 with_settings :display_subprojects_issues => '0' do
1167 1167 get :show, :id => 3
1168 1168 end
1169 1169
1170 1170 assert_response :success
1171 1171 # Previous and next issues inside project
1172 1172 assert_equal 2, assigns(:prev_issue_id)
1173 1173 assert_equal 7, assigns(:next_issue_id)
1174 1174
1175 1175 assert_select 'div.next-prev-links' do
1176 1176 assert_select 'a[href=/issues/2]', :text => /Previous/
1177 1177 assert_select 'a[href=/issues/7]', :text => /Next/
1178 1178 end
1179 1179 end
1180 1180
1181 1181 def test_show_should_not_display_prev_link_for_first_issue
1182 1182 @request.session[:query] = {:filters => {'status_id' => {:values => [''], :operator => 'o'}}, :project_id => 1}
1183 1183 @request.session['issues_index_sort'] = 'id'
1184 1184
1185 1185 with_settings :display_subprojects_issues => '0' do
1186 1186 get :show, :id => 1
1187 1187 end
1188 1188
1189 1189 assert_response :success
1190 1190 assert_nil assigns(:prev_issue_id)
1191 1191 assert_equal 2, assigns(:next_issue_id)
1192 1192
1193 1193 assert_select 'div.next-prev-links' do
1194 1194 assert_select 'a', :text => /Previous/, :count => 0
1195 1195 assert_select 'a[href=/issues/2]', :text => /Next/
1196 1196 end
1197 1197 end
1198 1198
1199 1199 def test_show_should_not_display_prev_next_links_for_issue_not_in_query_results
1200 1200 @request.session[:query] = {:filters => {'status_id' => {:values => [''], :operator => 'c'}}, :project_id => 1}
1201 1201 @request.session['issues_index_sort'] = 'id'
1202 1202
1203 1203 get :show, :id => 1
1204 1204
1205 1205 assert_response :success
1206 1206 assert_nil assigns(:prev_issue_id)
1207 1207 assert_nil assigns(:next_issue_id)
1208 1208
1209 1209 assert_select 'a', :text => /Previous/, :count => 0
1210 1210 assert_select 'a', :text => /Next/, :count => 0
1211 1211 end
1212 1212
1213 1213 def test_show_show_should_display_prev_next_links_with_query_sort_by_user_custom_field
1214 1214 cf = IssueCustomField.create!(:name => 'User', :is_for_all => true, :tracker_ids => [1,2,3], :field_format => 'user')
1215 1215 CustomValue.create!(:custom_field => cf, :customized => Issue.find(1), :value => '2')
1216 1216 CustomValue.create!(:custom_field => cf, :customized => Issue.find(2), :value => '3')
1217 1217 CustomValue.create!(:custom_field => cf, :customized => Issue.find(3), :value => '3')
1218 1218 CustomValue.create!(:custom_field => cf, :customized => Issue.find(5), :value => '')
1219 1219
1220 1220 query = Query.create!(:name => 'test', :is_public => true, :user_id => 1, :filters => {},
1221 1221 :sort_criteria => [["cf_#{cf.id}", 'asc'], ['id', 'asc']])
1222 1222 @request.session[:query] = {:id => query.id, :project_id => nil}
1223 1223
1224 1224 get :show, :id => 3
1225 1225 assert_response :success
1226 1226
1227 1227 assert_equal 2, assigns(:prev_issue_id)
1228 1228 assert_equal 1, assigns(:next_issue_id)
1229 1229
1230 1230 assert_select 'div.next-prev-links' do
1231 1231 assert_select 'a[href=/issues/2]', :text => /Previous/
1232 1232 assert_select 'a[href=/issues/1]', :text => /Next/
1233 1233 end
1234 1234 end
1235 1235
1236 1236 def test_show_should_display_link_to_the_assignee
1237 1237 get :show, :id => 2
1238 1238 assert_response :success
1239 1239 assert_select '.assigned-to' do
1240 1240 assert_select 'a[href=/users/3]'
1241 1241 end
1242 1242 end
1243 1243
1244 1244 def test_show_should_display_visible_changesets_from_other_projects
1245 1245 project = Project.find(2)
1246 1246 issue = project.issues.first
1247 1247 issue.changeset_ids = [102]
1248 1248 issue.save!
1249 1249 # changesets from other projects should be displayed even if repository
1250 1250 # is disabled on issue's project
1251 1251 project.disable_module! :repository
1252 1252
1253 1253 @request.session[:user_id] = 2
1254 1254 get :show, :id => issue.id
1255 1255
1256 1256 assert_select 'a[href=?]', '/projects/ecookbook/repository/revisions/3'
1257 1257 end
1258 1258
1259 1259 def test_show_should_display_watchers
1260 1260 @request.session[:user_id] = 2
1261 1261 Issue.find(1).add_watcher User.find(2)
1262 1262
1263 1263 get :show, :id => 1
1264 1264 assert_select 'div#watchers ul' do
1265 1265 assert_select 'li' do
1266 1266 assert_select 'a[href=/users/2]'
1267 1267 assert_select 'a img[alt=Delete]'
1268 1268 end
1269 1269 end
1270 1270 end
1271 1271
1272 1272 def test_show_should_display_watchers_with_gravatars
1273 1273 @request.session[:user_id] = 2
1274 1274 Issue.find(1).add_watcher User.find(2)
1275 1275
1276 1276 with_settings :gravatar_enabled => '1' do
1277 1277 get :show, :id => 1
1278 1278 end
1279 1279
1280 1280 assert_select 'div#watchers ul' do
1281 1281 assert_select 'li' do
1282 1282 assert_select 'img.gravatar'
1283 1283 assert_select 'a[href=/users/2]'
1284 1284 assert_select 'a img[alt=Delete]'
1285 1285 end
1286 1286 end
1287 1287 end
1288 1288
1289 1289 def test_show_with_thumbnails_enabled_should_display_thumbnails
1290 1290 @request.session[:user_id] = 2
1291 1291
1292 1292 with_settings :thumbnails_enabled => '1' do
1293 1293 get :show, :id => 14
1294 1294 assert_response :success
1295 1295 end
1296 1296
1297 1297 assert_select 'div.thumbnails' do
1298 1298 assert_select 'a[href=/attachments/16/testfile.png]' do
1299 1299 assert_select 'img[src=/attachments/thumbnail/16]'
1300 1300 end
1301 1301 end
1302 1302 end
1303 1303
1304 1304 def test_show_with_thumbnails_disabled_should_not_display_thumbnails
1305 1305 @request.session[:user_id] = 2
1306 1306
1307 1307 with_settings :thumbnails_enabled => '0' do
1308 1308 get :show, :id => 14
1309 1309 assert_response :success
1310 1310 end
1311 1311
1312 1312 assert_select 'div.thumbnails', 0
1313 1313 end
1314 1314
1315 1315 def test_show_with_multi_custom_field
1316 1316 field = CustomField.find(1)
1317 1317 field.update_attribute :multiple, true
1318 1318 issue = Issue.find(1)
1319 1319 issue.custom_field_values = {1 => ['MySQL', 'Oracle']}
1320 1320 issue.save!
1321 1321
1322 1322 get :show, :id => 1
1323 1323 assert_response :success
1324 1324
1325 1325 assert_select 'td', :text => 'MySQL, Oracle'
1326 1326 end
1327 1327
1328 1328 def test_show_with_multi_user_custom_field
1329 1329 field = IssueCustomField.create!(:name => 'Multi user', :field_format => 'user', :multiple => true,
1330 1330 :tracker_ids => [1], :is_for_all => true)
1331 1331 issue = Issue.find(1)
1332 1332 issue.custom_field_values = {field.id => ['2', '3']}
1333 1333 issue.save!
1334 1334
1335 1335 get :show, :id => 1
1336 1336 assert_response :success
1337 1337
1338 1338 # TODO: should display links
1339 1339 assert_select 'td', :text => 'Dave Lopper, John Smith'
1340 1340 end
1341 1341
1342 1342 def test_show_should_display_private_notes_with_permission_only
1343 1343 journal = Journal.create!(:journalized => Issue.find(2), :notes => 'Privates notes', :private_notes => true, :user_id => 1)
1344 1344 @request.session[:user_id] = 2
1345 1345
1346 1346 get :show, :id => 2
1347 1347 assert_response :success
1348 1348 assert_include journal, assigns(:journals)
1349 1349
1350 1350 Role.find(1).remove_permission! :view_private_notes
1351 1351 get :show, :id => 2
1352 1352 assert_response :success
1353 1353 assert_not_include journal, assigns(:journals)
1354 1354 end
1355 1355
1356 1356 def test_show_atom
1357 1357 get :show, :id => 2, :format => 'atom'
1358 1358 assert_response :success
1359 1359 assert_template 'journals/index'
1360 1360 # Inline image
1361 1361 assert_select 'content', :text => Regexp.new(Regexp.quote('http://test.host/attachments/download/10'))
1362 1362 end
1363 1363
1364 1364 def test_show_export_to_pdf
1365 1365 get :show, :id => 3, :format => 'pdf'
1366 1366 assert_response :success
1367 1367 assert_equal 'application/pdf', @response.content_type
1368 1368 assert @response.body.starts_with?('%PDF')
1369 1369 assert_not_nil assigns(:issue)
1370 1370 end
1371 1371
1372 1372 def test_show_export_to_pdf_with_ancestors
1373 1373 issue = Issue.generate!(:project_id => 1, :author_id => 2, :tracker_id => 1, :subject => 'child', :parent_issue_id => 1)
1374 1374
1375 1375 get :show, :id => issue.id, :format => 'pdf'
1376 1376 assert_response :success
1377 1377 assert_equal 'application/pdf', @response.content_type
1378 1378 assert @response.body.starts_with?('%PDF')
1379 1379 end
1380 1380
1381 1381 def test_show_export_to_pdf_with_descendants
1382 1382 c1 = Issue.generate!(:project_id => 1, :author_id => 2, :tracker_id => 1, :subject => 'child', :parent_issue_id => 1)
1383 1383 c2 = Issue.generate!(:project_id => 1, :author_id => 2, :tracker_id => 1, :subject => 'child', :parent_issue_id => 1)
1384 1384 c3 = Issue.generate!(:project_id => 1, :author_id => 2, :tracker_id => 1, :subject => 'child', :parent_issue_id => c1.id)
1385 1385
1386 1386 get :show, :id => 1, :format => 'pdf'
1387 1387 assert_response :success
1388 1388 assert_equal 'application/pdf', @response.content_type
1389 1389 assert @response.body.starts_with?('%PDF')
1390 1390 end
1391 1391
1392 1392 def test_show_export_to_pdf_with_journals
1393 1393 get :show, :id => 1, :format => 'pdf'
1394 1394 assert_response :success
1395 1395 assert_equal 'application/pdf', @response.content_type
1396 1396 assert @response.body.starts_with?('%PDF')
1397 1397 end
1398 1398
1399 1399 def test_show_export_to_pdf_with_changesets
1400 1400 Issue.find(3).changesets = Changeset.find_all_by_id(100, 101, 102)
1401 1401
1402 1402 get :show, :id => 3, :format => 'pdf'
1403 1403 assert_response :success
1404 1404 assert_equal 'application/pdf', @response.content_type
1405 1405 assert @response.body.starts_with?('%PDF')
1406 1406 end
1407 1407
1408 def test_show_invalid_should_respond_with_404
1409 get :show, :id => 999
1410 assert_response 404
1411 end
1412
1408 1413 def test_get_new
1409 1414 @request.session[:user_id] = 2
1410 1415 get :new, :project_id => 1, :tracker_id => 1
1411 1416 assert_response :success
1412 1417 assert_template 'new'
1413 1418
1414 1419 assert_tag 'input', :attributes => {:name => 'issue[is_private]'}
1415 1420 assert_no_tag 'select', :attributes => {:name => 'issue[project_id]'}
1416 1421 assert_tag 'select', :attributes => {:name => 'issue[tracker_id]'}
1417 1422 assert_tag 'input', :attributes => {:name => 'issue[subject]'}
1418 1423 assert_tag 'textarea', :attributes => {:name => 'issue[description]'}
1419 1424 assert_tag 'select', :attributes => {:name => 'issue[status_id]'}
1420 1425 assert_tag 'select', :attributes => {:name => 'issue[priority_id]'}
1421 1426 assert_tag 'select', :attributes => {:name => 'issue[assigned_to_id]'}
1422 1427 assert_tag 'select', :attributes => {:name => 'issue[category_id]'}
1423 1428 assert_tag 'select', :attributes => {:name => 'issue[fixed_version_id]'}
1424 1429 assert_tag 'input', :attributes => {:name => 'issue[parent_issue_id]'}
1425 1430 assert_tag 'input', :attributes => {:name => 'issue[start_date]'}
1426 1431 assert_tag 'input', :attributes => {:name => 'issue[due_date]'}
1427 1432 assert_tag 'select', :attributes => {:name => 'issue[done_ratio]'}
1428 1433 assert_tag 'input', :attributes => { :name => 'issue[custom_field_values][2]', :value => 'Default string' }
1429 1434 assert_tag 'input', :attributes => {:name => 'issue[watcher_user_ids][]'}
1430 1435
1431 1436 # Be sure we don't display inactive IssuePriorities
1432 1437 assert ! IssuePriority.find(15).active?
1433 1438 assert_no_tag :option, :attributes => {:value => '15'},
1434 1439 :parent => {:tag => 'select', :attributes => {:id => 'issue_priority_id'} }
1435 1440 end
1436 1441
1437 1442 def test_get_new_with_minimal_permissions
1438 1443 Role.find(1).update_attribute :permissions, [:add_issues]
1439 1444 WorkflowTransition.delete_all :role_id => 1
1440 1445
1441 1446 @request.session[:user_id] = 2
1442 1447 get :new, :project_id => 1, :tracker_id => 1
1443 1448 assert_response :success
1444 1449 assert_template 'new'
1445 1450
1446 1451 assert_no_tag 'input', :attributes => {:name => 'issue[is_private]'}
1447 1452 assert_no_tag 'select', :attributes => {:name => 'issue[project_id]'}
1448 1453 assert_tag 'select', :attributes => {:name => 'issue[tracker_id]'}
1449 1454 assert_tag 'input', :attributes => {:name => 'issue[subject]'}
1450 1455 assert_tag 'textarea', :attributes => {:name => 'issue[description]'}
1451 1456 assert_tag 'select', :attributes => {:name => 'issue[status_id]'}
1452 1457 assert_tag 'select', :attributes => {:name => 'issue[priority_id]'}
1453 1458 assert_tag 'select', :attributes => {:name => 'issue[assigned_to_id]'}
1454 1459 assert_tag 'select', :attributes => {:name => 'issue[category_id]'}
1455 1460 assert_tag 'select', :attributes => {:name => 'issue[fixed_version_id]'}
1456 1461 assert_no_tag 'input', :attributes => {:name => 'issue[parent_issue_id]'}
1457 1462 assert_tag 'input', :attributes => {:name => 'issue[start_date]'}
1458 1463 assert_tag 'input', :attributes => {:name => 'issue[due_date]'}
1459 1464 assert_tag 'select', :attributes => {:name => 'issue[done_ratio]'}
1460 1465 assert_tag 'input', :attributes => { :name => 'issue[custom_field_values][2]', :value => 'Default string' }
1461 1466 assert_no_tag 'input', :attributes => {:name => 'issue[watcher_user_ids][]'}
1462 1467 end
1463 1468
1464 1469 def test_get_new_with_list_custom_field
1465 1470 @request.session[:user_id] = 2
1466 1471 get :new, :project_id => 1, :tracker_id => 1
1467 1472 assert_response :success
1468 1473 assert_template 'new'
1469 1474
1470 1475 assert_select 'select.list_cf[name=?]', 'issue[custom_field_values][1]' do
1471 1476 assert_select 'option', 4
1472 1477 assert_select 'option[value=MySQL]', :text => 'MySQL'
1473 1478 end
1474 1479 end
1475 1480
1476 1481 def test_get_new_with_multi_custom_field
1477 1482 field = IssueCustomField.find(1)
1478 1483 field.update_attribute :multiple, true
1479 1484
1480 1485 @request.session[:user_id] = 2
1481 1486 get :new, :project_id => 1, :tracker_id => 1
1482 1487 assert_response :success
1483 1488 assert_template 'new'
1484 1489
1485 1490 assert_select 'select[name=?][multiple=multiple]', 'issue[custom_field_values][1][]' do
1486 1491 assert_select 'option', 3
1487 1492 assert_select 'option[value=MySQL]', :text => 'MySQL'
1488 1493 end
1489 1494 assert_select 'input[name=?][type=hidden][value=?]', 'issue[custom_field_values][1][]', ''
1490 1495 end
1491 1496
1492 1497 def test_get_new_with_multi_user_custom_field
1493 1498 field = IssueCustomField.create!(:name => 'Multi user', :field_format => 'user', :multiple => true,
1494 1499 :tracker_ids => [1], :is_for_all => true)
1495 1500
1496 1501 @request.session[:user_id] = 2
1497 1502 get :new, :project_id => 1, :tracker_id => 1
1498 1503 assert_response :success
1499 1504 assert_template 'new'
1500 1505
1501 1506 assert_select 'select[name=?][multiple=multiple]', "issue[custom_field_values][#{field.id}][]" do
1502 1507 assert_select 'option', Project.find(1).users.count
1503 1508 assert_select 'option[value=2]', :text => 'John Smith'
1504 1509 end
1505 1510 assert_select 'input[name=?][type=hidden][value=?]', "issue[custom_field_values][#{field.id}][]", ''
1506 1511 end
1507 1512
1508 1513 def test_get_new_with_date_custom_field
1509 1514 field = IssueCustomField.create!(:name => 'Date', :field_format => 'date', :tracker_ids => [1], :is_for_all => true)
1510 1515
1511 1516 @request.session[:user_id] = 2
1512 1517 get :new, :project_id => 1, :tracker_id => 1
1513 1518 assert_response :success
1514 1519
1515 1520 assert_select 'input[name=?]', "issue[custom_field_values][#{field.id}]"
1516 1521 end
1517 1522
1518 1523 def test_get_new_with_text_custom_field
1519 1524 field = IssueCustomField.create!(:name => 'Text', :field_format => 'text', :tracker_ids => [1], :is_for_all => true)
1520 1525
1521 1526 @request.session[:user_id] = 2
1522 1527 get :new, :project_id => 1, :tracker_id => 1
1523 1528 assert_response :success
1524 1529
1525 1530 assert_select 'textarea[name=?]', "issue[custom_field_values][#{field.id}]"
1526 1531 end
1527 1532
1528 1533 def test_get_new_without_default_start_date_is_creation_date
1529 1534 Setting.default_issue_start_date_to_creation_date = 0
1530 1535
1531 1536 @request.session[:user_id] = 2
1532 1537 get :new, :project_id => 1, :tracker_id => 1
1533 1538 assert_response :success
1534 1539 assert_template 'new'
1535 1540
1536 1541 assert_select 'input[name=?]', 'issue[start_date]'
1537 1542 assert_select 'input[name=?][value]', 'issue[start_date]', 0
1538 1543 end
1539 1544
1540 1545 def test_get_new_with_default_start_date_is_creation_date
1541 1546 Setting.default_issue_start_date_to_creation_date = 1
1542 1547
1543 1548 @request.session[:user_id] = 2
1544 1549 get :new, :project_id => 1, :tracker_id => 1
1545 1550 assert_response :success
1546 1551 assert_template 'new'
1547 1552
1548 1553 assert_select 'input[name=?][value=?]', 'issue[start_date]', Date.today.to_s
1549 1554 end
1550 1555
1551 1556 def test_get_new_form_should_allow_attachment_upload
1552 1557 @request.session[:user_id] = 2
1553 1558 get :new, :project_id => 1, :tracker_id => 1
1554 1559
1555 1560 assert_select 'form[id=issue-form][method=post][enctype=multipart/form-data]' do
1556 1561 assert_select 'input[name=?][type=file]', 'attachments[1][file]'
1557 1562 assert_select 'input[name=?][maxlength=255]', 'attachments[1][description]'
1558 1563 end
1559 1564 end
1560 1565
1561 1566 def test_get_new_should_prefill_the_form_from_params
1562 1567 @request.session[:user_id] = 2
1563 1568 get :new, :project_id => 1,
1564 1569 :issue => {:tracker_id => 3, :description => 'Prefilled', :custom_field_values => {'2' => 'Custom field value'}}
1565 1570
1566 1571 issue = assigns(:issue)
1567 1572 assert_equal 3, issue.tracker_id
1568 1573 assert_equal 'Prefilled', issue.description
1569 1574 assert_equal 'Custom field value', issue.custom_field_value(2)
1570 1575
1571 1576 assert_select 'select[name=?]', 'issue[tracker_id]' do
1572 1577 assert_select 'option[value=3][selected=selected]'
1573 1578 end
1574 1579 assert_select 'textarea[name=?]', 'issue[description]', :text => /Prefilled/
1575 1580 assert_select 'input[name=?][value=?]', 'issue[custom_field_values][2]', 'Custom field value'
1576 1581 end
1577 1582
1578 1583 def test_get_new_should_mark_required_fields
1579 1584 cf1 = IssueCustomField.create!(:name => 'Foo', :field_format => 'string', :is_for_all => true, :tracker_ids => [1, 2])
1580 1585 cf2 = IssueCustomField.create!(:name => 'Bar', :field_format => 'string', :is_for_all => true, :tracker_ids => [1, 2])
1581 1586 WorkflowPermission.delete_all
1582 1587 WorkflowPermission.create!(:old_status_id => 1, :tracker_id => 1, :role_id => 1, :field_name => 'due_date', :rule => 'required')
1583 1588 WorkflowPermission.create!(:old_status_id => 1, :tracker_id => 1, :role_id => 1, :field_name => cf2.id.to_s, :rule => 'required')
1584 1589 @request.session[:user_id] = 2
1585 1590
1586 1591 get :new, :project_id => 1
1587 1592 assert_response :success
1588 1593 assert_template 'new'
1589 1594
1590 1595 assert_select 'label[for=issue_start_date]' do
1591 1596 assert_select 'span[class=required]', 0
1592 1597 end
1593 1598 assert_select 'label[for=issue_due_date]' do
1594 1599 assert_select 'span[class=required]'
1595 1600 end
1596 1601 assert_select 'label[for=?]', "issue_custom_field_values_#{cf1.id}" do
1597 1602 assert_select 'span[class=required]', 0
1598 1603 end
1599 1604 assert_select 'label[for=?]', "issue_custom_field_values_#{cf2.id}" do
1600 1605 assert_select 'span[class=required]'
1601 1606 end
1602 1607 end
1603 1608
1604 1609 def test_get_new_should_not_display_readonly_fields
1605 1610 cf1 = IssueCustomField.create!(:name => 'Foo', :field_format => 'string', :is_for_all => true, :tracker_ids => [1, 2])
1606 1611 cf2 = IssueCustomField.create!(:name => 'Bar', :field_format => 'string', :is_for_all => true, :tracker_ids => [1, 2])
1607 1612 WorkflowPermission.delete_all
1608 1613 WorkflowPermission.create!(:old_status_id => 1, :tracker_id => 1, :role_id => 1, :field_name => 'due_date', :rule => 'readonly')
1609 1614 WorkflowPermission.create!(:old_status_id => 1, :tracker_id => 1, :role_id => 1, :field_name => cf2.id.to_s, :rule => 'readonly')
1610 1615 @request.session[:user_id] = 2
1611 1616
1612 1617 get :new, :project_id => 1
1613 1618 assert_response :success
1614 1619 assert_template 'new'
1615 1620
1616 1621 assert_select 'input[name=?]', 'issue[start_date]'
1617 1622 assert_select 'input[name=?]', 'issue[due_date]', 0
1618 1623 assert_select 'input[name=?]', "issue[custom_field_values][#{cf1.id}]"
1619 1624 assert_select 'input[name=?]', "issue[custom_field_values][#{cf2.id}]", 0
1620 1625 end
1621 1626
1622 1627 def test_get_new_without_tracker_id
1623 1628 @request.session[:user_id] = 2
1624 1629 get :new, :project_id => 1
1625 1630 assert_response :success
1626 1631 assert_template 'new'
1627 1632
1628 1633 issue = assigns(:issue)
1629 1634 assert_not_nil issue
1630 1635 assert_equal Project.find(1).trackers.first, issue.tracker
1631 1636 end
1632 1637
1633 1638 def test_get_new_with_no_default_status_should_display_an_error
1634 1639 @request.session[:user_id] = 2
1635 1640 IssueStatus.delete_all
1636 1641
1637 1642 get :new, :project_id => 1
1638 1643 assert_response 500
1639 1644 assert_error_tag :content => /No default issue/
1640 1645 end
1641 1646
1642 1647 def test_get_new_with_no_tracker_should_display_an_error
1643 1648 @request.session[:user_id] = 2
1644 1649 Tracker.delete_all
1645 1650
1646 1651 get :new, :project_id => 1
1647 1652 assert_response 500
1648 1653 assert_error_tag :content => /No tracker/
1649 1654 end
1650 1655
1651 1656 def test_update_new_form
1652 1657 @request.session[:user_id] = 2
1653 1658 xhr :post, :new, :project_id => 1,
1654 1659 :issue => {:tracker_id => 2,
1655 1660 :subject => 'This is the test_new issue',
1656 1661 :description => 'This is the description',
1657 1662 :priority_id => 5}
1658 1663 assert_response :success
1659 1664 assert_template 'update_form'
1660 1665 assert_template 'form'
1661 1666 assert_equal 'text/javascript', response.content_type
1662 1667
1663 1668 issue = assigns(:issue)
1664 1669 assert_kind_of Issue, issue
1665 1670 assert_equal 1, issue.project_id
1666 1671 assert_equal 2, issue.tracker_id
1667 1672 assert_equal 'This is the test_new issue', issue.subject
1668 1673 end
1669 1674
1670 1675 def test_update_new_form_should_propose_transitions_based_on_initial_status
1671 1676 @request.session[:user_id] = 2
1672 1677 WorkflowTransition.delete_all
1673 1678 WorkflowTransition.create!(:role_id => 1, :tracker_id => 1, :old_status_id => 1, :new_status_id => 2)
1674 1679 WorkflowTransition.create!(:role_id => 1, :tracker_id => 1, :old_status_id => 1, :new_status_id => 5)
1675 1680 WorkflowTransition.create!(:role_id => 1, :tracker_id => 1, :old_status_id => 5, :new_status_id => 4)
1676 1681
1677 1682 xhr :post, :new, :project_id => 1,
1678 1683 :issue => {:tracker_id => 1,
1679 1684 :status_id => 5,
1680 1685 :subject => 'This is an issue'}
1681 1686
1682 1687 assert_equal 5, assigns(:issue).status_id
1683 1688 assert_equal [1,2,5], assigns(:allowed_statuses).map(&:id).sort
1684 1689 end
1685 1690
1686 1691 def test_post_create
1687 1692 @request.session[:user_id] = 2
1688 1693 assert_difference 'Issue.count' do
1689 1694 post :create, :project_id => 1,
1690 1695 :issue => {:tracker_id => 3,
1691 1696 :status_id => 2,
1692 1697 :subject => 'This is the test_new issue',
1693 1698 :description => 'This is the description',
1694 1699 :priority_id => 5,
1695 1700 :start_date => '2010-11-07',
1696 1701 :estimated_hours => '',
1697 1702 :custom_field_values => {'2' => 'Value for field 2'}}
1698 1703 end
1699 1704 assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id
1700 1705
1701 1706 issue = Issue.find_by_subject('This is the test_new issue')
1702 1707 assert_not_nil issue
1703 1708 assert_equal 2, issue.author_id
1704 1709 assert_equal 3, issue.tracker_id
1705 1710 assert_equal 2, issue.status_id
1706 1711 assert_equal Date.parse('2010-11-07'), issue.start_date
1707 1712 assert_nil issue.estimated_hours
1708 1713 v = issue.custom_values.where(:custom_field_id => 2).first
1709 1714 assert_not_nil v
1710 1715 assert_equal 'Value for field 2', v.value
1711 1716 end
1712 1717
1713 1718 def test_post_new_with_group_assignment
1714 1719 group = Group.find(11)
1715 1720 project = Project.find(1)
1716 1721 project.members << Member.new(:principal => group, :roles => [Role.givable.first])
1717 1722
1718 1723 with_settings :issue_group_assignment => '1' do
1719 1724 @request.session[:user_id] = 2
1720 1725 assert_difference 'Issue.count' do
1721 1726 post :create, :project_id => project.id,
1722 1727 :issue => {:tracker_id => 3,
1723 1728 :status_id => 1,
1724 1729 :subject => 'This is the test_new_with_group_assignment issue',
1725 1730 :assigned_to_id => group.id}
1726 1731 end
1727 1732 end
1728 1733 assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id
1729 1734
1730 1735 issue = Issue.find_by_subject('This is the test_new_with_group_assignment issue')
1731 1736 assert_not_nil issue
1732 1737 assert_equal group, issue.assigned_to
1733 1738 end
1734 1739
1735 1740 def test_post_create_without_start_date_and_default_start_date_is_not_creation_date
1736 1741 Setting.default_issue_start_date_to_creation_date = 0
1737 1742
1738 1743 @request.session[:user_id] = 2
1739 1744 assert_difference 'Issue.count' do
1740 1745 post :create, :project_id => 1,
1741 1746 :issue => {:tracker_id => 3,
1742 1747 :status_id => 2,
1743 1748 :subject => 'This is the test_new issue',
1744 1749 :description => 'This is the description',
1745 1750 :priority_id => 5,
1746 1751 :estimated_hours => '',
1747 1752 :custom_field_values => {'2' => 'Value for field 2'}}
1748 1753 end
1749 1754 assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id
1750 1755
1751 1756 issue = Issue.find_by_subject('This is the test_new issue')
1752 1757 assert_not_nil issue
1753 1758 assert_nil issue.start_date
1754 1759 end
1755 1760
1756 1761 def test_post_create_without_start_date_and_default_start_date_is_creation_date
1757 1762 Setting.default_issue_start_date_to_creation_date = 1
1758 1763
1759 1764 @request.session[:user_id] = 2
1760 1765 assert_difference 'Issue.count' do
1761 1766 post :create, :project_id => 1,
1762 1767 :issue => {:tracker_id => 3,
1763 1768 :status_id => 2,
1764 1769 :subject => 'This is the test_new issue',
1765 1770 :description => 'This is the description',
1766 1771 :priority_id => 5,
1767 1772 :estimated_hours => '',
1768 1773 :custom_field_values => {'2' => 'Value for field 2'}}
1769 1774 end
1770 1775 assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id
1771 1776
1772 1777 issue = Issue.find_by_subject('This is the test_new issue')
1773 1778 assert_not_nil issue
1774 1779 assert_equal Date.today, issue.start_date
1775 1780 end
1776 1781
1777 1782 def test_post_create_and_continue
1778 1783 @request.session[:user_id] = 2
1779 1784 assert_difference 'Issue.count' do
1780 1785 post :create, :project_id => 1,
1781 1786 :issue => {:tracker_id => 3, :subject => 'This is first issue', :priority_id => 5},
1782 1787 :continue => ''
1783 1788 end
1784 1789
1785 1790 issue = Issue.first(:order => 'id DESC')
1786 1791 assert_redirected_to :controller => 'issues', :action => 'new', :project_id => 'ecookbook', :issue => {:tracker_id => 3}
1787 1792 assert_not_nil flash[:notice], "flash was not set"
1788 1793 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"
1789 1794 end
1790 1795
1791 1796 def test_post_create_without_custom_fields_param
1792 1797 @request.session[:user_id] = 2
1793 1798 assert_difference 'Issue.count' do
1794 1799 post :create, :project_id => 1,
1795 1800 :issue => {:tracker_id => 1,
1796 1801 :subject => 'This is the test_new issue',
1797 1802 :description => 'This is the description',
1798 1803 :priority_id => 5}
1799 1804 end
1800 1805 assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id
1801 1806 end
1802 1807
1803 1808 def test_post_create_with_multi_custom_field
1804 1809 field = IssueCustomField.find_by_name('Database')
1805 1810 field.update_attribute(:multiple, true)
1806 1811
1807 1812 @request.session[:user_id] = 2
1808 1813 assert_difference 'Issue.count' do
1809 1814 post :create, :project_id => 1,
1810 1815 :issue => {:tracker_id => 1,
1811 1816 :subject => 'This is the test_new issue',
1812 1817 :description => 'This is the description',
1813 1818 :priority_id => 5,
1814 1819 :custom_field_values => {'1' => ['', 'MySQL', 'Oracle']}}
1815 1820 end
1816 1821 assert_response 302
1817 1822 issue = Issue.first(:order => 'id DESC')
1818 1823 assert_equal ['MySQL', 'Oracle'], issue.custom_field_value(1).sort
1819 1824 end
1820 1825
1821 1826 def test_post_create_with_empty_multi_custom_field
1822 1827 field = IssueCustomField.find_by_name('Database')
1823 1828 field.update_attribute(:multiple, true)
1824 1829
1825 1830 @request.session[:user_id] = 2
1826 1831 assert_difference 'Issue.count' do
1827 1832 post :create, :project_id => 1,
1828 1833 :issue => {:tracker_id => 1,
1829 1834 :subject => 'This is the test_new issue',
1830 1835 :description => 'This is the description',
1831 1836 :priority_id => 5,
1832 1837 :custom_field_values => {'1' => ['']}}
1833 1838 end
1834 1839 assert_response 302
1835 1840 issue = Issue.first(:order => 'id DESC')
1836 1841 assert_equal [''], issue.custom_field_value(1).sort
1837 1842 end
1838 1843
1839 1844 def test_post_create_with_multi_user_custom_field
1840 1845 field = IssueCustomField.create!(:name => 'Multi user', :field_format => 'user', :multiple => true,
1841 1846 :tracker_ids => [1], :is_for_all => true)
1842 1847
1843 1848 @request.session[:user_id] = 2
1844 1849 assert_difference 'Issue.count' do
1845 1850 post :create, :project_id => 1,
1846 1851 :issue => {:tracker_id => 1,
1847 1852 :subject => 'This is the test_new issue',
1848 1853 :description => 'This is the description',
1849 1854 :priority_id => 5,
1850 1855 :custom_field_values => {field.id.to_s => ['', '2', '3']}}
1851 1856 end
1852 1857 assert_response 302
1853 1858 issue = Issue.first(:order => 'id DESC')
1854 1859 assert_equal ['2', '3'], issue.custom_field_value(field).sort
1855 1860 end
1856 1861
1857 1862 def test_post_create_with_required_custom_field_and_without_custom_fields_param
1858 1863 field = IssueCustomField.find_by_name('Database')
1859 1864 field.update_attribute(:is_required, true)
1860 1865
1861 1866 @request.session[:user_id] = 2
1862 1867 assert_no_difference 'Issue.count' do
1863 1868 post :create, :project_id => 1,
1864 1869 :issue => {:tracker_id => 1,
1865 1870 :subject => 'This is the test_new issue',
1866 1871 :description => 'This is the description',
1867 1872 :priority_id => 5}
1868 1873 end
1869 1874 assert_response :success
1870 1875 assert_template 'new'
1871 1876 issue = assigns(:issue)
1872 1877 assert_not_nil issue
1873 1878 assert_error_tag :content => /Database can&#x27;t be blank/
1874 1879 end
1875 1880
1876 1881 def test_create_should_validate_required_fields
1877 1882 cf1 = IssueCustomField.create!(:name => 'Foo', :field_format => 'string', :is_for_all => true, :tracker_ids => [1, 2])
1878 1883 cf2 = IssueCustomField.create!(:name => 'Bar', :field_format => 'string', :is_for_all => true, :tracker_ids => [1, 2])
1879 1884 WorkflowPermission.delete_all
1880 1885 WorkflowPermission.create!(:old_status_id => 1, :tracker_id => 2, :role_id => 1, :field_name => 'due_date', :rule => 'required')
1881 1886 WorkflowPermission.create!(:old_status_id => 1, :tracker_id => 2, :role_id => 1, :field_name => cf2.id.to_s, :rule => 'required')
1882 1887 @request.session[:user_id] = 2
1883 1888
1884 1889 assert_no_difference 'Issue.count' do
1885 1890 post :create, :project_id => 1, :issue => {
1886 1891 :tracker_id => 2,
1887 1892 :status_id => 1,
1888 1893 :subject => 'Test',
1889 1894 :start_date => '',
1890 1895 :due_date => '',
1891 1896 :custom_field_values => {cf1.id.to_s => '', cf2.id.to_s => ''}
1892 1897 }
1893 1898 assert_response :success
1894 1899 assert_template 'new'
1895 1900 end
1896 1901
1897 1902 assert_error_tag :content => /Due date can&#x27;t be blank/i
1898 1903 assert_error_tag :content => /Bar can&#x27;t be blank/i
1899 1904 end
1900 1905
1901 1906 def test_create_should_ignore_readonly_fields
1902 1907 cf1 = IssueCustomField.create!(:name => 'Foo', :field_format => 'string', :is_for_all => true, :tracker_ids => [1, 2])
1903 1908 cf2 = IssueCustomField.create!(:name => 'Bar', :field_format => 'string', :is_for_all => true, :tracker_ids => [1, 2])
1904 1909 WorkflowPermission.delete_all
1905 1910 WorkflowPermission.create!(:old_status_id => 1, :tracker_id => 2, :role_id => 1, :field_name => 'due_date', :rule => 'readonly')
1906 1911 WorkflowPermission.create!(:old_status_id => 1, :tracker_id => 2, :role_id => 1, :field_name => cf2.id.to_s, :rule => 'readonly')
1907 1912 @request.session[:user_id] = 2
1908 1913
1909 1914 assert_difference 'Issue.count' do
1910 1915 post :create, :project_id => 1, :issue => {
1911 1916 :tracker_id => 2,
1912 1917 :status_id => 1,
1913 1918 :subject => 'Test',
1914 1919 :start_date => '2012-07-14',
1915 1920 :due_date => '2012-07-16',
1916 1921 :custom_field_values => {cf1.id.to_s => 'value1', cf2.id.to_s => 'value2'}
1917 1922 }
1918 1923 assert_response 302
1919 1924 end
1920 1925
1921 1926 issue = Issue.first(:order => 'id DESC')
1922 1927 assert_equal Date.parse('2012-07-14'), issue.start_date
1923 1928 assert_nil issue.due_date
1924 1929 assert_equal 'value1', issue.custom_field_value(cf1)
1925 1930 assert_nil issue.custom_field_value(cf2)
1926 1931 end
1927 1932
1928 1933 def test_post_create_with_watchers
1929 1934 @request.session[:user_id] = 2
1930 1935 ActionMailer::Base.deliveries.clear
1931 1936
1932 1937 assert_difference 'Watcher.count', 2 do
1933 1938 post :create, :project_id => 1,
1934 1939 :issue => {:tracker_id => 1,
1935 1940 :subject => 'This is a new issue with watchers',
1936 1941 :description => 'This is the description',
1937 1942 :priority_id => 5,
1938 1943 :watcher_user_ids => ['2', '3']}
1939 1944 end
1940 1945 issue = Issue.find_by_subject('This is a new issue with watchers')
1941 1946 assert_not_nil issue
1942 1947 assert_redirected_to :controller => 'issues', :action => 'show', :id => issue
1943 1948
1944 1949 # Watchers added
1945 1950 assert_equal [2, 3], issue.watcher_user_ids.sort
1946 1951 assert issue.watched_by?(User.find(3))
1947 1952 # Watchers notified
1948 1953 mail = ActionMailer::Base.deliveries.last
1949 1954 assert_not_nil mail
1950 1955 assert [mail.bcc, mail.cc].flatten.include?(User.find(3).mail)
1951 1956 end
1952 1957
1953 1958 def test_post_create_subissue
1954 1959 @request.session[:user_id] = 2
1955 1960
1956 1961 assert_difference 'Issue.count' do
1957 1962 post :create, :project_id => 1,
1958 1963 :issue => {:tracker_id => 1,
1959 1964 :subject => 'This is a child issue',
1960 1965 :parent_issue_id => '2'}
1961 1966 assert_response 302
1962 1967 end
1963 1968 issue = Issue.order('id DESC').first
1964 1969 assert_equal Issue.find(2), issue.parent
1965 1970 end
1966 1971
1967 1972 def test_post_create_subissue_with_sharp_parent_id
1968 1973 @request.session[:user_id] = 2
1969 1974
1970 1975 assert_difference 'Issue.count' do
1971 1976 post :create, :project_id => 1,
1972 1977 :issue => {:tracker_id => 1,
1973 1978 :subject => 'This is a child issue',
1974 1979 :parent_issue_id => '#2'}
1975 1980 assert_response 302
1976 1981 end
1977 1982 issue = Issue.order('id DESC').first
1978 1983 assert_equal Issue.find(2), issue.parent
1979 1984 end
1980 1985
1981 1986 def test_post_create_subissue_with_non_visible_parent_id_should_not_validate
1982 1987 @request.session[:user_id] = 2
1983 1988
1984 1989 assert_no_difference 'Issue.count' do
1985 1990 post :create, :project_id => 1,
1986 1991 :issue => {:tracker_id => 1,
1987 1992 :subject => 'This is a child issue',
1988 1993 :parent_issue_id => '4'}
1989 1994
1990 1995 assert_response :success
1991 1996 assert_select 'input[name=?][value=?]', 'issue[parent_issue_id]', '4'
1992 1997 assert_error_tag :content => /Parent task is invalid/i
1993 1998 end
1994 1999 end
1995 2000
1996 2001 def test_post_create_subissue_with_non_numeric_parent_id_should_not_validate
1997 2002 @request.session[:user_id] = 2
1998 2003
1999 2004 assert_no_difference 'Issue.count' do
2000 2005 post :create, :project_id => 1,
2001 2006 :issue => {:tracker_id => 1,
2002 2007 :subject => 'This is a child issue',
2003 2008 :parent_issue_id => '01ABC'}
2004 2009
2005 2010 assert_response :success
2006 2011 assert_select 'input[name=?][value=?]', 'issue[parent_issue_id]', '01ABC'
2007 2012 assert_error_tag :content => /Parent task is invalid/i
2008 2013 end
2009 2014 end
2010 2015
2011 2016 def test_post_create_private
2012 2017 @request.session[:user_id] = 2
2013 2018
2014 2019 assert_difference 'Issue.count' do
2015 2020 post :create, :project_id => 1,
2016 2021 :issue => {:tracker_id => 1,
2017 2022 :subject => 'This is a private issue',
2018 2023 :is_private => '1'}
2019 2024 end
2020 2025 issue = Issue.first(:order => 'id DESC')
2021 2026 assert issue.is_private?
2022 2027 end
2023 2028
2024 2029 def test_post_create_private_with_set_own_issues_private_permission
2025 2030 role = Role.find(1)
2026 2031 role.remove_permission! :set_issues_private
2027 2032 role.add_permission! :set_own_issues_private
2028 2033
2029 2034 @request.session[:user_id] = 2
2030 2035
2031 2036 assert_difference 'Issue.count' do
2032 2037 post :create, :project_id => 1,
2033 2038 :issue => {:tracker_id => 1,
2034 2039 :subject => 'This is a private issue',
2035 2040 :is_private => '1'}
2036 2041 end
2037 2042 issue = Issue.first(:order => 'id DESC')
2038 2043 assert issue.is_private?
2039 2044 end
2040 2045
2041 2046 def test_post_create_should_send_a_notification
2042 2047 ActionMailer::Base.deliveries.clear
2043 2048 @request.session[:user_id] = 2
2044 2049 assert_difference 'Issue.count' do
2045 2050 post :create, :project_id => 1,
2046 2051 :issue => {:tracker_id => 3,
2047 2052 :subject => 'This is the test_new issue',
2048 2053 :description => 'This is the description',
2049 2054 :priority_id => 5,
2050 2055 :estimated_hours => '',
2051 2056 :custom_field_values => {'2' => 'Value for field 2'}}
2052 2057 end
2053 2058 assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id
2054 2059
2055 2060 assert_equal 1, ActionMailer::Base.deliveries.size
2056 2061 end
2057 2062
2058 2063 def test_post_create_should_preserve_fields_values_on_validation_failure
2059 2064 @request.session[:user_id] = 2
2060 2065 post :create, :project_id => 1,
2061 2066 :issue => {:tracker_id => 1,
2062 2067 # empty subject
2063 2068 :subject => '',
2064 2069 :description => 'This is a description',
2065 2070 :priority_id => 6,
2066 2071 :custom_field_values => {'1' => 'Oracle', '2' => 'Value for field 2'}}
2067 2072 assert_response :success
2068 2073 assert_template 'new'
2069 2074
2070 2075 assert_tag :textarea, :attributes => { :name => 'issue[description]' },
2071 2076 :content => "\nThis is a description"
2072 2077 assert_tag :select, :attributes => { :name => 'issue[priority_id]' },
2073 2078 :child => { :tag => 'option', :attributes => { :selected => 'selected',
2074 2079 :value => '6' },
2075 2080 :content => 'High' }
2076 2081 # Custom fields
2077 2082 assert_tag :select, :attributes => { :name => 'issue[custom_field_values][1]' },
2078 2083 :child => { :tag => 'option', :attributes => { :selected => 'selected',
2079 2084 :value => 'Oracle' },
2080 2085 :content => 'Oracle' }
2081 2086 assert_tag :input, :attributes => { :name => 'issue[custom_field_values][2]',
2082 2087 :value => 'Value for field 2'}
2083 2088 end
2084 2089
2085 2090 def test_post_create_with_failure_should_preserve_watchers
2086 2091 assert !User.find(8).member_of?(Project.find(1))
2087 2092
2088 2093 @request.session[:user_id] = 2
2089 2094 post :create, :project_id => 1,
2090 2095 :issue => {:tracker_id => 1,
2091 2096 :watcher_user_ids => ['3', '8']}
2092 2097 assert_response :success
2093 2098 assert_template 'new'
2094 2099
2095 2100 assert_tag 'input', :attributes => {:name => 'issue[watcher_user_ids][]', :value => '2', :checked => nil}
2096 2101 assert_tag 'input', :attributes => {:name => 'issue[watcher_user_ids][]', :value => '3', :checked => 'checked'}
2097 2102 assert_tag 'input', :attributes => {:name => 'issue[watcher_user_ids][]', :value => '8', :checked => 'checked'}
2098 2103 end
2099 2104
2100 2105 def test_post_create_should_ignore_non_safe_attributes
2101 2106 @request.session[:user_id] = 2
2102 2107 assert_nothing_raised do
2103 2108 post :create, :project_id => 1, :issue => { :tracker => "A param can not be a Tracker" }
2104 2109 end
2105 2110 end
2106 2111
2107 2112 def test_post_create_with_attachment
2108 2113 set_tmp_attachments_directory
2109 2114 @request.session[:user_id] = 2
2110 2115
2111 2116 assert_difference 'Issue.count' do
2112 2117 assert_difference 'Attachment.count' do
2113 2118 post :create, :project_id => 1,
2114 2119 :issue => { :tracker_id => '1', :subject => 'With attachment' },
2115 2120 :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain'), 'description' => 'test file'}}
2116 2121 end
2117 2122 end
2118 2123
2119 2124 issue = Issue.first(:order => 'id DESC')
2120 2125 attachment = Attachment.first(:order => 'id DESC')
2121 2126
2122 2127 assert_equal issue, attachment.container
2123 2128 assert_equal 2, attachment.author_id
2124 2129 assert_equal 'testfile.txt', attachment.filename
2125 2130 assert_equal 'text/plain', attachment.content_type
2126 2131 assert_equal 'test file', attachment.description
2127 2132 assert_equal 59, attachment.filesize
2128 2133 assert File.exists?(attachment.diskfile)
2129 2134 assert_equal 59, File.size(attachment.diskfile)
2130 2135 end
2131 2136
2132 2137 def test_post_create_with_failure_should_save_attachments
2133 2138 set_tmp_attachments_directory
2134 2139 @request.session[:user_id] = 2
2135 2140
2136 2141 assert_no_difference 'Issue.count' do
2137 2142 assert_difference 'Attachment.count' do
2138 2143 post :create, :project_id => 1,
2139 2144 :issue => { :tracker_id => '1', :subject => '' },
2140 2145 :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain'), 'description' => 'test file'}}
2141 2146 assert_response :success
2142 2147 assert_template 'new'
2143 2148 end
2144 2149 end
2145 2150
2146 2151 attachment = Attachment.first(:order => 'id DESC')
2147 2152 assert_equal 'testfile.txt', attachment.filename
2148 2153 assert File.exists?(attachment.diskfile)
2149 2154 assert_nil attachment.container
2150 2155
2151 2156 assert_tag 'input', :attributes => {:name => 'attachments[p0][token]', :value => attachment.token}
2152 2157 assert_tag 'span', :content => /testfile.txt/
2153 2158 end
2154 2159
2155 2160 def test_post_create_with_failure_should_keep_saved_attachments
2156 2161 set_tmp_attachments_directory
2157 2162 attachment = Attachment.create!(:file => uploaded_test_file("testfile.txt", "text/plain"), :author_id => 2)
2158 2163 @request.session[:user_id] = 2
2159 2164
2160 2165 assert_no_difference 'Issue.count' do
2161 2166 assert_no_difference 'Attachment.count' do
2162 2167 post :create, :project_id => 1,
2163 2168 :issue => { :tracker_id => '1', :subject => '' },
2164 2169 :attachments => {'p0' => {'token' => attachment.token}}
2165 2170 assert_response :success
2166 2171 assert_template 'new'
2167 2172 end
2168 2173 end
2169 2174
2170 2175 assert_tag 'input', :attributes => {:name => 'attachments[p0][token]', :value => attachment.token}
2171 2176 assert_tag 'span', :content => /testfile.txt/
2172 2177 end
2173 2178
2174 2179 def test_post_create_should_attach_saved_attachments
2175 2180 set_tmp_attachments_directory
2176 2181 attachment = Attachment.create!(:file => uploaded_test_file("testfile.txt", "text/plain"), :author_id => 2)
2177 2182 @request.session[:user_id] = 2
2178 2183
2179 2184 assert_difference 'Issue.count' do
2180 2185 assert_no_difference 'Attachment.count' do
2181 2186 post :create, :project_id => 1,
2182 2187 :issue => { :tracker_id => '1', :subject => 'Saved attachments' },
2183 2188 :attachments => {'p0' => {'token' => attachment.token}}
2184 2189 assert_response 302
2185 2190 end
2186 2191 end
2187 2192
2188 2193 issue = Issue.first(:order => 'id DESC')
2189 2194 assert_equal 1, issue.attachments.count
2190 2195
2191 2196 attachment.reload
2192 2197 assert_equal issue, attachment.container
2193 2198 end
2194 2199
2195 2200 context "without workflow privilege" do
2196 2201 setup do
2197 2202 WorkflowTransition.delete_all(["role_id = ?", Role.anonymous.id])
2198 2203 Role.anonymous.add_permission! :add_issues, :add_issue_notes
2199 2204 end
2200 2205
2201 2206 context "#new" do
2202 2207 should "propose default status only" do
2203 2208 get :new, :project_id => 1
2204 2209 assert_response :success
2205 2210 assert_template 'new'
2206 2211 assert_tag :tag => 'select',
2207 2212 :attributes => {:name => 'issue[status_id]'},
2208 2213 :children => {:count => 1},
2209 2214 :child => {:tag => 'option', :attributes => {:value => IssueStatus.default.id.to_s}}
2210 2215 end
2211 2216
2212 2217 should "accept default status" do
2213 2218 assert_difference 'Issue.count' do
2214 2219 post :create, :project_id => 1,
2215 2220 :issue => {:tracker_id => 1,
2216 2221 :subject => 'This is an issue',
2217 2222 :status_id => 1}
2218 2223 end
2219 2224 issue = Issue.last(:order => 'id')
2220 2225 assert_equal IssueStatus.default, issue.status
2221 2226 end
2222 2227
2223 2228 should "ignore unauthorized status" do
2224 2229 assert_difference 'Issue.count' do
2225 2230 post :create, :project_id => 1,
2226 2231 :issue => {:tracker_id => 1,
2227 2232 :subject => 'This is an issue',
2228 2233 :status_id => 3}
2229 2234 end
2230 2235 issue = Issue.last(:order => 'id')
2231 2236 assert_equal IssueStatus.default, issue.status
2232 2237 end
2233 2238 end
2234 2239
2235 2240 context "#update" do
2236 2241 should "ignore status change" do
2237 2242 assert_difference 'Journal.count' do
2238 2243 put :update, :id => 1, :issue => {:status_id => 3, :notes => 'just trying'}
2239 2244 end
2240 2245 assert_equal 1, Issue.find(1).status_id
2241 2246 end
2242 2247
2243 2248 should "ignore attributes changes" do
2244 2249 assert_difference 'Journal.count' do
2245 2250 put :update, :id => 1, :issue => {:subject => 'changed', :assigned_to_id => 2, :notes => 'just trying'}
2246 2251 end
2247 2252 issue = Issue.find(1)
2248 2253 assert_equal "Can't print recipes", issue.subject
2249 2254 assert_nil issue.assigned_to
2250 2255 end
2251 2256 end
2252 2257 end
2253 2258
2254 2259 context "with workflow privilege" do
2255 2260 setup do
2256 2261 WorkflowTransition.delete_all(["role_id = ?", Role.anonymous.id])
2257 2262 WorkflowTransition.create!(:role => Role.anonymous, :tracker_id => 1, :old_status_id => 1, :new_status_id => 3)
2258 2263 WorkflowTransition.create!(:role => Role.anonymous, :tracker_id => 1, :old_status_id => 1, :new_status_id => 4)
2259 2264 Role.anonymous.add_permission! :add_issues, :add_issue_notes
2260 2265 end
2261 2266
2262 2267 context "#update" do
2263 2268 should "accept authorized status" do
2264 2269 assert_difference 'Journal.count' do
2265 2270 put :update, :id => 1, :issue => {:status_id => 3, :notes => 'just trying'}
2266 2271 end
2267 2272 assert_equal 3, Issue.find(1).status_id
2268 2273 end
2269 2274
2270 2275 should "ignore unauthorized status" do
2271 2276 assert_difference 'Journal.count' do
2272 2277 put :update, :id => 1, :issue => {:status_id => 2, :notes => 'just trying'}
2273 2278 end
2274 2279 assert_equal 1, Issue.find(1).status_id
2275 2280 end
2276 2281
2277 2282 should "accept authorized attributes changes" do
2278 2283 assert_difference 'Journal.count' do
2279 2284 put :update, :id => 1, :issue => {:assigned_to_id => 2, :notes => 'just trying'}
2280 2285 end
2281 2286 issue = Issue.find(1)
2282 2287 assert_equal 2, issue.assigned_to_id
2283 2288 end
2284 2289
2285 2290 should "ignore unauthorized attributes changes" do
2286 2291 assert_difference 'Journal.count' do
2287 2292 put :update, :id => 1, :issue => {:subject => 'changed', :notes => 'just trying'}
2288 2293 end
2289 2294 issue = Issue.find(1)
2290 2295 assert_equal "Can't print recipes", issue.subject
2291 2296 end
2292 2297 end
2293 2298
2294 2299 context "and :edit_issues permission" do
2295 2300 setup do
2296 2301 Role.anonymous.add_permission! :add_issues, :edit_issues
2297 2302 end
2298 2303
2299 2304 should "accept authorized status" do
2300 2305 assert_difference 'Journal.count' do
2301 2306 put :update, :id => 1, :issue => {:status_id => 3, :notes => 'just trying'}
2302 2307 end
2303 2308 assert_equal 3, Issue.find(1).status_id
2304 2309 end
2305 2310
2306 2311 should "ignore unauthorized status" do
2307 2312 assert_difference 'Journal.count' do
2308 2313 put :update, :id => 1, :issue => {:status_id => 2, :notes => 'just trying'}
2309 2314 end
2310 2315 assert_equal 1, Issue.find(1).status_id
2311 2316 end
2312 2317
2313 2318 should "accept authorized attributes changes" do
2314 2319 assert_difference 'Journal.count' do
2315 2320 put :update, :id => 1, :issue => {:subject => 'changed', :assigned_to_id => 2, :notes => 'just trying'}
2316 2321 end
2317 2322 issue = Issue.find(1)
2318 2323 assert_equal "changed", issue.subject
2319 2324 assert_equal 2, issue.assigned_to_id
2320 2325 end
2321 2326 end
2322 2327 end
2323 2328
2324 2329 def test_new_as_copy
2325 2330 @request.session[:user_id] = 2
2326 2331 get :new, :project_id => 1, :copy_from => 1
2327 2332
2328 2333 assert_response :success
2329 2334 assert_template 'new'
2330 2335
2331 2336 assert_not_nil assigns(:issue)
2332 2337 orig = Issue.find(1)
2333 2338 assert_equal 1, assigns(:issue).project_id
2334 2339 assert_equal orig.subject, assigns(:issue).subject
2335 2340 assert assigns(:issue).copy?
2336 2341
2337 2342 assert_tag 'form', :attributes => {:id => 'issue-form', :action => '/projects/ecookbook/issues'}
2338 2343 assert_tag 'select', :attributes => {:name => 'issue[project_id]'}
2339 2344 assert_tag 'select', :attributes => {:name => 'issue[project_id]'},
2340 2345 :child => {:tag => 'option', :attributes => {:value => '1', :selected => 'selected'}, :content => 'eCookbook'}
2341 2346 assert_tag 'select', :attributes => {:name => 'issue[project_id]'},
2342 2347 :child => {:tag => 'option', :attributes => {:value => '2', :selected => nil}, :content => 'OnlineStore'}
2343 2348 assert_tag 'input', :attributes => {:name => 'copy_from', :value => '1'}
2344 2349 end
2345 2350
2346 2351 def test_new_as_copy_with_attachments_should_show_copy_attachments_checkbox
2347 2352 @request.session[:user_id] = 2
2348 2353 issue = Issue.find(3)
2349 2354 assert issue.attachments.count > 0
2350 2355 get :new, :project_id => 1, :copy_from => 3
2351 2356
2352 2357 assert_tag 'input', :attributes => {:name => 'copy_attachments', :type => 'checkbox', :checked => 'checked', :value => '1'}
2353 2358 end
2354 2359
2355 2360 def test_new_as_copy_without_attachments_should_not_show_copy_attachments_checkbox
2356 2361 @request.session[:user_id] = 2
2357 2362 issue = Issue.find(3)
2358 2363 issue.attachments.delete_all
2359 2364 get :new, :project_id => 1, :copy_from => 3
2360 2365
2361 2366 assert_no_tag 'input', :attributes => {:name => 'copy_attachments', :type => 'checkbox', :checked => 'checked', :value => '1'}
2362 2367 end
2363 2368
2364 2369 def test_new_as_copy_with_subtasks_should_show_copy_subtasks_checkbox
2365 2370 @request.session[:user_id] = 2
2366 2371 issue = Issue.generate_with_descendants!
2367 2372 get :new, :project_id => 1, :copy_from => issue.id
2368 2373
2369 2374 assert_select 'input[type=checkbox][name=copy_subtasks][checked=checked][value=1]'
2370 2375 end
2371 2376
2372 2377 def test_new_as_copy_with_invalid_issue_should_respond_with_404
2373 2378 @request.session[:user_id] = 2
2374 2379 get :new, :project_id => 1, :copy_from => 99999
2375 2380 assert_response 404
2376 2381 end
2377 2382
2378 2383 def test_create_as_copy_on_different_project
2379 2384 @request.session[:user_id] = 2
2380 2385 assert_difference 'Issue.count' do
2381 2386 post :create, :project_id => 1, :copy_from => 1,
2382 2387 :issue => {:project_id => '2', :tracker_id => '3', :status_id => '1', :subject => 'Copy'}
2383 2388
2384 2389 assert_not_nil assigns(:issue)
2385 2390 assert assigns(:issue).copy?
2386 2391 end
2387 2392 issue = Issue.first(:order => 'id DESC')
2388 2393 assert_redirected_to "/issues/#{issue.id}"
2389 2394
2390 2395 assert_equal 2, issue.project_id
2391 2396 assert_equal 3, issue.tracker_id
2392 2397 assert_equal 'Copy', issue.subject
2393 2398 end
2394 2399
2395 2400 def test_create_as_copy_should_copy_attachments
2396 2401 @request.session[:user_id] = 2
2397 2402 issue = Issue.find(3)
2398 2403 count = issue.attachments.count
2399 2404 assert count > 0
2400 2405
2401 2406 assert_difference 'Issue.count' do
2402 2407 assert_difference 'Attachment.count', count do
2403 2408 assert_no_difference 'Journal.count' do
2404 2409 post :create, :project_id => 1, :copy_from => 3,
2405 2410 :issue => {:project_id => '1', :tracker_id => '3', :status_id => '1', :subject => 'Copy with attachments'},
2406 2411 :copy_attachments => '1'
2407 2412 end
2408 2413 end
2409 2414 end
2410 2415 copy = Issue.first(:order => 'id DESC')
2411 2416 assert_equal count, copy.attachments.count
2412 2417 assert_equal issue.attachments.map(&:filename).sort, copy.attachments.map(&:filename).sort
2413 2418 end
2414 2419
2415 2420 def test_create_as_copy_without_copy_attachments_option_should_not_copy_attachments
2416 2421 @request.session[:user_id] = 2
2417 2422 issue = Issue.find(3)
2418 2423 count = issue.attachments.count
2419 2424 assert count > 0
2420 2425
2421 2426 assert_difference 'Issue.count' do
2422 2427 assert_no_difference 'Attachment.count' do
2423 2428 assert_no_difference 'Journal.count' do
2424 2429 post :create, :project_id => 1, :copy_from => 3,
2425 2430 :issue => {:project_id => '1', :tracker_id => '3', :status_id => '1', :subject => 'Copy with attachments'}
2426 2431 end
2427 2432 end
2428 2433 end
2429 2434 copy = Issue.first(:order => 'id DESC')
2430 2435 assert_equal 0, copy.attachments.count
2431 2436 end
2432 2437
2433 2438 def test_create_as_copy_with_attachments_should_add_new_files
2434 2439 @request.session[:user_id] = 2
2435 2440 issue = Issue.find(3)
2436 2441 count = issue.attachments.count
2437 2442 assert count > 0
2438 2443
2439 2444 assert_difference 'Issue.count' do
2440 2445 assert_difference 'Attachment.count', count + 1 do
2441 2446 assert_no_difference 'Journal.count' do
2442 2447 post :create, :project_id => 1, :copy_from => 3,
2443 2448 :issue => {:project_id => '1', :tracker_id => '3', :status_id => '1', :subject => 'Copy with attachments'},
2444 2449 :copy_attachments => '1',
2445 2450 :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain'), 'description' => 'test file'}}
2446 2451 end
2447 2452 end
2448 2453 end
2449 2454 copy = Issue.first(:order => 'id DESC')
2450 2455 assert_equal count + 1, copy.attachments.count
2451 2456 end
2452 2457
2453 2458 def test_create_as_copy_should_add_relation_with_copied_issue
2454 2459 @request.session[:user_id] = 2
2455 2460
2456 2461 assert_difference 'Issue.count' do
2457 2462 assert_difference 'IssueRelation.count' do
2458 2463 post :create, :project_id => 1, :copy_from => 1,
2459 2464 :issue => {:project_id => '1', :tracker_id => '3', :status_id => '1', :subject => 'Copy'}
2460 2465 end
2461 2466 end
2462 2467 copy = Issue.first(:order => 'id DESC')
2463 2468 assert_equal 1, copy.relations.size
2464 2469 end
2465 2470
2466 2471 def test_create_as_copy_should_copy_subtasks
2467 2472 @request.session[:user_id] = 2
2468 2473 issue = Issue.generate_with_descendants!
2469 2474 count = issue.descendants.count
2470 2475
2471 2476 assert_difference 'Issue.count', count+1 do
2472 2477 assert_no_difference 'Journal.count' do
2473 2478 post :create, :project_id => 1, :copy_from => issue.id,
2474 2479 :issue => {:project_id => '1', :tracker_id => '3', :status_id => '1', :subject => 'Copy with subtasks'},
2475 2480 :copy_subtasks => '1'
2476 2481 end
2477 2482 end
2478 2483 copy = Issue.where(:parent_id => nil).first(:order => 'id DESC')
2479 2484 assert_equal count, copy.descendants.count
2480 2485 assert_equal issue.descendants.map(&:subject).sort, copy.descendants.map(&:subject).sort
2481 2486 end
2482 2487
2483 2488 def test_create_as_copy_without_copy_subtasks_option_should_not_copy_subtasks
2484 2489 @request.session[:user_id] = 2
2485 2490 issue = Issue.generate_with_descendants!
2486 2491
2487 2492 assert_difference 'Issue.count', 1 do
2488 2493 assert_no_difference 'Journal.count' do
2489 2494 post :create, :project_id => 1, :copy_from => 3,
2490 2495 :issue => {:project_id => '1', :tracker_id => '3', :status_id => '1', :subject => 'Copy with subtasks'}
2491 2496 end
2492 2497 end
2493 2498 copy = Issue.where(:parent_id => nil).first(:order => 'id DESC')
2494 2499 assert_equal 0, copy.descendants.count
2495 2500 end
2496 2501
2497 2502 def test_create_as_copy_with_failure
2498 2503 @request.session[:user_id] = 2
2499 2504 post :create, :project_id => 1, :copy_from => 1,
2500 2505 :issue => {:project_id => '2', :tracker_id => '3', :status_id => '1', :subject => ''}
2501 2506
2502 2507 assert_response :success
2503 2508 assert_template 'new'
2504 2509
2505 2510 assert_not_nil assigns(:issue)
2506 2511 assert assigns(:issue).copy?
2507 2512
2508 2513 assert_tag 'form', :attributes => {:id => 'issue-form', :action => '/projects/ecookbook/issues'}
2509 2514 assert_tag 'select', :attributes => {:name => 'issue[project_id]'}
2510 2515 assert_tag 'select', :attributes => {:name => 'issue[project_id]'},
2511 2516 :child => {:tag => 'option', :attributes => {:value => '1', :selected => nil}, :content => 'eCookbook'}
2512 2517 assert_tag 'select', :attributes => {:name => 'issue[project_id]'},
2513 2518 :child => {:tag => 'option', :attributes => {:value => '2', :selected => 'selected'}, :content => 'OnlineStore'}
2514 2519 assert_tag 'input', :attributes => {:name => 'copy_from', :value => '1'}
2515 2520 end
2516 2521
2517 2522 def test_create_as_copy_on_project_without_permission_should_ignore_target_project
2518 2523 @request.session[:user_id] = 2
2519 2524 assert !User.find(2).member_of?(Project.find(4))
2520 2525
2521 2526 assert_difference 'Issue.count' do
2522 2527 post :create, :project_id => 1, :copy_from => 1,
2523 2528 :issue => {:project_id => '4', :tracker_id => '3', :status_id => '1', :subject => 'Copy'}
2524 2529 end
2525 2530 issue = Issue.first(:order => 'id DESC')
2526 2531 assert_equal 1, issue.project_id
2527 2532 end
2528 2533
2529 2534 def test_get_edit
2530 2535 @request.session[:user_id] = 2
2531 2536 get :edit, :id => 1
2532 2537 assert_response :success
2533 2538 assert_template 'edit'
2534 2539 assert_not_nil assigns(:issue)
2535 2540 assert_equal Issue.find(1), assigns(:issue)
2536 2541
2537 2542 # Be sure we don't display inactive IssuePriorities
2538 2543 assert ! IssuePriority.find(15).active?
2539 2544 assert_no_tag :option, :attributes => {:value => '15'},
2540 2545 :parent => {:tag => 'select', :attributes => {:id => 'issue_priority_id'} }
2541 2546 end
2542 2547
2543 2548 def test_get_edit_should_display_the_time_entry_form_with_log_time_permission
2544 2549 @request.session[:user_id] = 2
2545 2550 Role.find_by_name('Manager').update_attribute :permissions, [:view_issues, :edit_issues, :log_time]
2546 2551
2547 2552 get :edit, :id => 1
2548 2553 assert_tag 'input', :attributes => {:name => 'time_entry[hours]'}
2549 2554 end
2550 2555
2551 2556 def test_get_edit_should_not_display_the_time_entry_form_without_log_time_permission
2552 2557 @request.session[:user_id] = 2
2553 2558 Role.find_by_name('Manager').remove_permission! :log_time
2554 2559
2555 2560 get :edit, :id => 1
2556 2561 assert_no_tag 'input', :attributes => {:name => 'time_entry[hours]'}
2557 2562 end
2558 2563
2559 2564 def test_get_edit_with_params
2560 2565 @request.session[:user_id] = 2
2561 2566 get :edit, :id => 1, :issue => { :status_id => 5, :priority_id => 7 },
2562 2567 :time_entry => { :hours => '2.5', :comments => 'test_get_edit_with_params', :activity_id => TimeEntryActivity.first.id }
2563 2568 assert_response :success
2564 2569 assert_template 'edit'
2565 2570
2566 2571 issue = assigns(:issue)
2567 2572 assert_not_nil issue
2568 2573
2569 2574 assert_equal 5, issue.status_id
2570 2575 assert_tag :select, :attributes => { :name => 'issue[status_id]' },
2571 2576 :child => { :tag => 'option',
2572 2577 :content => 'Closed',
2573 2578 :attributes => { :selected => 'selected' } }
2574 2579
2575 2580 assert_equal 7, issue.priority_id
2576 2581 assert_tag :select, :attributes => { :name => 'issue[priority_id]' },
2577 2582 :child => { :tag => 'option',
2578 2583 :content => 'Urgent',
2579 2584 :attributes => { :selected => 'selected' } }
2580 2585
2581 2586 assert_tag :input, :attributes => { :name => 'time_entry[hours]', :value => '2.5' }
2582 2587 assert_tag :select, :attributes => { :name => 'time_entry[activity_id]' },
2583 2588 :child => { :tag => 'option',
2584 2589 :attributes => { :selected => 'selected', :value => TimeEntryActivity.first.id } }
2585 2590 assert_tag :input, :attributes => { :name => 'time_entry[comments]', :value => 'test_get_edit_with_params' }
2586 2591 end
2587 2592
2588 2593 def test_get_edit_with_multi_custom_field
2589 2594 field = CustomField.find(1)
2590 2595 field.update_attribute :multiple, true
2591 2596 issue = Issue.find(1)
2592 2597 issue.custom_field_values = {1 => ['MySQL', 'Oracle']}
2593 2598 issue.save!
2594 2599
2595 2600 @request.session[:user_id] = 2
2596 2601 get :edit, :id => 1
2597 2602 assert_response :success
2598 2603 assert_template 'edit'
2599 2604
2600 2605 assert_tag 'select', :attributes => {:name => 'issue[custom_field_values][1][]', :multiple => 'multiple'}
2601 2606 assert_tag 'select', :attributes => {:name => 'issue[custom_field_values][1][]'},
2602 2607 :child => {:tag => 'option', :attributes => {:value => 'MySQL', :selected => 'selected'}}
2603 2608 assert_tag 'select', :attributes => {:name => 'issue[custom_field_values][1][]'},
2604 2609 :child => {:tag => 'option', :attributes => {:value => 'PostgreSQL', :selected => nil}}
2605 2610 assert_tag 'select', :attributes => {:name => 'issue[custom_field_values][1][]'},
2606 2611 :child => {:tag => 'option', :attributes => {:value => 'Oracle', :selected => 'selected'}}
2607 2612 end
2608 2613
2609 2614 def test_update_edit_form
2610 2615 @request.session[:user_id] = 2
2611 2616 xhr :put, :new, :project_id => 1,
2612 2617 :id => 1,
2613 2618 :issue => {:tracker_id => 2,
2614 2619 :subject => 'This is the test_new issue',
2615 2620 :description => 'This is the description',
2616 2621 :priority_id => 5}
2617 2622 assert_response :success
2618 2623 assert_equal 'text/javascript', response.content_type
2619 2624 assert_template 'update_form'
2620 2625 assert_template 'form'
2621 2626
2622 2627 issue = assigns(:issue)
2623 2628 assert_kind_of Issue, issue
2624 2629 assert_equal 1, issue.id
2625 2630 assert_equal 1, issue.project_id
2626 2631 assert_equal 2, issue.tracker_id
2627 2632 assert_equal 'This is the test_new issue', issue.subject
2628 2633 end
2629 2634
2630 2635 def test_update_edit_form_should_keep_issue_author
2631 2636 @request.session[:user_id] = 3
2632 2637 xhr :put, :new, :project_id => 1, :id => 1, :issue => {:subject => 'Changed'}
2633 2638 assert_response :success
2634 2639 assert_equal 'text/javascript', response.content_type
2635 2640
2636 2641 issue = assigns(:issue)
2637 2642 assert_equal User.find(2), issue.author
2638 2643 assert_equal 2, issue.author_id
2639 2644 assert_not_equal User.current, issue.author
2640 2645 end
2641 2646
2642 2647 def test_update_edit_form_should_propose_transitions_based_on_initial_status
2643 2648 @request.session[:user_id] = 2
2644 2649 WorkflowTransition.delete_all
2645 2650 WorkflowTransition.create!(:role_id => 1, :tracker_id => 2, :old_status_id => 2, :new_status_id => 1)
2646 2651 WorkflowTransition.create!(:role_id => 1, :tracker_id => 2, :old_status_id => 2, :new_status_id => 5)
2647 2652 WorkflowTransition.create!(:role_id => 1, :tracker_id => 2, :old_status_id => 5, :new_status_id => 4)
2648 2653
2649 2654 xhr :put, :new, :project_id => 1,
2650 2655 :id => 2,
2651 2656 :issue => {:tracker_id => 2,
2652 2657 :status_id => 5,
2653 2658 :subject => 'This is an issue'}
2654 2659
2655 2660 assert_equal 5, assigns(:issue).status_id
2656 2661 assert_equal [1,2,5], assigns(:allowed_statuses).map(&:id).sort
2657 2662 end
2658 2663
2659 2664 def test_update_edit_form_with_project_change
2660 2665 @request.session[:user_id] = 2
2661 2666 xhr :put, :new, :project_id => 1,
2662 2667 :id => 1,
2663 2668 :issue => {:project_id => 2,
2664 2669 :tracker_id => 2,
2665 2670 :subject => 'This is the test_new issue',
2666 2671 :description => 'This is the description',
2667 2672 :priority_id => 5}
2668 2673 assert_response :success
2669 2674 assert_template 'form'
2670 2675
2671 2676 issue = assigns(:issue)
2672 2677 assert_kind_of Issue, issue
2673 2678 assert_equal 1, issue.id
2674 2679 assert_equal 2, issue.project_id
2675 2680 assert_equal 2, issue.tracker_id
2676 2681 assert_equal 'This is the test_new issue', issue.subject
2677 2682 end
2678 2683
2679 2684 def test_put_update_without_custom_fields_param
2680 2685 @request.session[:user_id] = 2
2681 2686 ActionMailer::Base.deliveries.clear
2682 2687
2683 2688 issue = Issue.find(1)
2684 2689 assert_equal '125', issue.custom_value_for(2).value
2685 2690 old_subject = issue.subject
2686 2691 new_subject = 'Subject modified by IssuesControllerTest#test_post_edit'
2687 2692
2688 2693 assert_difference('Journal.count') do
2689 2694 assert_difference('JournalDetail.count', 2) do
2690 2695 put :update, :id => 1, :issue => {:subject => new_subject,
2691 2696 :priority_id => '6',
2692 2697 :category_id => '1' # no change
2693 2698 }
2694 2699 end
2695 2700 end
2696 2701 assert_redirected_to :action => 'show', :id => '1'
2697 2702 issue.reload
2698 2703 assert_equal new_subject, issue.subject
2699 2704 # Make sure custom fields were not cleared
2700 2705 assert_equal '125', issue.custom_value_for(2).value
2701 2706
2702 2707 mail = ActionMailer::Base.deliveries.last
2703 2708 assert_not_nil mail
2704 2709 assert mail.subject.starts_with?("[#{issue.project.name} - #{issue.tracker.name} ##{issue.id}]")
2705 2710 assert_mail_body_match "Subject changed from #{old_subject} to #{new_subject}", mail
2706 2711 end
2707 2712
2708 2713 def test_put_update_with_project_change
2709 2714 @request.session[:user_id] = 2
2710 2715 ActionMailer::Base.deliveries.clear
2711 2716
2712 2717 assert_difference('Journal.count') do
2713 2718 assert_difference('JournalDetail.count', 3) do
2714 2719 put :update, :id => 1, :issue => {:project_id => '2',
2715 2720 :tracker_id => '1', # no change
2716 2721 :priority_id => '6',
2717 2722 :category_id => '3'
2718 2723 }
2719 2724 end
2720 2725 end
2721 2726 assert_redirected_to :action => 'show', :id => '1'
2722 2727 issue = Issue.find(1)
2723 2728 assert_equal 2, issue.project_id
2724 2729 assert_equal 1, issue.tracker_id
2725 2730 assert_equal 6, issue.priority_id
2726 2731 assert_equal 3, issue.category_id
2727 2732
2728 2733 mail = ActionMailer::Base.deliveries.last
2729 2734 assert_not_nil mail
2730 2735 assert mail.subject.starts_with?("[#{issue.project.name} - #{issue.tracker.name} ##{issue.id}]")
2731 2736 assert_mail_body_match "Project changed from eCookbook to OnlineStore", mail
2732 2737 end
2733 2738
2734 2739 def test_put_update_with_tracker_change
2735 2740 @request.session[:user_id] = 2
2736 2741 ActionMailer::Base.deliveries.clear
2737 2742
2738 2743 assert_difference('Journal.count') do
2739 2744 assert_difference('JournalDetail.count', 2) do
2740 2745 put :update, :id => 1, :issue => {:project_id => '1',
2741 2746 :tracker_id => '2',
2742 2747 :priority_id => '6'
2743 2748 }
2744 2749 end
2745 2750 end
2746 2751 assert_redirected_to :action => 'show', :id => '1'
2747 2752 issue = Issue.find(1)
2748 2753 assert_equal 1, issue.project_id
2749 2754 assert_equal 2, issue.tracker_id
2750 2755 assert_equal 6, issue.priority_id
2751 2756 assert_equal 1, issue.category_id
2752 2757
2753 2758 mail = ActionMailer::Base.deliveries.last
2754 2759 assert_not_nil mail
2755 2760 assert mail.subject.starts_with?("[#{issue.project.name} - #{issue.tracker.name} ##{issue.id}]")
2756 2761 assert_mail_body_match "Tracker changed from Bug to Feature request", mail
2757 2762 end
2758 2763
2759 2764 def test_put_update_with_custom_field_change
2760 2765 @request.session[:user_id] = 2
2761 2766 issue = Issue.find(1)
2762 2767 assert_equal '125', issue.custom_value_for(2).value
2763 2768
2764 2769 assert_difference('Journal.count') do
2765 2770 assert_difference('JournalDetail.count', 3) do
2766 2771 put :update, :id => 1, :issue => {:subject => 'Custom field change',
2767 2772 :priority_id => '6',
2768 2773 :category_id => '1', # no change
2769 2774 :custom_field_values => { '2' => 'New custom value' }
2770 2775 }
2771 2776 end
2772 2777 end
2773 2778 assert_redirected_to :action => 'show', :id => '1'
2774 2779 issue.reload
2775 2780 assert_equal 'New custom value', issue.custom_value_for(2).value
2776 2781
2777 2782 mail = ActionMailer::Base.deliveries.last
2778 2783 assert_not_nil mail
2779 2784 assert_mail_body_match "Searchable field changed from 125 to New custom value", mail
2780 2785 end
2781 2786
2782 2787 def test_put_update_with_multi_custom_field_change
2783 2788 field = CustomField.find(1)
2784 2789 field.update_attribute :multiple, true
2785 2790 issue = Issue.find(1)
2786 2791 issue.custom_field_values = {1 => ['MySQL', 'Oracle']}
2787 2792 issue.save!
2788 2793
2789 2794 @request.session[:user_id] = 2
2790 2795 assert_difference('Journal.count') do
2791 2796 assert_difference('JournalDetail.count', 3) do
2792 2797 put :update, :id => 1,
2793 2798 :issue => {
2794 2799 :subject => 'Custom field change',
2795 2800 :custom_field_values => { '1' => ['', 'Oracle', 'PostgreSQL'] }
2796 2801 }
2797 2802 end
2798 2803 end
2799 2804 assert_redirected_to :action => 'show', :id => '1'
2800 2805 assert_equal ['Oracle', 'PostgreSQL'], Issue.find(1).custom_field_value(1).sort
2801 2806 end
2802 2807
2803 2808 def test_put_update_with_status_and_assignee_change
2804 2809 issue = Issue.find(1)
2805 2810 assert_equal 1, issue.status_id
2806 2811 @request.session[:user_id] = 2
2807 2812 assert_difference('TimeEntry.count', 0) do
2808 2813 put :update,
2809 2814 :id => 1,
2810 2815 :issue => { :status_id => 2, :assigned_to_id => 3, :notes => 'Assigned to dlopper' },
2811 2816 :time_entry => { :hours => '', :comments => '', :activity_id => TimeEntryActivity.first }
2812 2817 end
2813 2818 assert_redirected_to :action => 'show', :id => '1'
2814 2819 issue.reload
2815 2820 assert_equal 2, issue.status_id
2816 2821 j = Journal.order('id DESC').first
2817 2822 assert_equal 'Assigned to dlopper', j.notes
2818 2823 assert_equal 2, j.details.size
2819 2824
2820 2825 mail = ActionMailer::Base.deliveries.last
2821 2826 assert_mail_body_match "Status changed from New to Assigned", mail
2822 2827 # subject should contain the new status
2823 2828 assert mail.subject.include?("(#{ IssueStatus.find(2).name })")
2824 2829 end
2825 2830
2826 2831 def test_put_update_with_note_only
2827 2832 notes = 'Note added by IssuesControllerTest#test_update_with_note_only'
2828 2833 # anonymous user
2829 2834 put :update,
2830 2835 :id => 1,
2831 2836 :issue => { :notes => notes }
2832 2837 assert_redirected_to :action => 'show', :id => '1'
2833 2838 j = Journal.order('id DESC').first
2834 2839 assert_equal notes, j.notes
2835 2840 assert_equal 0, j.details.size
2836 2841 assert_equal User.anonymous, j.user
2837 2842
2838 2843 mail = ActionMailer::Base.deliveries.last
2839 2844 assert_mail_body_match notes, mail
2840 2845 end
2841 2846
2842 2847 def test_put_update_with_private_note_only
2843 2848 notes = 'Private note'
2844 2849 @request.session[:user_id] = 2
2845 2850
2846 2851 assert_difference 'Journal.count' do
2847 2852 put :update, :id => 1, :issue => {:notes => notes, :private_notes => '1'}
2848 2853 assert_redirected_to :action => 'show', :id => '1'
2849 2854 end
2850 2855
2851 2856 j = Journal.order('id DESC').first
2852 2857 assert_equal notes, j.notes
2853 2858 assert_equal true, j.private_notes
2854 2859 end
2855 2860
2856 2861 def test_put_update_with_private_note_and_changes
2857 2862 notes = 'Private note'
2858 2863 @request.session[:user_id] = 2
2859 2864
2860 2865 assert_difference 'Journal.count', 2 do
2861 2866 put :update, :id => 1, :issue => {:subject => 'New subject', :notes => notes, :private_notes => '1'}
2862 2867 assert_redirected_to :action => 'show', :id => '1'
2863 2868 end
2864 2869
2865 2870 j = Journal.order('id DESC').first
2866 2871 assert_equal notes, j.notes
2867 2872 assert_equal true, j.private_notes
2868 2873 assert_equal 0, j.details.count
2869 2874
2870 2875 j = Journal.order('id DESC').offset(1).first
2871 2876 assert_nil j.notes
2872 2877 assert_equal false, j.private_notes
2873 2878 assert_equal 1, j.details.count
2874 2879 end
2875 2880
2876 2881 def test_put_update_with_note_and_spent_time
2877 2882 @request.session[:user_id] = 2
2878 2883 spent_hours_before = Issue.find(1).spent_hours
2879 2884 assert_difference('TimeEntry.count') do
2880 2885 put :update,
2881 2886 :id => 1,
2882 2887 :issue => { :notes => '2.5 hours added' },
2883 2888 :time_entry => { :hours => '2.5', :comments => 'test_put_update_with_note_and_spent_time', :activity_id => TimeEntryActivity.first.id }
2884 2889 end
2885 2890 assert_redirected_to :action => 'show', :id => '1'
2886 2891
2887 2892 issue = Issue.find(1)
2888 2893
2889 2894 j = Journal.order('id DESC').first
2890 2895 assert_equal '2.5 hours added', j.notes
2891 2896 assert_equal 0, j.details.size
2892 2897
2893 2898 t = issue.time_entries.find_by_comments('test_put_update_with_note_and_spent_time')
2894 2899 assert_not_nil t
2895 2900 assert_equal 2.5, t.hours
2896 2901 assert_equal spent_hours_before + 2.5, issue.spent_hours
2897 2902 end
2898 2903
2899 2904 def test_put_update_with_attachment_only
2900 2905 set_tmp_attachments_directory
2901 2906
2902 2907 # Delete all fixtured journals, a race condition can occur causing the wrong
2903 2908 # journal to get fetched in the next find.
2904 2909 Journal.delete_all
2905 2910
2906 2911 # anonymous user
2907 2912 assert_difference 'Attachment.count' do
2908 2913 put :update, :id => 1,
2909 2914 :issue => {:notes => ''},
2910 2915 :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain'), 'description' => 'test file'}}
2911 2916 end
2912 2917
2913 2918 assert_redirected_to :action => 'show', :id => '1'
2914 2919 j = Issue.find(1).journals.reorder('id DESC').first
2915 2920 assert j.notes.blank?
2916 2921 assert_equal 1, j.details.size
2917 2922 assert_equal 'testfile.txt', j.details.first.value
2918 2923 assert_equal User.anonymous, j.user
2919 2924
2920 2925 attachment = Attachment.first(:order => 'id DESC')
2921 2926 assert_equal Issue.find(1), attachment.container
2922 2927 assert_equal User.anonymous, attachment.author
2923 2928 assert_equal 'testfile.txt', attachment.filename
2924 2929 assert_equal 'text/plain', attachment.content_type
2925 2930 assert_equal 'test file', attachment.description
2926 2931 assert_equal 59, attachment.filesize
2927 2932 assert File.exists?(attachment.diskfile)
2928 2933 assert_equal 59, File.size(attachment.diskfile)
2929 2934
2930 2935 mail = ActionMailer::Base.deliveries.last
2931 2936 assert_mail_body_match 'testfile.txt', mail
2932 2937 end
2933 2938
2934 2939 def test_put_update_with_failure_should_save_attachments
2935 2940 set_tmp_attachments_directory
2936 2941 @request.session[:user_id] = 2
2937 2942
2938 2943 assert_no_difference 'Journal.count' do
2939 2944 assert_difference 'Attachment.count' do
2940 2945 put :update, :id => 1,
2941 2946 :issue => { :subject => '' },
2942 2947 :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain'), 'description' => 'test file'}}
2943 2948 assert_response :success
2944 2949 assert_template 'edit'
2945 2950 end
2946 2951 end
2947 2952
2948 2953 attachment = Attachment.first(:order => 'id DESC')
2949 2954 assert_equal 'testfile.txt', attachment.filename
2950 2955 assert File.exists?(attachment.diskfile)
2951 2956 assert_nil attachment.container
2952 2957
2953 2958 assert_tag 'input', :attributes => {:name => 'attachments[p0][token]', :value => attachment.token}
2954 2959 assert_tag 'span', :content => /testfile.txt/
2955 2960 end
2956 2961
2957 2962 def test_put_update_with_failure_should_keep_saved_attachments
2958 2963 set_tmp_attachments_directory
2959 2964 attachment = Attachment.create!(:file => uploaded_test_file("testfile.txt", "text/plain"), :author_id => 2)
2960 2965 @request.session[:user_id] = 2
2961 2966
2962 2967 assert_no_difference 'Journal.count' do
2963 2968 assert_no_difference 'Attachment.count' do
2964 2969 put :update, :id => 1,
2965 2970 :issue => { :subject => '' },
2966 2971 :attachments => {'p0' => {'token' => attachment.token}}
2967 2972 assert_response :success
2968 2973 assert_template 'edit'
2969 2974 end
2970 2975 end
2971 2976
2972 2977 assert_tag 'input', :attributes => {:name => 'attachments[p0][token]', :value => attachment.token}
2973 2978 assert_tag 'span', :content => /testfile.txt/
2974 2979 end
2975 2980
2976 2981 def test_put_update_should_attach_saved_attachments
2977 2982 set_tmp_attachments_directory
2978 2983 attachment = Attachment.create!(:file => uploaded_test_file("testfile.txt", "text/plain"), :author_id => 2)
2979 2984 @request.session[:user_id] = 2
2980 2985
2981 2986 assert_difference 'Journal.count' do
2982 2987 assert_difference 'JournalDetail.count' do
2983 2988 assert_no_difference 'Attachment.count' do
2984 2989 put :update, :id => 1,
2985 2990 :issue => {:notes => 'Attachment added'},
2986 2991 :attachments => {'p0' => {'token' => attachment.token}}
2987 2992 assert_redirected_to '/issues/1'
2988 2993 end
2989 2994 end
2990 2995 end
2991 2996
2992 2997 attachment.reload
2993 2998 assert_equal Issue.find(1), attachment.container
2994 2999
2995 3000 journal = Journal.first(:order => 'id DESC')
2996 3001 assert_equal 1, journal.details.size
2997 3002 assert_equal 'testfile.txt', journal.details.first.value
2998 3003 end
2999 3004
3000 3005 def test_put_update_with_attachment_that_fails_to_save
3001 3006 set_tmp_attachments_directory
3002 3007
3003 3008 # Delete all fixtured journals, a race condition can occur causing the wrong
3004 3009 # journal to get fetched in the next find.
3005 3010 Journal.delete_all
3006 3011
3007 3012 # Mock out the unsaved attachment
3008 3013 Attachment.any_instance.stubs(:create).returns(Attachment.new)
3009 3014
3010 3015 # anonymous user
3011 3016 put :update,
3012 3017 :id => 1,
3013 3018 :issue => {:notes => ''},
3014 3019 :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain')}}
3015 3020 assert_redirected_to :action => 'show', :id => '1'
3016 3021 assert_equal '1 file(s) could not be saved.', flash[:warning]
3017 3022 end
3018 3023
3019 3024 def test_put_update_with_no_change
3020 3025 issue = Issue.find(1)
3021 3026 issue.journals.clear
3022 3027 ActionMailer::Base.deliveries.clear
3023 3028
3024 3029 put :update,
3025 3030 :id => 1,
3026 3031 :issue => {:notes => ''}
3027 3032 assert_redirected_to :action => 'show', :id => '1'
3028 3033
3029 3034 issue.reload
3030 3035 assert issue.journals.empty?
3031 3036 # No email should be sent
3032 3037 assert ActionMailer::Base.deliveries.empty?
3033 3038 end
3034 3039
3035 3040 def test_put_update_should_send_a_notification
3036 3041 @request.session[:user_id] = 2
3037 3042 ActionMailer::Base.deliveries.clear
3038 3043 issue = Issue.find(1)
3039 3044 old_subject = issue.subject
3040 3045 new_subject = 'Subject modified by IssuesControllerTest#test_post_edit'
3041 3046
3042 3047 put :update, :id => 1, :issue => {:subject => new_subject,
3043 3048 :priority_id => '6',
3044 3049 :category_id => '1' # no change
3045 3050 }
3046 3051 assert_equal 1, ActionMailer::Base.deliveries.size
3047 3052 end
3048 3053
3049 3054 def test_put_update_with_invalid_spent_time_hours_only
3050 3055 @request.session[:user_id] = 2
3051 3056 notes = 'Note added by IssuesControllerTest#test_post_edit_with_invalid_spent_time'
3052 3057
3053 3058 assert_no_difference('Journal.count') do
3054 3059 put :update,
3055 3060 :id => 1,
3056 3061 :issue => {:notes => notes},
3057 3062 :time_entry => {"comments"=>"", "activity_id"=>"", "hours"=>"2z"}
3058 3063 end
3059 3064 assert_response :success
3060 3065 assert_template 'edit'
3061 3066
3062 3067 assert_error_tag :descendant => {:content => /Activity can&#x27;t be blank/}
3063 3068 assert_tag :textarea, :attributes => { :name => 'issue[notes]' }, :content => "\n"+notes
3064 3069 assert_tag :input, :attributes => { :name => 'time_entry[hours]', :value => "2z" }
3065 3070 end
3066 3071
3067 3072 def test_put_update_with_invalid_spent_time_comments_only
3068 3073 @request.session[:user_id] = 2
3069 3074 notes = 'Note added by IssuesControllerTest#test_post_edit_with_invalid_spent_time'
3070 3075
3071 3076 assert_no_difference('Journal.count') do
3072 3077 put :update,
3073 3078 :id => 1,
3074 3079 :issue => {:notes => notes},
3075 3080 :time_entry => {"comments"=>"this is my comment", "activity_id"=>"", "hours"=>""}
3076 3081 end
3077 3082 assert_response :success
3078 3083 assert_template 'edit'
3079 3084
3080 3085 assert_error_tag :descendant => {:content => /Activity can&#x27;t be blank/}
3081 3086 assert_error_tag :descendant => {:content => /Hours can&#x27;t be blank/}
3082 3087 assert_tag :textarea, :attributes => { :name => 'issue[notes]' }, :content => "\n"+notes
3083 3088 assert_tag :input, :attributes => { :name => 'time_entry[comments]', :value => "this is my comment" }
3084 3089 end
3085 3090
3086 3091 def test_put_update_should_allow_fixed_version_to_be_set_to_a_subproject
3087 3092 issue = Issue.find(2)
3088 3093 @request.session[:user_id] = 2
3089 3094
3090 3095 put :update,
3091 3096 :id => issue.id,
3092 3097 :issue => {
3093 3098 :fixed_version_id => 4
3094 3099 }
3095 3100
3096 3101 assert_response :redirect
3097 3102 issue.reload
3098 3103 assert_equal 4, issue.fixed_version_id
3099 3104 assert_not_equal issue.project_id, issue.fixed_version.project_id
3100 3105 end
3101 3106
3102 3107 def test_put_update_should_redirect_back_using_the_back_url_parameter
3103 3108 issue = Issue.find(2)
3104 3109 @request.session[:user_id] = 2
3105 3110
3106 3111 put :update,
3107 3112 :id => issue.id,
3108 3113 :issue => {
3109 3114 :fixed_version_id => 4
3110 3115 },
3111 3116 :back_url => '/issues'
3112 3117
3113 3118 assert_response :redirect
3114 3119 assert_redirected_to '/issues'
3115 3120 end
3116 3121
3117 3122 def test_put_update_should_not_redirect_back_using_the_back_url_parameter_off_the_host
3118 3123 issue = Issue.find(2)
3119 3124 @request.session[:user_id] = 2
3120 3125
3121 3126 put :update,
3122 3127 :id => issue.id,
3123 3128 :issue => {
3124 3129 :fixed_version_id => 4
3125 3130 },
3126 3131 :back_url => 'http://google.com'
3127 3132
3128 3133 assert_response :redirect
3129 3134 assert_redirected_to :controller => 'issues', :action => 'show', :id => issue.id
3130 3135 end
3131 3136
3132 3137 def test_get_bulk_edit
3133 3138 @request.session[:user_id] = 2
3134 3139 get :bulk_edit, :ids => [1, 2]
3135 3140 assert_response :success
3136 3141 assert_template 'bulk_edit'
3137 3142
3138 3143 assert_tag :select, :attributes => {:name => 'issue[project_id]'}
3139 3144 assert_tag :input, :attributes => {:name => 'issue[parent_issue_id]'}
3140 3145
3141 3146 # Project specific custom field, date type
3142 3147 field = CustomField.find(9)
3143 3148 assert !field.is_for_all?
3144 3149 assert_equal 'date', field.field_format
3145 3150 assert_tag :input, :attributes => {:name => 'issue[custom_field_values][9]'}
3146 3151
3147 3152 # System wide custom field
3148 3153 assert CustomField.find(1).is_for_all?
3149 3154 assert_tag :select, :attributes => {:name => 'issue[custom_field_values][1]'}
3150 3155
3151 3156 # Be sure we don't display inactive IssuePriorities
3152 3157 assert ! IssuePriority.find(15).active?
3153 3158 assert_no_tag :option, :attributes => {:value => '15'},
3154 3159 :parent => {:tag => 'select', :attributes => {:id => 'issue_priority_id'} }
3155 3160 end
3156 3161
3157 3162 def test_get_bulk_edit_on_different_projects
3158 3163 @request.session[:user_id] = 2
3159 3164 get :bulk_edit, :ids => [1, 2, 6]
3160 3165 assert_response :success
3161 3166 assert_template 'bulk_edit'
3162 3167
3163 3168 # Can not set issues from different projects as children of an issue
3164 3169 assert_no_tag :input, :attributes => {:name => 'issue[parent_issue_id]'}
3165 3170
3166 3171 # Project specific custom field, date type
3167 3172 field = CustomField.find(9)
3168 3173 assert !field.is_for_all?
3169 3174 assert !field.project_ids.include?(Issue.find(6).project_id)
3170 3175 assert_no_tag :input, :attributes => {:name => 'issue[custom_field_values][9]'}
3171 3176 end
3172 3177
3173 3178 def test_get_bulk_edit_with_user_custom_field
3174 3179 field = IssueCustomField.create!(:name => 'Tester', :field_format => 'user', :is_for_all => true)
3175 3180
3176 3181 @request.session[:user_id] = 2
3177 3182 get :bulk_edit, :ids => [1, 2]
3178 3183 assert_response :success
3179 3184 assert_template 'bulk_edit'
3180 3185
3181 3186 assert_tag :select,
3182 3187 :attributes => {:name => "issue[custom_field_values][#{field.id}]", :class => 'user_cf'},
3183 3188 :children => {
3184 3189 :only => {:tag => 'option'},
3185 3190 :count => Project.find(1).users.count + 2 # "no change" + "none" options
3186 3191 }
3187 3192 end
3188 3193
3189 3194 def test_get_bulk_edit_with_version_custom_field
3190 3195 field = IssueCustomField.create!(:name => 'Affected version', :field_format => 'version', :is_for_all => true)
3191 3196
3192 3197 @request.session[:user_id] = 2
3193 3198 get :bulk_edit, :ids => [1, 2]
3194 3199 assert_response :success
3195 3200 assert_template 'bulk_edit'
3196 3201
3197 3202 assert_tag :select,
3198 3203 :attributes => {:name => "issue[custom_field_values][#{field.id}]"},
3199 3204 :children => {
3200 3205 :only => {:tag => 'option'},
3201 3206 :count => Project.find(1).shared_versions.count + 2 # "no change" + "none" options
3202 3207 }
3203 3208 end
3204 3209
3205 3210 def test_get_bulk_edit_with_multi_custom_field
3206 3211 field = CustomField.find(1)
3207 3212 field.update_attribute :multiple, true
3208 3213
3209 3214 @request.session[:user_id] = 2
3210 3215 get :bulk_edit, :ids => [1, 2]
3211 3216 assert_response :success
3212 3217 assert_template 'bulk_edit'
3213 3218
3214 3219 assert_tag :select,
3215 3220 :attributes => {:name => "issue[custom_field_values][1][]"},
3216 3221 :children => {
3217 3222 :only => {:tag => 'option'},
3218 3223 :count => field.possible_values.size + 1 # "none" options
3219 3224 }
3220 3225 end
3221 3226
3222 3227 def test_bulk_edit_should_only_propose_statuses_allowed_for_all_issues
3223 3228 WorkflowTransition.delete_all
3224 3229 WorkflowTransition.create!(:role_id => 1, :tracker_id => 1, :old_status_id => 1, :new_status_id => 1)
3225 3230 WorkflowTransition.create!(:role_id => 1, :tracker_id => 1, :old_status_id => 1, :new_status_id => 3)
3226 3231 WorkflowTransition.create!(:role_id => 1, :tracker_id => 1, :old_status_id => 1, :new_status_id => 4)
3227 3232 WorkflowTransition.create!(:role_id => 1, :tracker_id => 2, :old_status_id => 2, :new_status_id => 1)
3228 3233 WorkflowTransition.create!(:role_id => 1, :tracker_id => 2, :old_status_id => 2, :new_status_id => 3)
3229 3234 WorkflowTransition.create!(:role_id => 1, :tracker_id => 2, :old_status_id => 2, :new_status_id => 5)
3230 3235 @request.session[:user_id] = 2
3231 3236 get :bulk_edit, :ids => [1, 2]
3232 3237
3233 3238 assert_response :success
3234 3239 statuses = assigns(:available_statuses)
3235 3240 assert_not_nil statuses
3236 3241 assert_equal [1, 3], statuses.map(&:id).sort
3237 3242
3238 3243 assert_tag 'select', :attributes => {:name => 'issue[status_id]'},
3239 3244 :children => {:count => 3} # 2 statuses + "no change" option
3240 3245 end
3241 3246
3242 3247 def test_bulk_edit_should_propose_target_project_open_shared_versions
3243 3248 @request.session[:user_id] = 2
3244 3249 post :bulk_edit, :ids => [1, 2, 6], :issue => {:project_id => 1}
3245 3250 assert_response :success
3246 3251 assert_template 'bulk_edit'
3247 3252 assert_equal Project.find(1).shared_versions.open.all.sort, assigns(:versions).sort
3248 3253 assert_tag 'select',
3249 3254 :attributes => {:name => 'issue[fixed_version_id]'},
3250 3255 :descendant => {:tag => 'option', :content => '2.0'}
3251 3256 end
3252 3257
3253 3258 def test_bulk_edit_should_propose_target_project_categories
3254 3259 @request.session[:user_id] = 2
3255 3260 post :bulk_edit, :ids => [1, 2, 6], :issue => {:project_id => 1}
3256 3261 assert_response :success
3257 3262 assert_template 'bulk_edit'
3258 3263 assert_equal Project.find(1).issue_categories.sort, assigns(:categories).sort
3259 3264 assert_tag 'select',
3260 3265 :attributes => {:name => 'issue[category_id]'},
3261 3266 :descendant => {:tag => 'option', :content => 'Recipes'}
3262 3267 end
3263 3268
3264 3269 def test_bulk_update
3265 3270 @request.session[:user_id] = 2
3266 3271 # update issues priority
3267 3272 post :bulk_update, :ids => [1, 2], :notes => 'Bulk editing',
3268 3273 :issue => {:priority_id => 7,
3269 3274 :assigned_to_id => '',
3270 3275 :custom_field_values => {'2' => ''}}
3271 3276
3272 3277 assert_response 302
3273 3278 # check that the issues were updated
3274 3279 assert_equal [7, 7], Issue.find_all_by_id([1, 2]).collect {|i| i.priority.id}
3275 3280
3276 3281 issue = Issue.find(1)
3277 3282 journal = issue.journals.reorder('created_on DESC').first
3278 3283 assert_equal '125', issue.custom_value_for(2).value
3279 3284 assert_equal 'Bulk editing', journal.notes
3280 3285 assert_equal 1, journal.details.size
3281 3286 end
3282 3287
3283 3288 def test_bulk_update_with_group_assignee
3284 3289 group = Group.find(11)
3285 3290 project = Project.find(1)
3286 3291 project.members << Member.new(:principal => group, :roles => [Role.givable.first])
3287 3292
3288 3293 @request.session[:user_id] = 2
3289 3294 # update issues assignee
3290 3295 post :bulk_update, :ids => [1, 2], :notes => 'Bulk editing',
3291 3296 :issue => {:priority_id => '',
3292 3297 :assigned_to_id => group.id,
3293 3298 :custom_field_values => {'2' => ''}}
3294 3299
3295 3300 assert_response 302
3296 3301 assert_equal [group, group], Issue.find_all_by_id([1, 2]).collect {|i| i.assigned_to}
3297 3302 end
3298 3303
3299 3304 def test_bulk_update_on_different_projects
3300 3305 @request.session[:user_id] = 2
3301 3306 # update issues priority
3302 3307 post :bulk_update, :ids => [1, 2, 6], :notes => 'Bulk editing',
3303 3308 :issue => {:priority_id => 7,
3304 3309 :assigned_to_id => '',
3305 3310 :custom_field_values => {'2' => ''}}
3306 3311
3307 3312 assert_response 302
3308 3313 # check that the issues were updated
3309 3314 assert_equal [7, 7, 7], Issue.find([1,2,6]).map(&:priority_id)
3310 3315
3311 3316 issue = Issue.find(1)
3312 3317 journal = issue.journals.reorder('created_on DESC').first
3313 3318 assert_equal '125', issue.custom_value_for(2).value
3314 3319 assert_equal 'Bulk editing', journal.notes
3315 3320 assert_equal 1, journal.details.size
3316 3321 end
3317 3322
3318 3323 def test_bulk_update_on_different_projects_without_rights
3319 3324 @request.session[:user_id] = 3
3320 3325 user = User.find(3)
3321 3326 action = { :controller => "issues", :action => "bulk_update" }
3322 3327 assert user.allowed_to?(action, Issue.find(1).project)
3323 3328 assert ! user.allowed_to?(action, Issue.find(6).project)
3324 3329 post :bulk_update, :ids => [1, 6], :notes => 'Bulk should fail',
3325 3330 :issue => {:priority_id => 7,
3326 3331 :assigned_to_id => '',
3327 3332 :custom_field_values => {'2' => ''}}
3328 3333 assert_response 403
3329 3334 assert_not_equal "Bulk should fail", Journal.last.notes
3330 3335 end
3331 3336
3332 3337 def test_bullk_update_should_send_a_notification
3333 3338 @request.session[:user_id] = 2
3334 3339 ActionMailer::Base.deliveries.clear
3335 3340 post(:bulk_update,
3336 3341 {
3337 3342 :ids => [1, 2],
3338 3343 :notes => 'Bulk editing',
3339 3344 :issue => {
3340 3345 :priority_id => 7,
3341 3346 :assigned_to_id => '',
3342 3347 :custom_field_values => {'2' => ''}
3343 3348 }
3344 3349 })
3345 3350
3346 3351 assert_response 302
3347 3352 assert_equal 2, ActionMailer::Base.deliveries.size
3348 3353 end
3349 3354
3350 3355 def test_bulk_update_project
3351 3356 @request.session[:user_id] = 2
3352 3357 post :bulk_update, :ids => [1, 2], :issue => {:project_id => '2'}
3353 3358 assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook'
3354 3359 # Issues moved to project 2
3355 3360 assert_equal 2, Issue.find(1).project_id
3356 3361 assert_equal 2, Issue.find(2).project_id
3357 3362 # No tracker change
3358 3363 assert_equal 1, Issue.find(1).tracker_id
3359 3364 assert_equal 2, Issue.find(2).tracker_id
3360 3365 end
3361 3366
3362 3367 def test_bulk_update_project_on_single_issue_should_follow_when_needed
3363 3368 @request.session[:user_id] = 2
3364 3369 post :bulk_update, :id => 1, :issue => {:project_id => '2'}, :follow => '1'
3365 3370 assert_redirected_to '/issues/1'
3366 3371 end
3367 3372
3368 3373 def test_bulk_update_project_on_multiple_issues_should_follow_when_needed
3369 3374 @request.session[:user_id] = 2
3370 3375 post :bulk_update, :id => [1, 2], :issue => {:project_id => '2'}, :follow => '1'
3371 3376 assert_redirected_to '/projects/onlinestore/issues'
3372 3377 end
3373 3378
3374 3379 def test_bulk_update_tracker
3375 3380 @request.session[:user_id] = 2
3376 3381 post :bulk_update, :ids => [1, 2], :issue => {:tracker_id => '2'}
3377 3382 assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook'
3378 3383 assert_equal 2, Issue.find(1).tracker_id
3379 3384 assert_equal 2, Issue.find(2).tracker_id
3380 3385 end
3381 3386
3382 3387 def test_bulk_update_status
3383 3388 @request.session[:user_id] = 2
3384 3389 # update issues priority
3385 3390 post :bulk_update, :ids => [1, 2], :notes => 'Bulk editing status',
3386 3391 :issue => {:priority_id => '',
3387 3392 :assigned_to_id => '',
3388 3393 :status_id => '5'}
3389 3394
3390 3395 assert_response 302
3391 3396 issue = Issue.find(1)
3392 3397 assert issue.closed?
3393 3398 end
3394 3399
3395 3400 def test_bulk_update_priority
3396 3401 @request.session[:user_id] = 2
3397 3402 post :bulk_update, :ids => [1, 2], :issue => {:priority_id => 6}
3398 3403
3399 3404 assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook'
3400 3405 assert_equal 6, Issue.find(1).priority_id
3401 3406 assert_equal 6, Issue.find(2).priority_id
3402 3407 end
3403 3408
3404 3409 def test_bulk_update_with_notes
3405 3410 @request.session[:user_id] = 2
3406 3411 post :bulk_update, :ids => [1, 2], :notes => 'Moving two issues'
3407 3412
3408 3413 assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook'
3409 3414 assert_equal 'Moving two issues', Issue.find(1).journals.sort_by(&:id).last.notes
3410 3415 assert_equal 'Moving two issues', Issue.find(2).journals.sort_by(&:id).last.notes
3411 3416 end
3412 3417
3413 3418 def test_bulk_update_parent_id
3414 3419 @request.session[:user_id] = 2
3415 3420 post :bulk_update, :ids => [1, 3],
3416 3421 :notes => 'Bulk editing parent',
3417 3422 :issue => {:priority_id => '', :assigned_to_id => '', :status_id => '', :parent_issue_id => '2'}
3418 3423
3419 3424 assert_response 302
3420 3425 parent = Issue.find(2)
3421 3426 assert_equal parent.id, Issue.find(1).parent_id
3422 3427 assert_equal parent.id, Issue.find(3).parent_id
3423 3428 assert_equal [1, 3], parent.children.collect(&:id).sort
3424 3429 end
3425 3430
3426 3431 def test_bulk_update_custom_field
3427 3432 @request.session[:user_id] = 2
3428 3433 # update issues priority
3429 3434 post :bulk_update, :ids => [1, 2], :notes => 'Bulk editing custom field',
3430 3435 :issue => {:priority_id => '',
3431 3436 :assigned_to_id => '',
3432 3437 :custom_field_values => {'2' => '777'}}
3433 3438
3434 3439 assert_response 302
3435 3440
3436 3441 issue = Issue.find(1)
3437 3442 journal = issue.journals.reorder('created_on DESC').first
3438 3443 assert_equal '777', issue.custom_value_for(2).value
3439 3444 assert_equal 1, journal.details.size
3440 3445 assert_equal '125', journal.details.first.old_value
3441 3446 assert_equal '777', journal.details.first.value
3442 3447 end
3443 3448
3444 3449 def test_bulk_update_custom_field_to_blank
3445 3450 @request.session[:user_id] = 2
3446 3451 post :bulk_update, :ids => [1, 3], :notes => 'Bulk editing custom field',
3447 3452 :issue => {:priority_id => '',
3448 3453 :assigned_to_id => '',
3449 3454 :custom_field_values => {'1' => '__none__'}}
3450 3455 assert_response 302
3451 3456 assert_equal '', Issue.find(1).custom_field_value(1)
3452 3457 assert_equal '', Issue.find(3).custom_field_value(1)
3453 3458 end
3454 3459
3455 3460 def test_bulk_update_multi_custom_field
3456 3461 field = CustomField.find(1)
3457 3462 field.update_attribute :multiple, true
3458 3463
3459 3464 @request.session[:user_id] = 2
3460 3465 post :bulk_update, :ids => [1, 2, 3], :notes => 'Bulk editing multi custom field',
3461 3466 :issue => {:priority_id => '',
3462 3467 :assigned_to_id => '',
3463 3468 :custom_field_values => {'1' => ['MySQL', 'Oracle']}}
3464 3469
3465 3470 assert_response 302
3466 3471
3467 3472 assert_equal ['MySQL', 'Oracle'], Issue.find(1).custom_field_value(1).sort
3468 3473 assert_equal ['MySQL', 'Oracle'], Issue.find(3).custom_field_value(1).sort
3469 3474 # the custom field is not associated with the issue tracker
3470 3475 assert_nil Issue.find(2).custom_field_value(1)
3471 3476 end
3472 3477
3473 3478 def test_bulk_update_multi_custom_field_to_blank
3474 3479 field = CustomField.find(1)
3475 3480 field.update_attribute :multiple, true
3476 3481
3477 3482 @request.session[:user_id] = 2
3478 3483 post :bulk_update, :ids => [1, 3], :notes => 'Bulk editing multi custom field',
3479 3484 :issue => {:priority_id => '',
3480 3485 :assigned_to_id => '',
3481 3486 :custom_field_values => {'1' => ['__none__']}}
3482 3487 assert_response 302
3483 3488 assert_equal [''], Issue.find(1).custom_field_value(1)
3484 3489 assert_equal [''], Issue.find(3).custom_field_value(1)
3485 3490 end
3486 3491
3487 3492 def test_bulk_update_unassign
3488 3493 assert_not_nil Issue.find(2).assigned_to
3489 3494 @request.session[:user_id] = 2
3490 3495 # unassign issues
3491 3496 post :bulk_update, :ids => [1, 2], :notes => 'Bulk unassigning', :issue => {:assigned_to_id => 'none'}
3492 3497 assert_response 302
3493 3498 # check that the issues were updated
3494 3499 assert_nil Issue.find(2).assigned_to
3495 3500 end
3496 3501
3497 3502 def test_post_bulk_update_should_allow_fixed_version_to_be_set_to_a_subproject
3498 3503 @request.session[:user_id] = 2
3499 3504
3500 3505 post :bulk_update, :ids => [1,2], :issue => {:fixed_version_id => 4}
3501 3506
3502 3507 assert_response :redirect
3503 3508 issues = Issue.find([1,2])
3504 3509 issues.each do |issue|
3505 3510 assert_equal 4, issue.fixed_version_id
3506 3511 assert_not_equal issue.project_id, issue.fixed_version.project_id
3507 3512 end
3508 3513 end
3509 3514
3510 3515 def test_post_bulk_update_should_redirect_back_using_the_back_url_parameter
3511 3516 @request.session[:user_id] = 2
3512 3517 post :bulk_update, :ids => [1,2], :back_url => '/issues'
3513 3518
3514 3519 assert_response :redirect
3515 3520 assert_redirected_to '/issues'
3516 3521 end
3517 3522
3518 3523 def test_post_bulk_update_should_not_redirect_back_using_the_back_url_parameter_off_the_host
3519 3524 @request.session[:user_id] = 2
3520 3525 post :bulk_update, :ids => [1,2], :back_url => 'http://google.com'
3521 3526
3522 3527 assert_response :redirect
3523 3528 assert_redirected_to :controller => 'issues', :action => 'index', :project_id => Project.find(1).identifier
3524 3529 end
3525 3530
3526 3531 def test_bulk_update_with_failure_should_set_flash
3527 3532 @request.session[:user_id] = 2
3528 3533 Issue.update_all("subject = ''", "id = 2") # Make it invalid
3529 3534 post :bulk_update, :ids => [1, 2], :issue => {:priority_id => 6}
3530 3535
3531 3536 assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook'
3532 3537 assert_equal 'Failed to save 1 issue(s) on 2 selected: #2.', flash[:error]
3533 3538 end
3534 3539
3535 3540 def test_get_bulk_copy
3536 3541 @request.session[:user_id] = 2
3537 3542 get :bulk_edit, :ids => [1, 2, 3], :copy => '1'
3538 3543 assert_response :success
3539 3544 assert_template 'bulk_edit'
3540 3545
3541 3546 issues = assigns(:issues)
3542 3547 assert_not_nil issues
3543 3548 assert_equal [1, 2, 3], issues.map(&:id).sort
3544 3549
3545 3550 assert_select 'input[name=copy_attachments]'
3546 3551 end
3547 3552
3548 3553 def test_bulk_copy_to_another_project
3549 3554 @request.session[:user_id] = 2
3550 3555 assert_difference 'Issue.count', 2 do
3551 3556 assert_no_difference 'Project.find(1).issues.count' do
3552 3557 post :bulk_update, :ids => [1, 2], :issue => {:project_id => '2'}, :copy => '1'
3553 3558 end
3554 3559 end
3555 3560 assert_redirected_to '/projects/ecookbook/issues'
3556 3561
3557 3562 copies = Issue.all(:order => 'id DESC', :limit => issues.size)
3558 3563 copies.each do |copy|
3559 3564 assert_equal 2, copy.project_id
3560 3565 end
3561 3566 end
3562 3567
3563 3568 def test_bulk_copy_should_allow_not_changing_the_issue_attributes
3564 3569 @request.session[:user_id] = 2
3565 3570 issues = [
3566 3571 Issue.create!(:project_id => 1, :tracker_id => 1, :status_id => 1, :priority_id => 2, :subject => 'issue 1', :author_id => 1, :assigned_to_id => nil),
3567 3572 Issue.create!(:project_id => 2, :tracker_id => 3, :status_id => 2, :priority_id => 1, :subject => 'issue 2', :author_id => 2, :assigned_to_id => 3)
3568 3573 ]
3569 3574
3570 3575 assert_difference 'Issue.count', issues.size do
3571 3576 post :bulk_update, :ids => issues.map(&:id), :copy => '1',
3572 3577 :issue => {
3573 3578 :project_id => '', :tracker_id => '', :assigned_to_id => '',
3574 3579 :status_id => '', :start_date => '', :due_date => ''
3575 3580 }
3576 3581 end
3577 3582
3578 3583 copies = Issue.all(:order => 'id DESC', :limit => issues.size)
3579 3584 issues.each do |orig|
3580 3585 copy = copies.detect {|c| c.subject == orig.subject}
3581 3586 assert_not_nil copy
3582 3587 assert_equal orig.project_id, copy.project_id
3583 3588 assert_equal orig.tracker_id, copy.tracker_id
3584 3589 assert_equal orig.status_id, copy.status_id
3585 3590 assert_equal orig.assigned_to_id, copy.assigned_to_id
3586 3591 assert_equal orig.priority_id, copy.priority_id
3587 3592 end
3588 3593 end
3589 3594
3590 3595 def test_bulk_copy_should_allow_changing_the_issue_attributes
3591 3596 # Fixes random test failure with Mysql
3592 3597 # where Issue.all(:limit => 2, :order => 'id desc', :conditions => {:project_id => 2})
3593 3598 # doesn't return the expected results
3594 3599 Issue.delete_all("project_id=2")
3595 3600
3596 3601 @request.session[:user_id] = 2
3597 3602 assert_difference 'Issue.count', 2 do
3598 3603 assert_no_difference 'Project.find(1).issues.count' do
3599 3604 post :bulk_update, :ids => [1, 2], :copy => '1',
3600 3605 :issue => {
3601 3606 :project_id => '2', :tracker_id => '', :assigned_to_id => '4',
3602 3607 :status_id => '1', :start_date => '2009-12-01', :due_date => '2009-12-31'
3603 3608 }
3604 3609 end
3605 3610 end
3606 3611
3607 3612 copied_issues = Issue.all(:limit => 2, :order => 'id desc', :conditions => {:project_id => 2})
3608 3613 assert_equal 2, copied_issues.size
3609 3614 copied_issues.each do |issue|
3610 3615 assert_equal 2, issue.project_id, "Project is incorrect"
3611 3616 assert_equal 4, issue.assigned_to_id, "Assigned to is incorrect"
3612 3617 assert_equal 1, issue.status_id, "Status is incorrect"
3613 3618 assert_equal '2009-12-01', issue.start_date.to_s, "Start date is incorrect"
3614 3619 assert_equal '2009-12-31', issue.due_date.to_s, "Due date is incorrect"
3615 3620 end
3616 3621 end
3617 3622
3618 3623 def test_bulk_copy_should_allow_adding_a_note
3619 3624 @request.session[:user_id] = 2
3620 3625 assert_difference 'Issue.count', 1 do
3621 3626 post :bulk_update, :ids => [1], :copy => '1',
3622 3627 :notes => 'Copying one issue',
3623 3628 :issue => {
3624 3629 :project_id => '', :tracker_id => '', :assigned_to_id => '4',
3625 3630 :status_id => '3', :start_date => '2009-12-01', :due_date => '2009-12-31'
3626 3631 }
3627 3632 end
3628 3633
3629 3634 issue = Issue.first(:order => 'id DESC')
3630 3635 assert_equal 1, issue.journals.size
3631 3636 journal = issue.journals.first
3632 3637 assert_equal 0, journal.details.size
3633 3638 assert_equal 'Copying one issue', journal.notes
3634 3639 end
3635 3640
3636 3641 def test_bulk_copy_should_allow_not_copying_the_attachments
3637 3642 attachment_count = Issue.find(3).attachments.size
3638 3643 assert attachment_count > 0
3639 3644 @request.session[:user_id] = 2
3640 3645
3641 3646 assert_difference 'Issue.count', 1 do
3642 3647 assert_no_difference 'Attachment.count' do
3643 3648 post :bulk_update, :ids => [3], :copy => '1',
3644 3649 :issue => {
3645 3650 :project_id => ''
3646 3651 }
3647 3652 end
3648 3653 end
3649 3654 end
3650 3655
3651 3656 def test_bulk_copy_should_allow_copying_the_attachments
3652 3657 attachment_count = Issue.find(3).attachments.size
3653 3658 assert attachment_count > 0
3654 3659 @request.session[:user_id] = 2
3655 3660
3656 3661 assert_difference 'Issue.count', 1 do
3657 3662 assert_difference 'Attachment.count', attachment_count do
3658 3663 post :bulk_update, :ids => [3], :copy => '1', :copy_attachments => '1',
3659 3664 :issue => {
3660 3665 :project_id => ''
3661 3666 }
3662 3667 end
3663 3668 end
3664 3669 end
3665 3670
3666 3671 def test_bulk_copy_should_add_relations_with_copied_issues
3667 3672 @request.session[:user_id] = 2
3668 3673
3669 3674 assert_difference 'Issue.count', 2 do
3670 3675 assert_difference 'IssueRelation.count', 2 do
3671 3676 post :bulk_update, :ids => [1, 3], :copy => '1',
3672 3677 :issue => {
3673 3678 :project_id => '1'
3674 3679 }
3675 3680 end
3676 3681 end
3677 3682 end
3678 3683
3679 3684 def test_bulk_copy_should_allow_not_copying_the_subtasks
3680 3685 issue = Issue.generate_with_descendants!
3681 3686 @request.session[:user_id] = 2
3682 3687
3683 3688 assert_difference 'Issue.count', 1 do
3684 3689 post :bulk_update, :ids => [issue.id], :copy => '1',
3685 3690 :issue => {
3686 3691 :project_id => ''
3687 3692 }
3688 3693 end
3689 3694 end
3690 3695
3691 3696 def test_bulk_copy_should_allow_copying_the_subtasks
3692 3697 issue = Issue.generate_with_descendants!
3693 3698 count = issue.descendants.count
3694 3699 @request.session[:user_id] = 2
3695 3700
3696 3701 assert_difference 'Issue.count', count+1 do
3697 3702 post :bulk_update, :ids => [issue.id], :copy => '1', :copy_subtasks => '1',
3698 3703 :issue => {
3699 3704 :project_id => ''
3700 3705 }
3701 3706 end
3702 3707 copy = Issue.where(:parent_id => nil).order("id DESC").first
3703 3708 assert_equal count, copy.descendants.count
3704 3709 end
3705 3710
3706 3711 def test_bulk_copy_should_not_copy_selected_subtasks_twice
3707 3712 issue = Issue.generate_with_descendants!
3708 3713 count = issue.descendants.count
3709 3714 @request.session[:user_id] = 2
3710 3715
3711 3716 assert_difference 'Issue.count', count+1 do
3712 3717 post :bulk_update, :ids => issue.self_and_descendants.map(&:id), :copy => '1', :copy_subtasks => '1',
3713 3718 :issue => {
3714 3719 :project_id => ''
3715 3720 }
3716 3721 end
3717 3722 copy = Issue.where(:parent_id => nil).order("id DESC").first
3718 3723 assert_equal count, copy.descendants.count
3719 3724 end
3720 3725
3721 3726 def test_bulk_copy_to_another_project_should_follow_when_needed
3722 3727 @request.session[:user_id] = 2
3723 3728 post :bulk_update, :ids => [1], :copy => '1', :issue => {:project_id => 2}, :follow => '1'
3724 3729 issue = Issue.first(:order => 'id DESC')
3725 3730 assert_redirected_to :controller => 'issues', :action => 'show', :id => issue
3726 3731 end
3727 3732
3728 3733 def test_destroy_issue_with_no_time_entries
3729 3734 assert_nil TimeEntry.find_by_issue_id(2)
3730 3735 @request.session[:user_id] = 2
3731 3736
3732 3737 assert_difference 'Issue.count', -1 do
3733 3738 delete :destroy, :id => 2
3734 3739 end
3735 3740 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
3736 3741 assert_nil Issue.find_by_id(2)
3737 3742 end
3738 3743
3739 3744 def test_destroy_issues_with_time_entries
3740 3745 @request.session[:user_id] = 2
3741 3746
3742 3747 assert_no_difference 'Issue.count' do
3743 3748 delete :destroy, :ids => [1, 3]
3744 3749 end
3745 3750 assert_response :success
3746 3751 assert_template 'destroy'
3747 3752 assert_not_nil assigns(:hours)
3748 3753 assert Issue.find_by_id(1) && Issue.find_by_id(3)
3749 3754 assert_tag 'form',
3750 3755 :descendant => {:tag => 'input', :attributes => {:name => '_method', :value => 'delete'}}
3751 3756 end
3752 3757
3753 3758 def test_destroy_issues_and_destroy_time_entries
3754 3759 @request.session[:user_id] = 2
3755 3760
3756 3761 assert_difference 'Issue.count', -2 do
3757 3762 assert_difference 'TimeEntry.count', -3 do
3758 3763 delete :destroy, :ids => [1, 3], :todo => 'destroy'
3759 3764 end
3760 3765 end
3761 3766 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
3762 3767 assert !(Issue.find_by_id(1) || Issue.find_by_id(3))
3763 3768 assert_nil TimeEntry.find_by_id([1, 2])
3764 3769 end
3765 3770
3766 3771 def test_destroy_issues_and_assign_time_entries_to_project
3767 3772 @request.session[:user_id] = 2
3768 3773
3769 3774 assert_difference 'Issue.count', -2 do
3770 3775 assert_no_difference 'TimeEntry.count' do
3771 3776 delete :destroy, :ids => [1, 3], :todo => 'nullify'
3772 3777 end
3773 3778 end
3774 3779 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
3775 3780 assert !(Issue.find_by_id(1) || Issue.find_by_id(3))
3776 3781 assert_nil TimeEntry.find(1).issue_id
3777 3782 assert_nil TimeEntry.find(2).issue_id
3778 3783 end
3779 3784
3780 3785 def test_destroy_issues_and_reassign_time_entries_to_another_issue
3781 3786 @request.session[:user_id] = 2
3782 3787
3783 3788 assert_difference 'Issue.count', -2 do
3784 3789 assert_no_difference 'TimeEntry.count' do
3785 3790 delete :destroy, :ids => [1, 3], :todo => 'reassign', :reassign_to_id => 2
3786 3791 end
3787 3792 end
3788 3793 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
3789 3794 assert !(Issue.find_by_id(1) || Issue.find_by_id(3))
3790 3795 assert_equal 2, TimeEntry.find(1).issue_id
3791 3796 assert_equal 2, TimeEntry.find(2).issue_id
3792 3797 end
3793 3798
3794 3799 def test_destroy_issues_from_different_projects
3795 3800 @request.session[:user_id] = 2
3796 3801
3797 3802 assert_difference 'Issue.count', -3 do
3798 3803 delete :destroy, :ids => [1, 2, 6], :todo => 'destroy'
3799 3804 end
3800 3805 assert_redirected_to :controller => 'issues', :action => 'index'
3801 3806 assert !(Issue.find_by_id(1) || Issue.find_by_id(2) || Issue.find_by_id(6))
3802 3807 end
3803 3808
3804 3809 def test_destroy_parent_and_child_issues
3805 3810 parent = Issue.create!(:project_id => 1, :author_id => 1, :tracker_id => 1, :subject => 'Parent Issue')
3806 3811 child = Issue.create!(:project_id => 1, :author_id => 1, :tracker_id => 1, :subject => 'Child Issue', :parent_issue_id => parent.id)
3807 3812 assert child.is_descendant_of?(parent.reload)
3808 3813
3809 3814 @request.session[:user_id] = 2
3810 3815 assert_difference 'Issue.count', -2 do
3811 3816 delete :destroy, :ids => [parent.id, child.id], :todo => 'destroy'
3812 3817 end
3813 3818 assert_response 302
3814 3819 end
3815 3820
3821 def test_destroy_invalid_should_respond_with_404
3822 @request.session[:user_id] = 2
3823 assert_no_difference 'Issue.count' do
3824 delete :destroy, :id => 999
3825 end
3826 assert_response 404
3827 end
3828
3816 3829 def test_default_search_scope
3817 3830 get :index
3818 3831 assert_tag :div, :attributes => {:id => 'quick-search'},
3819 3832 :child => {:tag => 'form',
3820 3833 :child => {:tag => 'input', :attributes => {:name => 'issues', :type => 'hidden', :value => '1'}}}
3821 3834 end
3822 3835 end
General Comments 0
You need to be logged in to leave comments. Login now