##// END OF EJS Templates
Updated assertion that fails after r8680....
Jean-Philippe Lang -
r8561:fdd79c0448a3
parent child
Show More
@@ -1,2679 +1,2679
1 1 # Redmine - project management software
2 2 # Copyright (C) 2006-2011 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 require 'issues_controller'
20 20
21 21 class IssuesControllerTest < ActionController::TestCase
22 22 fixtures :projects,
23 23 :users,
24 24 :roles,
25 25 :members,
26 26 :member_roles,
27 27 :issues,
28 28 :issue_statuses,
29 29 :versions,
30 30 :trackers,
31 31 :projects_trackers,
32 32 :issue_categories,
33 33 :enabled_modules,
34 34 :enumerations,
35 35 :attachments,
36 36 :workflows,
37 37 :custom_fields,
38 38 :custom_values,
39 39 :custom_fields_projects,
40 40 :custom_fields_trackers,
41 41 :time_entries,
42 42 :journals,
43 43 :journal_details,
44 44 :queries
45 45
46 46 include Redmine::I18n
47 47
48 48 def setup
49 49 @controller = IssuesController.new
50 50 @request = ActionController::TestRequest.new
51 51 @response = ActionController::TestResponse.new
52 52 User.current = nil
53 53 end
54 54
55 55 def test_index
56 56 Setting.default_language = 'en'
57 57
58 58 get :index
59 59 assert_response :success
60 60 assert_template 'index'
61 61 assert_not_nil assigns(:issues)
62 62 assert_nil assigns(:project)
63 63 assert_tag :tag => 'a', :content => /Can't print recipes/
64 64 assert_tag :tag => 'a', :content => /Subproject issue/
65 65 # private projects hidden
66 66 assert_no_tag :tag => 'a', :content => /Issue of a private subproject/
67 67 assert_no_tag :tag => 'a', :content => /Issue on project 2/
68 68 # project column
69 69 assert_tag :tag => 'th', :content => /Project/
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 assert_no_tag :tag => 'a', :content => /Can't print recipes/
80 80 assert_tag :tag => 'a', :content => /Subproject issue/
81 81 end
82 82
83 83 def test_index_should_list_visible_issues_only
84 84 get :index, :per_page => 100
85 85 assert_response :success
86 86 assert_not_nil assigns(:issues)
87 87 assert_nil assigns(:issues).detect {|issue| !issue.visible?}
88 88 end
89 89
90 90 def test_index_with_project
91 91 Setting.display_subprojects_issues = 0
92 92 get :index, :project_id => 1
93 93 assert_response :success
94 94 assert_template 'index'
95 95 assert_not_nil assigns(:issues)
96 96 assert_tag :tag => 'a', :content => /Can't print recipes/
97 97 assert_no_tag :tag => 'a', :content => /Subproject issue/
98 98 end
99 99
100 100 def test_index_with_project_and_subprojects
101 101 Setting.display_subprojects_issues = 1
102 102 get :index, :project_id => 1
103 103 assert_response :success
104 104 assert_template 'index'
105 105 assert_not_nil assigns(:issues)
106 106 assert_tag :tag => 'a', :content => /Can't print recipes/
107 107 assert_tag :tag => 'a', :content => /Subproject issue/
108 108 assert_no_tag :tag => 'a', :content => /Issue of a private subproject/
109 109 end
110 110
111 111 def test_index_with_project_and_subprojects_should_show_private_subprojects
112 112 @request.session[:user_id] = 2
113 113 Setting.display_subprojects_issues = 1
114 114 get :index, :project_id => 1
115 115 assert_response :success
116 116 assert_template 'index'
117 117 assert_not_nil assigns(:issues)
118 118 assert_tag :tag => 'a', :content => /Can't print recipes/
119 119 assert_tag :tag => 'a', :content => /Subproject issue/
120 120 assert_tag :tag => 'a', :content => /Issue of a private subproject/
121 121 end
122 122
123 123 def test_index_with_project_and_default_filter
124 124 get :index, :project_id => 1, :set_filter => 1
125 125 assert_response :success
126 126 assert_template 'index'
127 127 assert_not_nil assigns(:issues)
128 128
129 129 query = assigns(:query)
130 130 assert_not_nil query
131 131 # default filter
132 132 assert_equal({'status_id' => {:operator => 'o', :values => ['']}}, query.filters)
133 133 end
134 134
135 135 def test_index_with_project_and_filter
136 136 get :index, :project_id => 1, :set_filter => 1,
137 137 :f => ['tracker_id'],
138 138 :op => {'tracker_id' => '='},
139 139 :v => {'tracker_id' => ['1']}
140 140 assert_response :success
141 141 assert_template 'index'
142 142 assert_not_nil assigns(:issues)
143 143
144 144 query = assigns(:query)
145 145 assert_not_nil query
146 146 assert_equal({'tracker_id' => {:operator => '=', :values => ['1']}}, query.filters)
147 147 end
148 148
149 149 def test_index_with_short_filters
150 150
151 151 to_test = {
152 152 'status_id' => {
153 153 'o' => { :op => 'o', :values => [''] },
154 154 'c' => { :op => 'c', :values => [''] },
155 155 '7' => { :op => '=', :values => ['7'] },
156 156 '7|3|4' => { :op => '=', :values => ['7', '3', '4'] },
157 157 '=7' => { :op => '=', :values => ['7'] },
158 158 '!3' => { :op => '!', :values => ['3'] },
159 159 '!7|3|4' => { :op => '!', :values => ['7', '3', '4'] }},
160 160 'subject' => {
161 161 'This is a subject' => { :op => '=', :values => ['This is a subject'] },
162 162 'o' => { :op => '=', :values => ['o'] },
163 163 '~This is part of a subject' => { :op => '~', :values => ['This is part of a subject'] },
164 164 '!~This is part of a subject' => { :op => '!~', :values => ['This is part of a subject'] }},
165 165 'tracker_id' => {
166 166 '3' => { :op => '=', :values => ['3'] },
167 167 '=3' => { :op => '=', :values => ['3'] }},
168 168 'start_date' => {
169 169 '2011-10-12' => { :op => '=', :values => ['2011-10-12'] },
170 170 '=2011-10-12' => { :op => '=', :values => ['2011-10-12'] },
171 171 '>=2011-10-12' => { :op => '>=', :values => ['2011-10-12'] },
172 172 '<=2011-10-12' => { :op => '<=', :values => ['2011-10-12'] },
173 173 '><2011-10-01|2011-10-30' => { :op => '><', :values => ['2011-10-01', '2011-10-30'] },
174 174 '<t+2' => { :op => '<t+', :values => ['2'] },
175 175 '>t+2' => { :op => '>t+', :values => ['2'] },
176 176 't+2' => { :op => 't+', :values => ['2'] },
177 177 't' => { :op => 't', :values => [''] },
178 178 'w' => { :op => 'w', :values => [''] },
179 179 '>t-2' => { :op => '>t-', :values => ['2'] },
180 180 '<t-2' => { :op => '<t-', :values => ['2'] },
181 181 't-2' => { :op => 't-', :values => ['2'] }},
182 182 'created_on' => {
183 183 '>=2011-10-12' => { :op => '>=', :values => ['2011-10-12'] },
184 184 '<t+2' => { :op => '=', :values => ['<t+2'] },
185 185 '>t+2' => { :op => '=', :values => ['>t+2'] },
186 186 't+2' => { :op => 't', :values => ['+2'] }},
187 187 'cf_1' => {
188 188 'c' => { :op => '=', :values => ['c'] },
189 189 '!c' => { :op => '!', :values => ['c'] },
190 190 '!*' => { :op => '!*', :values => [''] },
191 191 '*' => { :op => '*', :values => [''] }},
192 192 'estimated_hours' => {
193 193 '=13.4' => { :op => '=', :values => ['13.4'] },
194 194 '>=45' => { :op => '>=', :values => ['45'] },
195 195 '<=125' => { :op => '<=', :values => ['125'] },
196 196 '><10.5|20.5' => { :op => '><', :values => ['10.5', '20.5'] },
197 197 '!*' => { :op => '!*', :values => [''] },
198 198 '*' => { :op => '*', :values => [''] }}
199 199 }
200 200
201 201 default_filter = { 'status_id' => {:operator => 'o', :values => [''] }}
202 202
203 203 to_test.each do |field, expression_and_expected|
204 204 expression_and_expected.each do |filter_expression, expected|
205 205
206 206 get :index, :set_filter => 1, field => filter_expression
207 207
208 208 assert_response :success
209 209 assert_template 'index'
210 210 assert_not_nil assigns(:issues)
211 211
212 212 query = assigns(:query)
213 213 assert_not_nil query
214 214 assert query.has_filter?(field)
215 215 assert_equal(default_filter.merge({field => {:operator => expected[:op], :values => expected[:values]}}), query.filters)
216 216 end
217 217 end
218 218
219 219 end
220 220
221 221 def test_index_with_project_and_empty_filters
222 222 get :index, :project_id => 1, :set_filter => 1, :fields => ['']
223 223 assert_response :success
224 224 assert_template 'index'
225 225 assert_not_nil assigns(:issues)
226 226
227 227 query = assigns(:query)
228 228 assert_not_nil query
229 229 # no filter
230 230 assert_equal({}, query.filters)
231 231 end
232 232
233 233 def test_index_with_query
234 234 get :index, :project_id => 1, :query_id => 5
235 235 assert_response :success
236 236 assert_template 'index'
237 237 assert_not_nil assigns(:issues)
238 238 assert_nil assigns(:issue_count_by_group)
239 239 end
240 240
241 241 def test_index_with_query_grouped_by_tracker
242 242 get :index, :project_id => 1, :query_id => 6
243 243 assert_response :success
244 244 assert_template 'index'
245 245 assert_not_nil assigns(:issues)
246 246 assert_not_nil assigns(:issue_count_by_group)
247 247 end
248 248
249 249 def test_index_with_query_grouped_by_list_custom_field
250 250 get :index, :project_id => 1, :query_id => 9
251 251 assert_response :success
252 252 assert_template 'index'
253 253 assert_not_nil assigns(:issues)
254 254 assert_not_nil assigns(:issue_count_by_group)
255 255 end
256 256
257 257 def test_index_with_query_id_and_project_id_should_set_session_query
258 258 get :index, :project_id => 1, :query_id => 4
259 259 assert_response :success
260 260 assert_kind_of Hash, session[:query]
261 261 assert_equal 4, session[:query][:id]
262 262 assert_equal 1, session[:query][:project_id]
263 263 end
264 264
265 265 def test_index_with_cross_project_query_in_session_should_show_project_issues
266 266 q = Query.create!(:name => "test", :user_id => 2, :is_public => false, :project => nil)
267 267 @request.session[:query] = {:id => q.id, :project_id => 1}
268 268
269 269 with_settings :display_subprojects_issues => '0' do
270 270 get :index, :project_id => 1
271 271 end
272 272 assert_response :success
273 273 assert_not_nil assigns(:query)
274 274 assert_equal q.id, assigns(:query).id
275 275 assert_equal 1, assigns(:query).project_id
276 276 assert_equal [1], assigns(:issues).map(&:project_id).uniq
277 277 end
278 278
279 279 def test_private_query_should_not_be_available_to_other_users
280 280 q = Query.create!(:name => "private", :user => User.find(2), :is_public => false, :project => nil)
281 281 @request.session[:user_id] = 3
282 282
283 283 get :index, :query_id => q.id
284 284 assert_response 403
285 285 end
286 286
287 287 def test_private_query_should_be_available_to_its_user
288 288 q = Query.create!(:name => "private", :user => User.find(2), :is_public => false, :project => nil)
289 289 @request.session[:user_id] = 2
290 290
291 291 get :index, :query_id => q.id
292 292 assert_response :success
293 293 end
294 294
295 295 def test_public_query_should_be_available_to_other_users
296 296 q = Query.create!(:name => "private", :user => User.find(2), :is_public => true, :project => nil)
297 297 @request.session[:user_id] = 3
298 298
299 299 get :index, :query_id => q.id
300 300 assert_response :success
301 301 end
302 302
303 303 def test_index_csv
304 304 get :index, :format => 'csv'
305 305 assert_response :success
306 306 assert_not_nil assigns(:issues)
307 307 assert_equal 'text/csv', @response.content_type
308 308 assert @response.body.starts_with?("#,")
309 309 lines = @response.body.chomp.split("\n")
310 310 assert_equal assigns(:query).columns.size + 1, lines[0].split(',').size
311 311 end
312 312
313 313 def test_index_csv_with_project
314 314 get :index, :project_id => 1, :format => 'csv'
315 315 assert_response :success
316 316 assert_not_nil assigns(:issues)
317 317 assert_equal 'text/csv', @response.content_type
318 318 end
319 319
320 320 def test_index_csv_with_description
321 321 get :index, :format => 'csv', :description => '1'
322 322 assert_response :success
323 323 assert_not_nil assigns(:issues)
324 324 assert_equal 'text/csv', @response.content_type
325 325 assert @response.body.starts_with?("#,")
326 326 lines = @response.body.chomp.split("\n")
327 327 assert_equal assigns(:query).columns.size + 2, lines[0].split(',').size
328 328 end
329 329
330 330 def test_index_csv_with_all_columns
331 331 get :index, :format => 'csv', :columns => 'all'
332 332 assert_response :success
333 333 assert_not_nil assigns(:issues)
334 334 assert_equal 'text/csv', @response.content_type
335 335 assert @response.body.starts_with?("#,")
336 336 lines = @response.body.chomp.split("\n")
337 337 assert_equal assigns(:query).available_columns.size + 1, lines[0].split(',').size
338 338 end
339 339
340 340 def test_index_csv_big_5
341 341 with_settings :default_language => "zh-TW" do
342 342 str_utf8 = "\xe4\xb8\x80\xe6\x9c\x88"
343 343 str_big5 = "\xa4@\xa4\xeb"
344 344 if str_utf8.respond_to?(:force_encoding)
345 345 str_utf8.force_encoding('UTF-8')
346 346 str_big5.force_encoding('Big5')
347 347 end
348 348 issue = Issue.new(:project_id => 1, :tracker_id => 1, :author_id => 3,
349 349 :status_id => 1, :priority => IssuePriority.all.first,
350 350 :subject => str_utf8)
351 351 assert issue.save
352 352
353 353 get :index, :project_id => 1,
354 354 :f => ['subject'],
355 355 :op => '=', :values => [str_utf8],
356 356 :format => 'csv'
357 357 assert_equal 'text/csv', @response.content_type
358 358 lines = @response.body.chomp.split("\n")
359 359 s1 = "\xaa\xac\xbaA"
360 360 if str_utf8.respond_to?(:force_encoding)
361 361 s1.force_encoding('Big5')
362 362 end
363 363 assert lines[0].include?(s1)
364 364 assert lines[1].include?(str_big5)
365 365 end
366 366 end
367 367
368 368 def test_index_csv_cannot_convert_should_be_replaced_big_5
369 369 with_settings :default_language => "zh-TW" do
370 370 str_utf8 = "\xe4\xbb\xa5\xe5\x86\x85"
371 371 if str_utf8.respond_to?(:force_encoding)
372 372 str_utf8.force_encoding('UTF-8')
373 373 end
374 374 issue = Issue.new(:project_id => 1, :tracker_id => 1, :author_id => 3,
375 375 :status_id => 1, :priority => IssuePriority.all.first,
376 376 :subject => str_utf8)
377 377 assert issue.save
378 378
379 379 get :index, :project_id => 1,
380 380 :f => ['subject'],
381 381 :op => '=', :values => [str_utf8],
382 382 :c => ['status', 'subject'],
383 383 :format => 'csv',
384 384 :set_filter => 1
385 385 assert_equal 'text/csv', @response.content_type
386 386 lines = @response.body.chomp.split("\n")
387 387 s1 = "\xaa\xac\xbaA" # status
388 388 if str_utf8.respond_to?(:force_encoding)
389 389 s1.force_encoding('Big5')
390 390 end
391 391 assert lines[0].include?(s1)
392 392 s2 = lines[1].split(",")[2]
393 393 if s1.respond_to?(:force_encoding)
394 394 s3 = "\xa5H?" # subject
395 395 s3.force_encoding('Big5')
396 396 assert_equal s3, s2
397 397 elsif RUBY_PLATFORM == 'java'
398 398 assert_equal "??", s2
399 399 else
400 400 assert_equal "\xa5H???", s2
401 401 end
402 402 end
403 403 end
404 404
405 405 def test_index_csv_tw
406 406 with_settings :default_language => "zh-TW" do
407 407 str1 = "test_index_csv_tw"
408 408 issue = Issue.new(:project_id => 1, :tracker_id => 1, :author_id => 3,
409 409 :status_id => 1, :priority => IssuePriority.all.first,
410 410 :subject => str1, :estimated_hours => '1234.5')
411 411 assert issue.save
412 412 assert_equal 1234.5, issue.estimated_hours
413 413
414 414 get :index, :project_id => 1,
415 415 :f => ['subject'],
416 416 :op => '=', :values => [str1],
417 417 :c => ['estimated_hours', 'subject'],
418 418 :format => 'csv',
419 419 :set_filter => 1
420 420 assert_equal 'text/csv', @response.content_type
421 421 lines = @response.body.chomp.split("\n")
422 422 assert_equal "#{issue.id},1234.5,#{str1}", lines[1]
423 423
424 424 str_tw = "Traditional Chinese (\xe7\xb9\x81\xe9\xab\x94\xe4\xb8\xad\xe6\x96\x87)"
425 425 if str_tw.respond_to?(:force_encoding)
426 426 str_tw.force_encoding('UTF-8')
427 427 end
428 428 assert_equal str_tw, l(:general_lang_name)
429 429 assert_equal ',', l(:general_csv_separator)
430 430 assert_equal '.', l(:general_csv_decimal_separator)
431 431 end
432 432 end
433 433
434 434 def test_index_csv_fr
435 435 with_settings :default_language => "fr" do
436 436 str1 = "test_index_csv_fr"
437 437 issue = Issue.new(:project_id => 1, :tracker_id => 1, :author_id => 3,
438 438 :status_id => 1, :priority => IssuePriority.all.first,
439 439 :subject => str1, :estimated_hours => '1234.5')
440 440 assert issue.save
441 441 assert_equal 1234.5, issue.estimated_hours
442 442
443 443 get :index, :project_id => 1,
444 444 :f => ['subject'],
445 445 :op => '=', :values => [str1],
446 446 :c => ['estimated_hours', 'subject'],
447 447 :format => 'csv',
448 448 :set_filter => 1
449 449 assert_equal 'text/csv', @response.content_type
450 450 lines = @response.body.chomp.split("\n")
451 451 assert_equal "#{issue.id};1234,5;#{str1}", lines[1]
452 452
453 453 str_fr = "Fran\xc3\xa7ais"
454 454 if str_fr.respond_to?(:force_encoding)
455 455 str_fr.force_encoding('UTF-8')
456 456 end
457 457 assert_equal str_fr, l(:general_lang_name)
458 458 assert_equal ';', l(:general_csv_separator)
459 459 assert_equal ',', l(:general_csv_decimal_separator)
460 460 end
461 461 end
462 462
463 463 def test_index_pdf
464 464 ["en", "zh", "zh-TW", "ja", "ko"].each do |lang|
465 465 with_settings :default_language => lang do
466 466
467 467 get :index
468 468 assert_response :success
469 469 assert_template 'index'
470 470
471 471 if lang == "ja"
472 472 if RUBY_PLATFORM != 'java'
473 473 assert_equal "CP932", l(:general_pdf_encoding)
474 474 end
475 475 if RUBY_PLATFORM == 'java' && l(:general_pdf_encoding) == "CP932"
476 476 next
477 477 end
478 478 end
479 479
480 480 get :index, :format => 'pdf'
481 481 assert_response :success
482 482 assert_not_nil assigns(:issues)
483 483 assert_equal 'application/pdf', @response.content_type
484 484
485 485 get :index, :project_id => 1, :format => 'pdf'
486 486 assert_response :success
487 487 assert_not_nil assigns(:issues)
488 488 assert_equal 'application/pdf', @response.content_type
489 489
490 490 get :index, :project_id => 1, :query_id => 6, :format => 'pdf'
491 491 assert_response :success
492 492 assert_not_nil assigns(:issues)
493 493 assert_equal 'application/pdf', @response.content_type
494 494 end
495 495 end
496 496 end
497 497
498 498 def test_index_pdf_with_query_grouped_by_list_custom_field
499 499 get :index, :project_id => 1, :query_id => 9, :format => 'pdf'
500 500 assert_response :success
501 501 assert_not_nil assigns(:issues)
502 502 assert_not_nil assigns(:issue_count_by_group)
503 503 assert_equal 'application/pdf', @response.content_type
504 504 end
505 505
506 506 def test_index_sort
507 507 get :index, :sort => 'tracker,id:desc'
508 508 assert_response :success
509 509
510 510 sort_params = @request.session['issues_index_sort']
511 511 assert sort_params.is_a?(String)
512 512 assert_equal 'tracker,id:desc', sort_params
513 513
514 514 issues = assigns(:issues)
515 515 assert_not_nil issues
516 516 assert !issues.empty?
517 517 assert_equal issues.sort {|a,b| a.tracker == b.tracker ? b.id <=> a.id : a.tracker <=> b.tracker }.collect(&:id), issues.collect(&:id)
518 518 end
519 519
520 520 def test_index_sort_by_field_not_included_in_columns
521 521 Setting.issue_list_default_columns = %w(subject author)
522 522 get :index, :sort => 'tracker'
523 523 end
524 524
525 525 def test_index_sort_by_assigned_to
526 526 get :index, :sort => 'assigned_to'
527 527 assert_response :success
528 528 assignees = assigns(:issues).collect(&:assigned_to).compact
529 529 assert_equal assignees.sort, assignees
530 530 end
531 531
532 532 def test_index_sort_by_assigned_to_desc
533 533 get :index, :sort => 'assigned_to:desc'
534 534 assert_response :success
535 535 assignees = assigns(:issues).collect(&:assigned_to).compact
536 536 assert_equal assignees.sort.reverse, assignees
537 537 end
538 538
539 539 def test_index_group_by_assigned_to
540 540 get :index, :group_by => 'assigned_to', :sort => 'priority'
541 541 assert_response :success
542 542 end
543 543
544 544 def test_index_sort_by_author
545 545 get :index, :sort => 'author'
546 546 assert_response :success
547 547 authors = assigns(:issues).collect(&:author)
548 548 assert_equal authors.sort, authors
549 549 end
550 550
551 551 def test_index_sort_by_author_desc
552 552 get :index, :sort => 'author:desc'
553 553 assert_response :success
554 554 authors = assigns(:issues).collect(&:author)
555 555 assert_equal authors.sort.reverse, authors
556 556 end
557 557
558 558 def test_index_group_by_author
559 559 get :index, :group_by => 'author', :sort => 'priority'
560 560 assert_response :success
561 561 end
562 562
563 563 def test_index_sort_by_spent_hours
564 564 get :index, :sort => 'spent_hours:desc'
565 565 assert_response :success
566 566 hours = assigns(:issues).collect(&:spent_hours)
567 567 assert_equal hours.sort.reverse, hours
568 568 end
569 569
570 570 def test_index_with_columns
571 571 columns = ['tracker', 'subject', 'assigned_to']
572 572 get :index, :set_filter => 1, :c => columns
573 573 assert_response :success
574 574
575 575 # query should use specified columns
576 576 query = assigns(:query)
577 577 assert_kind_of Query, query
578 578 assert_equal columns, query.column_names.map(&:to_s)
579 579
580 580 # columns should be stored in session
581 581 assert_kind_of Hash, session[:query]
582 582 assert_kind_of Array, session[:query][:column_names]
583 583 assert_equal columns, session[:query][:column_names].map(&:to_s)
584 584
585 585 # ensure only these columns are kept in the selected columns list
586 586 assert_tag :tag => 'select', :attributes => { :id => 'selected_columns' },
587 587 :children => { :count => 3 }
588 588 assert_no_tag :tag => 'option', :attributes => { :value => 'project' },
589 589 :parent => { :tag => 'select', :attributes => { :id => "selected_columns" } }
590 590 end
591 591
592 592 def test_index_without_project_should_implicitly_add_project_column_to_default_columns
593 593 Setting.issue_list_default_columns = ['tracker', 'subject', 'assigned_to']
594 594 get :index, :set_filter => 1
595 595
596 596 # query should use specified columns
597 597 query = assigns(:query)
598 598 assert_kind_of Query, query
599 599 assert_equal [:project, :tracker, :subject, :assigned_to], query.columns.map(&:name)
600 600 end
601 601
602 602 def test_index_without_project_and_explicit_default_columns_should_not_add_project_column
603 603 Setting.issue_list_default_columns = ['tracker', 'subject', 'assigned_to']
604 604 columns = ['tracker', 'subject', 'assigned_to']
605 605 get :index, :set_filter => 1, :c => columns
606 606
607 607 # query should use specified columns
608 608 query = assigns(:query)
609 609 assert_kind_of Query, query
610 610 assert_equal columns.map(&:to_sym), query.columns.map(&:name)
611 611 end
612 612
613 613 def test_index_with_custom_field_column
614 614 columns = %w(tracker subject cf_2)
615 615 get :index, :set_filter => 1, :c => columns
616 616 assert_response :success
617 617
618 618 # query should use specified columns
619 619 query = assigns(:query)
620 620 assert_kind_of Query, query
621 621 assert_equal columns, query.column_names.map(&:to_s)
622 622
623 623 assert_tag :td,
624 624 :attributes => {:class => 'cf_2 string'},
625 625 :ancestor => {:tag => 'table', :attributes => {:class => /issues/}}
626 626 end
627 627
628 628 def test_index_with_date_column
629 629 Issue.find(1).update_attribute :start_date, '1987-08-24'
630 630
631 631 with_settings :date_format => '%d/%m/%Y' do
632 632 get :index, :set_filter => 1, :c => %w(start_date)
633 633 assert_tag 'td', :attributes => {:class => /start_date/}, :content => '24/08/1987'
634 634 end
635 635 end
636 636
637 637 def test_index_with_done_ratio
638 638 Issue.find(1).update_attribute :done_ratio, 40
639 639
640 640 get :index, :set_filter => 1, :c => %w(done_ratio)
641 641 assert_tag 'td', :attributes => {:class => /done_ratio/},
642 642 :child => {:tag => 'table', :attributes => {:class => 'progress'},
643 643 :descendant => {:tag => 'td', :attributes => {:class => 'closed', :style => 'width: 40%;'}}
644 644 }
645 645 end
646 646
647 647 def test_index_with_spent_hours_column
648 648 get :index, :set_filter => 1, :c => %w(subject spent_hours)
649 649
650 650 assert_tag 'tr', :attributes => {:id => 'issue-3'},
651 651 :child => {
652 652 :tag => 'td', :attributes => {:class => /spent_hours/}, :content => '1.00'
653 653 }
654 654 end
655 655
656 656 def test_index_should_not_show_spent_hours_column_without_permission
657 657 Role.anonymous.remove_permission! :view_time_entries
658 658 get :index, :set_filter => 1, :c => %w(subject spent_hours)
659 659
660 660 assert_no_tag 'td', :attributes => {:class => /spent_hours/}
661 661 end
662 662
663 663 def test_index_with_fixed_version
664 664 get :index, :set_filter => 1, :c => %w(fixed_version)
665 665 assert_tag 'td', :attributes => {:class => /fixed_version/},
666 666 :child => {:tag => 'a', :content => '1.0', :attributes => {:href => '/versions/2'}}
667 667 end
668 668
669 669 def test_index_send_html_if_query_is_invalid
670 670 get :index, :f => ['start_date'], :op => {:start_date => '='}
671 671 assert_equal 'text/html', @response.content_type
672 672 assert_template 'index'
673 673 end
674 674
675 675 def test_index_send_nothing_if_query_is_invalid
676 676 get :index, :f => ['start_date'], :op => {:start_date => '='}, :format => 'csv'
677 677 assert_equal 'text/csv', @response.content_type
678 678 assert @response.body.blank?
679 679 end
680 680
681 681 def test_show_by_anonymous
682 682 get :show, :id => 1
683 683 assert_response :success
684 684 assert_template 'show'
685 685 assert_not_nil assigns(:issue)
686 686 assert_equal Issue.find(1), assigns(:issue)
687 687
688 688 # anonymous role is allowed to add a note
689 689 assert_tag :tag => 'form',
690 690 :descendant => { :tag => 'fieldset',
691 691 :child => { :tag => 'legend',
692 692 :content => /Notes/ } }
693 693 assert_tag :tag => 'title',
694 694 :content => "Bug #1: Can't print recipes - eCookbook - Redmine"
695 695 end
696 696
697 697 def test_show_by_manager
698 698 @request.session[:user_id] = 2
699 699 get :show, :id => 1
700 700 assert_response :success
701 701
702 702 assert_tag :tag => 'a',
703 703 :content => /Quote/
704 704
705 705 assert_tag :tag => 'form',
706 706 :descendant => { :tag => 'fieldset',
707 707 :child => { :tag => 'legend',
708 708 :content => /Change properties/ } },
709 709 :descendant => { :tag => 'fieldset',
710 710 :child => { :tag => 'legend',
711 711 :content => /Log time/ } },
712 712 :descendant => { :tag => 'fieldset',
713 713 :child => { :tag => 'legend',
714 714 :content => /Notes/ } }
715 715 end
716 716
717 717 def test_show_should_display_update_form
718 718 @request.session[:user_id] = 2
719 719 get :show, :id => 1
720 720 assert_response :success
721 721
722 722 assert_tag 'form', :attributes => {:id => 'issue-form'}
723 723 assert_tag 'input', :attributes => {:name => 'issue[is_private]'}
724 724 assert_tag 'select', :attributes => {:name => 'issue[project_id]'}
725 725 assert_tag 'select', :attributes => {:name => 'issue[tracker_id]'}
726 726 assert_tag 'input', :attributes => {:name => 'issue[subject]'}
727 727 assert_tag 'textarea', :attributes => {:name => 'issue[description]'}
728 728 assert_tag 'select', :attributes => {:name => 'issue[status_id]'}
729 729 assert_tag 'select', :attributes => {:name => 'issue[priority_id]'}
730 730 assert_tag 'select', :attributes => {:name => 'issue[assigned_to_id]'}
731 731 assert_tag 'select', :attributes => {:name => 'issue[category_id]'}
732 732 assert_tag 'select', :attributes => {:name => 'issue[fixed_version_id]'}
733 733 assert_tag 'input', :attributes => {:name => 'issue[parent_issue_id]'}
734 734 assert_tag 'input', :attributes => {:name => 'issue[start_date]'}
735 735 assert_tag 'input', :attributes => {:name => 'issue[due_date]'}
736 736 assert_tag 'select', :attributes => {:name => 'issue[done_ratio]'}
737 737 assert_tag 'input', :attributes => { :name => 'issue[custom_field_values][2]' }
738 738 assert_no_tag 'input', :attributes => {:name => 'issue[watcher_user_ids][]'}
739 739 assert_tag 'textarea', :attributes => {:name => 'notes'}
740 740 end
741 741
742 742 def test_show_should_display_update_form_with_minimal_permissions
743 743 Role.find(1).update_attribute :permissions, [:view_issues, :add_issue_notes]
744 744 Workflow.delete_all :role_id => 1
745 745
746 746 @request.session[:user_id] = 2
747 747 get :show, :id => 1
748 748 assert_response :success
749 749
750 750 assert_tag 'form', :attributes => {:id => 'issue-form'}
751 751 assert_no_tag 'input', :attributes => {:name => 'issue[is_private]'}
752 752 assert_no_tag 'select', :attributes => {:name => 'issue[project_id]'}
753 753 assert_no_tag 'select', :attributes => {:name => 'issue[tracker_id]'}
754 754 assert_no_tag 'input', :attributes => {:name => 'issue[subject]'}
755 755 assert_no_tag 'textarea', :attributes => {:name => 'issue[description]'}
756 756 assert_no_tag 'select', :attributes => {:name => 'issue[status_id]'}
757 757 assert_no_tag 'select', :attributes => {:name => 'issue[priority_id]'}
758 758 assert_no_tag 'select', :attributes => {:name => 'issue[assigned_to_id]'}
759 759 assert_no_tag 'select', :attributes => {:name => 'issue[category_id]'}
760 760 assert_no_tag 'select', :attributes => {:name => 'issue[fixed_version_id]'}
761 761 assert_no_tag 'input', :attributes => {:name => 'issue[parent_issue_id]'}
762 762 assert_no_tag 'input', :attributes => {:name => 'issue[start_date]'}
763 763 assert_no_tag 'input', :attributes => {:name => 'issue[due_date]'}
764 764 assert_no_tag 'select', :attributes => {:name => 'issue[done_ratio]'}
765 765 assert_no_tag 'input', :attributes => { :name => 'issue[custom_field_values][2]' }
766 766 assert_no_tag 'input', :attributes => {:name => 'issue[watcher_user_ids][]'}
767 767 assert_tag 'textarea', :attributes => {:name => 'notes'}
768 768 end
769 769
770 770 def test_show_should_display_update_form_with_workflow_permissions
771 771 Role.find(1).update_attribute :permissions, [:view_issues, :add_issue_notes]
772 772
773 773 @request.session[:user_id] = 2
774 774 get :show, :id => 1
775 775 assert_response :success
776 776
777 777 assert_tag 'form', :attributes => {:id => 'issue-form'}
778 778 assert_no_tag 'input', :attributes => {:name => 'issue[is_private]'}
779 779 assert_no_tag 'select', :attributes => {:name => 'issue[project_id]'}
780 780 assert_no_tag 'select', :attributes => {:name => 'issue[tracker_id]'}
781 781 assert_no_tag 'input', :attributes => {:name => 'issue[subject]'}
782 782 assert_no_tag 'textarea', :attributes => {:name => 'issue[description]'}
783 783 assert_tag 'select', :attributes => {:name => 'issue[status_id]'}
784 784 assert_no_tag 'select', :attributes => {:name => 'issue[priority_id]'}
785 785 assert_tag 'select', :attributes => {:name => 'issue[assigned_to_id]'}
786 786 assert_no_tag 'select', :attributes => {:name => 'issue[category_id]'}
787 787 assert_tag 'select', :attributes => {:name => 'issue[fixed_version_id]'}
788 788 assert_no_tag 'input', :attributes => {:name => 'issue[parent_issue_id]'}
789 789 assert_no_tag 'input', :attributes => {:name => 'issue[start_date]'}
790 790 assert_no_tag 'input', :attributes => {:name => 'issue[due_date]'}
791 791 assert_tag 'select', :attributes => {:name => 'issue[done_ratio]'}
792 792 assert_no_tag 'input', :attributes => { :name => 'issue[custom_field_values][2]' }
793 793 assert_no_tag 'input', :attributes => {:name => 'issue[watcher_user_ids][]'}
794 794 assert_tag 'textarea', :attributes => {:name => 'notes'}
795 795 end
796 796
797 797 def test_show_should_not_display_update_form_without_permissions
798 798 Role.find(1).update_attribute :permissions, [:view_issues]
799 799
800 800 @request.session[:user_id] = 2
801 801 get :show, :id => 1
802 802 assert_response :success
803 803
804 804 assert_no_tag 'form', :attributes => {:id => 'issue-form'}
805 805 end
806 806
807 807 def test_update_form_should_not_display_inactive_enumerations
808 808 @request.session[:user_id] = 2
809 809 get :show, :id => 1
810 810 assert_response :success
811 811
812 812 assert ! IssuePriority.find(15).active?
813 813 assert_no_tag :option, :attributes => {:value => '15'},
814 814 :parent => {:tag => 'select', :attributes => {:id => 'issue_priority_id'} }
815 815 end
816 816
817 817 def test_update_form_should_allow_attachment_upload
818 818 @request.session[:user_id] = 2
819 819 get :show, :id => 1
820 820
821 821 assert_tag :tag => 'form',
822 822 :attributes => {:id => 'issue-form', :method => 'post', :enctype => 'multipart/form-data'},
823 823 :descendant => {
824 824 :tag => 'input',
825 825 :attributes => {:type => 'file', :name => 'attachments[1][file]'}
826 826 }
827 827 end
828 828
829 829 def test_show_should_deny_anonymous_access_without_permission
830 830 Role.anonymous.remove_permission!(:view_issues)
831 831 get :show, :id => 1
832 832 assert_response :redirect
833 833 end
834 834
835 835 def test_show_should_deny_anonymous_access_to_private_issue
836 836 Issue.update_all(["is_private = ?", true], "id = 1")
837 837 get :show, :id => 1
838 838 assert_response :redirect
839 839 end
840 840
841 841 def test_show_should_deny_non_member_access_without_permission
842 842 Role.non_member.remove_permission!(:view_issues)
843 843 @request.session[:user_id] = 9
844 844 get :show, :id => 1
845 845 assert_response 403
846 846 end
847 847
848 848 def test_show_should_deny_non_member_access_to_private_issue
849 849 Issue.update_all(["is_private = ?", true], "id = 1")
850 850 @request.session[:user_id] = 9
851 851 get :show, :id => 1
852 852 assert_response 403
853 853 end
854 854
855 855 def test_show_should_deny_member_access_without_permission
856 856 Role.find(1).remove_permission!(:view_issues)
857 857 @request.session[:user_id] = 2
858 858 get :show, :id => 1
859 859 assert_response 403
860 860 end
861 861
862 862 def test_show_should_deny_member_access_to_private_issue_without_permission
863 863 Issue.update_all(["is_private = ?", true], "id = 1")
864 864 @request.session[:user_id] = 3
865 865 get :show, :id => 1
866 866 assert_response 403
867 867 end
868 868
869 869 def test_show_should_allow_author_access_to_private_issue
870 870 Issue.update_all(["is_private = ?, author_id = 3", true], "id = 1")
871 871 @request.session[:user_id] = 3
872 872 get :show, :id => 1
873 873 assert_response :success
874 874 end
875 875
876 876 def test_show_should_allow_assignee_access_to_private_issue
877 877 Issue.update_all(["is_private = ?, assigned_to_id = 3", true], "id = 1")
878 878 @request.session[:user_id] = 3
879 879 get :show, :id => 1
880 880 assert_response :success
881 881 end
882 882
883 883 def test_show_should_allow_member_access_to_private_issue_with_permission
884 884 Issue.update_all(["is_private = ?", true], "id = 1")
885 885 User.find(3).roles_for_project(Project.find(1)).first.update_attribute :issues_visibility, 'all'
886 886 @request.session[:user_id] = 3
887 887 get :show, :id => 1
888 888 assert_response :success
889 889 end
890 890
891 891 def test_show_should_not_disclose_relations_to_invisible_issues
892 892 Setting.cross_project_issue_relations = '1'
893 893 IssueRelation.create!(:issue_from => Issue.find(1), :issue_to => Issue.find(2), :relation_type => 'relates')
894 894 # Relation to a private project issue
895 895 IssueRelation.create!(:issue_from => Issue.find(1), :issue_to => Issue.find(4), :relation_type => 'relates')
896 896
897 897 get :show, :id => 1
898 898 assert_response :success
899 899
900 900 assert_tag :div, :attributes => { :id => 'relations' },
901 901 :descendant => { :tag => 'a', :content => /#2$/ }
902 902 assert_no_tag :div, :attributes => { :id => 'relations' },
903 903 :descendant => { :tag => 'a', :content => /#4$/ }
904 904 end
905 905
906 906 def test_show_should_list_subtasks
907 907 Issue.generate!(:project_id => 1, :author_id => 1, :tracker_id => 1, :parent_issue_id => 1, :subject => 'Child Issue')
908 908
909 909 get :show, :id => 1
910 910 assert_response :success
911 911 assert_tag 'div', :attributes => {:id => 'issue_tree'},
912 912 :descendant => {:tag => 'td', :content => /Child Issue/, :attributes => {:class => /subject/}}
913 913 end
914 914
915 915 def test_show_should_list_parents
916 916 issue = Issue.generate!(:project_id => 1, :author_id => 1, :tracker_id => 1, :parent_issue_id => 1, :subject => 'Child Issue')
917 917
918 918 get :show, :id => issue.id
919 919 assert_response :success
920 920 assert_tag 'div', :attributes => {:class => 'subject'},
921 921 :descendant => {:tag => 'h3', :content => 'Child Issue'}
922 922 assert_tag 'div', :attributes => {:class => 'subject'},
923 923 :descendant => {:tag => 'a', :attributes => {:href => '/issues/1'}}
924 924 end
925 925
926 926 def test_show_should_not_display_prev_next_links_without_query_in_session
927 927 get :show, :id => 1
928 928 assert_response :success
929 929 assert_nil assigns(:prev_issue_id)
930 930 assert_nil assigns(:next_issue_id)
931 931
932 932 assert_no_tag 'div', :attributes => {:class => /next-prev-links/}
933 933 end
934 934
935 935 def test_show_should_display_prev_next_links_with_query_in_session
936 936 @request.session[:query] = {:filters => {'status_id' => {:values => [''], :operator => 'o'}}, :project_id => nil}
937 937 @request.session['issues_index_sort'] = 'id'
938 938
939 939 with_settings :display_subprojects_issues => '0' do
940 940 get :show, :id => 3
941 941 end
942 942
943 943 assert_response :success
944 944 # Previous and next issues for all projects
945 945 assert_equal 2, assigns(:prev_issue_id)
946 946 assert_equal 5, assigns(:next_issue_id)
947 947
948 948 assert_tag 'div', :attributes => {:class => /next-prev-links/}
949 949 assert_tag 'a', :attributes => {:href => '/issues/2'}, :content => /Previous/
950 950 assert_tag 'a', :attributes => {:href => '/issues/5'}, :content => /Next/
951 951
952 952 count = Issue.open.visible.count
953 assert_tag 'span', :attributes => {:class => 'position'}, :content => "3/#{count}"
953 assert_tag 'span', :attributes => {:class => 'position'}, :content => "3 of #{count}"
954 954 end
955 955
956 956 def test_show_should_display_prev_next_links_with_saved_query_in_session
957 957 query = Query.create!(:name => 'test', :is_public => true, :user_id => 1,
958 958 :filters => {'status_id' => {:values => ['5'], :operator => '='}},
959 959 :sort_criteria => [['id', 'asc']])
960 960 @request.session[:query] = {:id => query.id, :project_id => nil}
961 961
962 962 get :show, :id => 11
963 963
964 964 assert_response :success
965 965 assert_equal query, assigns(:query)
966 966 # Previous and next issues for all projects
967 967 assert_equal 8, assigns(:prev_issue_id)
968 968 assert_equal 12, assigns(:next_issue_id)
969 969
970 970 assert_tag 'a', :attributes => {:href => '/issues/8'}, :content => /Previous/
971 971 assert_tag 'a', :attributes => {:href => '/issues/12'}, :content => /Next/
972 972 end
973 973
974 974 def test_show_should_display_prev_next_links_with_query_and_sort_on_association
975 975 @request.session[:query] = {:filters => {'status_id' => {:values => [''], :operator => 'o'}}, :project_id => nil}
976 976
977 977 %w(project tracker status priority author assigned_to category fixed_version).each do |assoc_sort|
978 978 @request.session['issues_index_sort'] = assoc_sort
979 979
980 980 get :show, :id => 3
981 981 assert_response :success, "Wrong response status for #{assoc_sort} sort"
982 982
983 983 assert_tag 'a', :content => /Previous/
984 984 assert_tag 'a', :content => /Next/
985 985 end
986 986 end
987 987
988 988 def test_show_should_display_prev_next_links_with_project_query_in_session
989 989 @request.session[:query] = {:filters => {'status_id' => {:values => [''], :operator => 'o'}}, :project_id => 1}
990 990 @request.session['issues_index_sort'] = 'id'
991 991
992 992 with_settings :display_subprojects_issues => '0' do
993 993 get :show, :id => 3
994 994 end
995 995
996 996 assert_response :success
997 997 # Previous and next issues inside project
998 998 assert_equal 2, assigns(:prev_issue_id)
999 999 assert_equal 7, assigns(:next_issue_id)
1000 1000
1001 1001 assert_tag 'a', :attributes => {:href => '/issues/2'}, :content => /Previous/
1002 1002 assert_tag 'a', :attributes => {:href => '/issues/7'}, :content => /Next/
1003 1003 end
1004 1004
1005 1005 def test_show_should_not_display_prev_link_for_first_issue
1006 1006 @request.session[:query] = {:filters => {'status_id' => {:values => [''], :operator => 'o'}}, :project_id => 1}
1007 1007 @request.session['issues_index_sort'] = 'id'
1008 1008
1009 1009 with_settings :display_subprojects_issues => '0' do
1010 1010 get :show, :id => 1
1011 1011 end
1012 1012
1013 1013 assert_response :success
1014 1014 assert_nil assigns(:prev_issue_id)
1015 1015 assert_equal 2, assigns(:next_issue_id)
1016 1016
1017 1017 assert_no_tag 'a', :content => /Previous/
1018 1018 assert_tag 'a', :attributes => {:href => '/issues/2'}, :content => /Next/
1019 1019 end
1020 1020
1021 1021 def test_show_should_not_display_prev_next_links_for_issue_not_in_query_results
1022 1022 @request.session[:query] = {:filters => {'status_id' => {:values => [''], :operator => 'c'}}, :project_id => 1}
1023 1023 @request.session['issues_index_sort'] = 'id'
1024 1024
1025 1025 get :show, :id => 1
1026 1026
1027 1027 assert_response :success
1028 1028 assert_nil assigns(:prev_issue_id)
1029 1029 assert_nil assigns(:next_issue_id)
1030 1030
1031 1031 assert_no_tag 'a', :content => /Previous/
1032 1032 assert_no_tag 'a', :content => /Next/
1033 1033 end
1034 1034
1035 1035 def test_show_atom
1036 1036 get :show, :id => 2, :format => 'atom'
1037 1037 assert_response :success
1038 1038 assert_template 'journals/index'
1039 1039 # Inline image
1040 1040 assert_select 'content', :text => Regexp.new(Regexp.quote('http://test.host/attachments/download/10'))
1041 1041 end
1042 1042
1043 1043 def test_show_export_to_pdf
1044 1044 get :show, :id => 3, :format => 'pdf'
1045 1045 assert_response :success
1046 1046 assert_equal 'application/pdf', @response.content_type
1047 1047 assert @response.body.starts_with?('%PDF')
1048 1048 assert_not_nil assigns(:issue)
1049 1049 end
1050 1050
1051 1051 def test_get_new
1052 1052 @request.session[:user_id] = 2
1053 1053 get :new, :project_id => 1, :tracker_id => 1
1054 1054 assert_response :success
1055 1055 assert_template 'new'
1056 1056
1057 1057 assert_tag 'input', :attributes => {:name => 'issue[is_private]'}
1058 1058 assert_no_tag 'select', :attributes => {:name => 'issue[project_id]'}
1059 1059 assert_tag 'select', :attributes => {:name => 'issue[tracker_id]'}
1060 1060 assert_tag 'input', :attributes => {:name => 'issue[subject]'}
1061 1061 assert_tag 'textarea', :attributes => {:name => 'issue[description]'}
1062 1062 assert_tag 'select', :attributes => {:name => 'issue[status_id]'}
1063 1063 assert_tag 'select', :attributes => {:name => 'issue[priority_id]'}
1064 1064 assert_tag 'select', :attributes => {:name => 'issue[assigned_to_id]'}
1065 1065 assert_tag 'select', :attributes => {:name => 'issue[category_id]'}
1066 1066 assert_tag 'select', :attributes => {:name => 'issue[fixed_version_id]'}
1067 1067 assert_tag 'input', :attributes => {:name => 'issue[parent_issue_id]'}
1068 1068 assert_tag 'input', :attributes => {:name => 'issue[start_date]'}
1069 1069 assert_tag 'input', :attributes => {:name => 'issue[due_date]'}
1070 1070 assert_tag 'select', :attributes => {:name => 'issue[done_ratio]'}
1071 1071 assert_tag 'input', :attributes => { :name => 'issue[custom_field_values][2]', :value => 'Default string' }
1072 1072 assert_tag 'input', :attributes => {:name => 'issue[watcher_user_ids][]'}
1073 1073
1074 1074 # Be sure we don't display inactive IssuePriorities
1075 1075 assert ! IssuePriority.find(15).active?
1076 1076 assert_no_tag :option, :attributes => {:value => '15'},
1077 1077 :parent => {:tag => 'select', :attributes => {:id => 'issue_priority_id'} }
1078 1078 end
1079 1079
1080 1080 def test_get_new_with_minimal_permissions
1081 1081 Role.find(1).update_attribute :permissions, [:add_issues]
1082 1082 Workflow.delete_all :role_id => 1
1083 1083
1084 1084 @request.session[:user_id] = 2
1085 1085 get :new, :project_id => 1, :tracker_id => 1
1086 1086 assert_response :success
1087 1087 assert_template 'new'
1088 1088
1089 1089 assert_no_tag 'input', :attributes => {:name => 'issue[is_private]'}
1090 1090 assert_no_tag 'select', :attributes => {:name => 'issue[project_id]'}
1091 1091 assert_tag 'select', :attributes => {:name => 'issue[tracker_id]'}
1092 1092 assert_tag 'input', :attributes => {:name => 'issue[subject]'}
1093 1093 assert_tag 'textarea', :attributes => {:name => 'issue[description]'}
1094 1094 assert_tag 'select', :attributes => {:name => 'issue[status_id]'}
1095 1095 assert_tag 'select', :attributes => {:name => 'issue[priority_id]'}
1096 1096 assert_tag 'select', :attributes => {:name => 'issue[assigned_to_id]'}
1097 1097 assert_tag 'select', :attributes => {:name => 'issue[category_id]'}
1098 1098 assert_tag 'select', :attributes => {:name => 'issue[fixed_version_id]'}
1099 1099 assert_no_tag 'input', :attributes => {:name => 'issue[parent_issue_id]'}
1100 1100 assert_tag 'input', :attributes => {:name => 'issue[start_date]'}
1101 1101 assert_tag 'input', :attributes => {:name => 'issue[due_date]'}
1102 1102 assert_tag 'select', :attributes => {:name => 'issue[done_ratio]'}
1103 1103 assert_tag 'input', :attributes => { :name => 'issue[custom_field_values][2]', :value => 'Default string' }
1104 1104 assert_no_tag 'input', :attributes => {:name => 'issue[watcher_user_ids][]'}
1105 1105 end
1106 1106
1107 1107 def test_get_new_without_default_start_date_is_creation_date
1108 1108 Setting.default_issue_start_date_to_creation_date = 0
1109 1109
1110 1110 @request.session[:user_id] = 2
1111 1111 get :new, :project_id => 1, :tracker_id => 1
1112 1112 assert_response :success
1113 1113 assert_template 'new'
1114 1114
1115 1115 assert_tag :tag => 'input', :attributes => { :name => 'issue[start_date]',
1116 1116 :value => nil }
1117 1117 end
1118 1118
1119 1119 def test_get_new_with_default_start_date_is_creation_date
1120 1120 Setting.default_issue_start_date_to_creation_date = 1
1121 1121
1122 1122 @request.session[:user_id] = 2
1123 1123 get :new, :project_id => 1, :tracker_id => 1
1124 1124 assert_response :success
1125 1125 assert_template 'new'
1126 1126
1127 1127 assert_tag :tag => 'input', :attributes => { :name => 'issue[start_date]',
1128 1128 :value => Date.today.to_s }
1129 1129 end
1130 1130
1131 1131 def test_get_new_form_should_allow_attachment_upload
1132 1132 @request.session[:user_id] = 2
1133 1133 get :new, :project_id => 1, :tracker_id => 1
1134 1134
1135 1135 assert_tag :tag => 'form',
1136 1136 :attributes => {:id => 'issue-form', :method => 'post', :enctype => 'multipart/form-data'},
1137 1137 :descendant => {
1138 1138 :tag => 'input',
1139 1139 :attributes => {:type => 'file', :name => 'attachments[1][file]'}
1140 1140 }
1141 1141 end
1142 1142
1143 1143 def test_get_new_without_tracker_id
1144 1144 @request.session[:user_id] = 2
1145 1145 get :new, :project_id => 1
1146 1146 assert_response :success
1147 1147 assert_template 'new'
1148 1148
1149 1149 issue = assigns(:issue)
1150 1150 assert_not_nil issue
1151 1151 assert_equal Project.find(1).trackers.first, issue.tracker
1152 1152 end
1153 1153
1154 1154 def test_get_new_with_no_default_status_should_display_an_error
1155 1155 @request.session[:user_id] = 2
1156 1156 IssueStatus.delete_all
1157 1157
1158 1158 get :new, :project_id => 1
1159 1159 assert_response 500
1160 1160 assert_error_tag :content => /No default issue/
1161 1161 end
1162 1162
1163 1163 def test_get_new_with_no_tracker_should_display_an_error
1164 1164 @request.session[:user_id] = 2
1165 1165 Tracker.delete_all
1166 1166
1167 1167 get :new, :project_id => 1
1168 1168 assert_response 500
1169 1169 assert_error_tag :content => /No tracker/
1170 1170 end
1171 1171
1172 1172 def test_update_new_form
1173 1173 @request.session[:user_id] = 2
1174 1174 xhr :post, :new, :project_id => 1,
1175 1175 :issue => {:tracker_id => 2,
1176 1176 :subject => 'This is the test_new issue',
1177 1177 :description => 'This is the description',
1178 1178 :priority_id => 5}
1179 1179 assert_response :success
1180 1180 assert_template 'attributes'
1181 1181
1182 1182 issue = assigns(:issue)
1183 1183 assert_kind_of Issue, issue
1184 1184 assert_equal 1, issue.project_id
1185 1185 assert_equal 2, issue.tracker_id
1186 1186 assert_equal 'This is the test_new issue', issue.subject
1187 1187 end
1188 1188
1189 1189 def test_post_create
1190 1190 @request.session[:user_id] = 2
1191 1191 assert_difference 'Issue.count' do
1192 1192 post :create, :project_id => 1,
1193 1193 :issue => {:tracker_id => 3,
1194 1194 :status_id => 2,
1195 1195 :subject => 'This is the test_new issue',
1196 1196 :description => 'This is the description',
1197 1197 :priority_id => 5,
1198 1198 :start_date => '2010-11-07',
1199 1199 :estimated_hours => '',
1200 1200 :custom_field_values => {'2' => 'Value for field 2'}}
1201 1201 end
1202 1202 assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id
1203 1203
1204 1204 issue = Issue.find_by_subject('This is the test_new issue')
1205 1205 assert_not_nil issue
1206 1206 assert_equal 2, issue.author_id
1207 1207 assert_equal 3, issue.tracker_id
1208 1208 assert_equal 2, issue.status_id
1209 1209 assert_equal Date.parse('2010-11-07'), issue.start_date
1210 1210 assert_nil issue.estimated_hours
1211 1211 v = issue.custom_values.find(:first, :conditions => {:custom_field_id => 2})
1212 1212 assert_not_nil v
1213 1213 assert_equal 'Value for field 2', v.value
1214 1214 end
1215 1215
1216 1216 def test_post_new_with_group_assignment
1217 1217 group = Group.find(11)
1218 1218 project = Project.find(1)
1219 1219 project.members << Member.new(:principal => group, :roles => [Role.first])
1220 1220
1221 1221 with_settings :issue_group_assignment => '1' do
1222 1222 @request.session[:user_id] = 2
1223 1223 assert_difference 'Issue.count' do
1224 1224 post :create, :project_id => project.id,
1225 1225 :issue => {:tracker_id => 3,
1226 1226 :status_id => 1,
1227 1227 :subject => 'This is the test_new_with_group_assignment issue',
1228 1228 :assigned_to_id => group.id}
1229 1229 end
1230 1230 end
1231 1231 assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id
1232 1232
1233 1233 issue = Issue.find_by_subject('This is the test_new_with_group_assignment issue')
1234 1234 assert_not_nil issue
1235 1235 assert_equal group, issue.assigned_to
1236 1236 end
1237 1237
1238 1238 def test_post_create_without_start_date_and_default_start_date_is_not_creation_date
1239 1239 Setting.default_issue_start_date_to_creation_date = 0
1240 1240
1241 1241 @request.session[:user_id] = 2
1242 1242 assert_difference 'Issue.count' do
1243 1243 post :create, :project_id => 1,
1244 1244 :issue => {:tracker_id => 3,
1245 1245 :status_id => 2,
1246 1246 :subject => 'This is the test_new issue',
1247 1247 :description => 'This is the description',
1248 1248 :priority_id => 5,
1249 1249 :estimated_hours => '',
1250 1250 :custom_field_values => {'2' => 'Value for field 2'}}
1251 1251 end
1252 1252 assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id
1253 1253
1254 1254 issue = Issue.find_by_subject('This is the test_new issue')
1255 1255 assert_not_nil issue
1256 1256 assert_nil issue.start_date
1257 1257 end
1258 1258
1259 1259 def test_post_create_without_start_date_and_default_start_date_is_creation_date
1260 1260 Setting.default_issue_start_date_to_creation_date = 1
1261 1261
1262 1262 @request.session[:user_id] = 2
1263 1263 assert_difference 'Issue.count' do
1264 1264 post :create, :project_id => 1,
1265 1265 :issue => {:tracker_id => 3,
1266 1266 :status_id => 2,
1267 1267 :subject => 'This is the test_new issue',
1268 1268 :description => 'This is the description',
1269 1269 :priority_id => 5,
1270 1270 :estimated_hours => '',
1271 1271 :custom_field_values => {'2' => 'Value for field 2'}}
1272 1272 end
1273 1273 assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id
1274 1274
1275 1275 issue = Issue.find_by_subject('This is the test_new issue')
1276 1276 assert_not_nil issue
1277 1277 assert_equal Date.today, issue.start_date
1278 1278 end
1279 1279
1280 1280 def test_post_create_and_continue
1281 1281 @request.session[:user_id] = 2
1282 1282 assert_difference 'Issue.count' do
1283 1283 post :create, :project_id => 1,
1284 1284 :issue => {:tracker_id => 3, :subject => 'This is first issue', :priority_id => 5},
1285 1285 :continue => ''
1286 1286 end
1287 1287
1288 1288 issue = Issue.first(:order => 'id DESC')
1289 1289 assert_redirected_to :controller => 'issues', :action => 'new', :project_id => 'ecookbook', :issue => {:tracker_id => 3}
1290 1290 assert_not_nil flash[:notice], "flash was not set"
1291 1291 assert flash[:notice].include?("<a href='/issues/#{issue.id}'>##{issue.id}</a>"), "issue link not found in flash: #{flash[:notice]}"
1292 1292 end
1293 1293
1294 1294 def test_post_create_without_custom_fields_param
1295 1295 @request.session[:user_id] = 2
1296 1296 assert_difference 'Issue.count' do
1297 1297 post :create, :project_id => 1,
1298 1298 :issue => {:tracker_id => 1,
1299 1299 :subject => 'This is the test_new issue',
1300 1300 :description => 'This is the description',
1301 1301 :priority_id => 5}
1302 1302 end
1303 1303 assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id
1304 1304 end
1305 1305
1306 1306 def test_post_create_with_required_custom_field_and_without_custom_fields_param
1307 1307 field = IssueCustomField.find_by_name('Database')
1308 1308 field.update_attribute(:is_required, true)
1309 1309
1310 1310 @request.session[:user_id] = 2
1311 1311 post :create, :project_id => 1,
1312 1312 :issue => {:tracker_id => 1,
1313 1313 :subject => 'This is the test_new issue',
1314 1314 :description => 'This is the description',
1315 1315 :priority_id => 5}
1316 1316 assert_response :success
1317 1317 assert_template 'new'
1318 1318 issue = assigns(:issue)
1319 1319 assert_not_nil issue
1320 1320 assert_equal I18n.translate('activerecord.errors.messages.invalid'),
1321 1321 issue.errors[:custom_values].to_s
1322 1322 end
1323 1323
1324 1324 def test_post_create_with_watchers
1325 1325 @request.session[:user_id] = 2
1326 1326 ActionMailer::Base.deliveries.clear
1327 1327
1328 1328 assert_difference 'Watcher.count', 2 do
1329 1329 post :create, :project_id => 1,
1330 1330 :issue => {:tracker_id => 1,
1331 1331 :subject => 'This is a new issue with watchers',
1332 1332 :description => 'This is the description',
1333 1333 :priority_id => 5,
1334 1334 :watcher_user_ids => ['2', '3']}
1335 1335 end
1336 1336 issue = Issue.find_by_subject('This is a new issue with watchers')
1337 1337 assert_not_nil issue
1338 1338 assert_redirected_to :controller => 'issues', :action => 'show', :id => issue
1339 1339
1340 1340 # Watchers added
1341 1341 assert_equal [2, 3], issue.watcher_user_ids.sort
1342 1342 assert issue.watched_by?(User.find(3))
1343 1343 # Watchers notified
1344 1344 mail = ActionMailer::Base.deliveries.last
1345 1345 assert_kind_of TMail::Mail, mail
1346 1346 assert [mail.bcc, mail.cc].flatten.include?(User.find(3).mail)
1347 1347 end
1348 1348
1349 1349 def test_post_create_subissue
1350 1350 @request.session[:user_id] = 2
1351 1351
1352 1352 assert_difference 'Issue.count' do
1353 1353 post :create, :project_id => 1,
1354 1354 :issue => {:tracker_id => 1,
1355 1355 :subject => 'This is a child issue',
1356 1356 :parent_issue_id => 2}
1357 1357 end
1358 1358 issue = Issue.find_by_subject('This is a child issue')
1359 1359 assert_not_nil issue
1360 1360 assert_equal Issue.find(2), issue.parent
1361 1361 end
1362 1362
1363 1363 def test_post_create_subissue_with_non_numeric_parent_id
1364 1364 @request.session[:user_id] = 2
1365 1365
1366 1366 assert_difference 'Issue.count' do
1367 1367 post :create, :project_id => 1,
1368 1368 :issue => {:tracker_id => 1,
1369 1369 :subject => 'This is a child issue',
1370 1370 :parent_issue_id => 'ABC'}
1371 1371 end
1372 1372 issue = Issue.find_by_subject('This is a child issue')
1373 1373 assert_not_nil issue
1374 1374 assert_nil issue.parent
1375 1375 end
1376 1376
1377 1377 def test_post_create_private
1378 1378 @request.session[:user_id] = 2
1379 1379
1380 1380 assert_difference 'Issue.count' do
1381 1381 post :create, :project_id => 1,
1382 1382 :issue => {:tracker_id => 1,
1383 1383 :subject => 'This is a private issue',
1384 1384 :is_private => '1'}
1385 1385 end
1386 1386 issue = Issue.first(:order => 'id DESC')
1387 1387 assert issue.is_private?
1388 1388 end
1389 1389
1390 1390 def test_post_create_private_with_set_own_issues_private_permission
1391 1391 role = Role.find(1)
1392 1392 role.remove_permission! :set_issues_private
1393 1393 role.add_permission! :set_own_issues_private
1394 1394
1395 1395 @request.session[:user_id] = 2
1396 1396
1397 1397 assert_difference 'Issue.count' do
1398 1398 post :create, :project_id => 1,
1399 1399 :issue => {:tracker_id => 1,
1400 1400 :subject => 'This is a private issue',
1401 1401 :is_private => '1'}
1402 1402 end
1403 1403 issue = Issue.first(:order => 'id DESC')
1404 1404 assert issue.is_private?
1405 1405 end
1406 1406
1407 1407 def test_post_create_should_send_a_notification
1408 1408 ActionMailer::Base.deliveries.clear
1409 1409 @request.session[:user_id] = 2
1410 1410 assert_difference 'Issue.count' do
1411 1411 post :create, :project_id => 1,
1412 1412 :issue => {:tracker_id => 3,
1413 1413 :subject => 'This is the test_new issue',
1414 1414 :description => 'This is the description',
1415 1415 :priority_id => 5,
1416 1416 :estimated_hours => '',
1417 1417 :custom_field_values => {'2' => 'Value for field 2'}}
1418 1418 end
1419 1419 assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id
1420 1420
1421 1421 assert_equal 1, ActionMailer::Base.deliveries.size
1422 1422 end
1423 1423
1424 1424 def test_post_create_should_preserve_fields_values_on_validation_failure
1425 1425 @request.session[:user_id] = 2
1426 1426 post :create, :project_id => 1,
1427 1427 :issue => {:tracker_id => 1,
1428 1428 # empty subject
1429 1429 :subject => '',
1430 1430 :description => 'This is a description',
1431 1431 :priority_id => 6,
1432 1432 :custom_field_values => {'1' => 'Oracle', '2' => 'Value for field 2'}}
1433 1433 assert_response :success
1434 1434 assert_template 'new'
1435 1435
1436 1436 assert_tag :textarea, :attributes => { :name => 'issue[description]' },
1437 1437 :content => 'This is a description'
1438 1438 assert_tag :select, :attributes => { :name => 'issue[priority_id]' },
1439 1439 :child => { :tag => 'option', :attributes => { :selected => 'selected',
1440 1440 :value => '6' },
1441 1441 :content => 'High' }
1442 1442 # Custom fields
1443 1443 assert_tag :select, :attributes => { :name => 'issue[custom_field_values][1]' },
1444 1444 :child => { :tag => 'option', :attributes => { :selected => 'selected',
1445 1445 :value => 'Oracle' },
1446 1446 :content => 'Oracle' }
1447 1447 assert_tag :input, :attributes => { :name => 'issue[custom_field_values][2]',
1448 1448 :value => 'Value for field 2'}
1449 1449 end
1450 1450
1451 1451 def test_post_create_should_ignore_non_safe_attributes
1452 1452 @request.session[:user_id] = 2
1453 1453 assert_nothing_raised do
1454 1454 post :create, :project_id => 1, :issue => { :tracker => "A param can not be a Tracker" }
1455 1455 end
1456 1456 end
1457 1457
1458 1458 def test_post_create_with_attachment
1459 1459 set_tmp_attachments_directory
1460 1460 @request.session[:user_id] = 2
1461 1461
1462 1462 assert_difference 'Issue.count' do
1463 1463 assert_difference 'Attachment.count' do
1464 1464 post :create, :project_id => 1,
1465 1465 :issue => { :tracker_id => '1', :subject => 'With attachment' },
1466 1466 :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain'), 'description' => 'test file'}}
1467 1467 end
1468 1468 end
1469 1469
1470 1470 issue = Issue.first(:order => 'id DESC')
1471 1471 attachment = Attachment.first(:order => 'id DESC')
1472 1472
1473 1473 assert_equal issue, attachment.container
1474 1474 assert_equal 2, attachment.author_id
1475 1475 assert_equal 'testfile.txt', attachment.filename
1476 1476 assert_equal 'text/plain', attachment.content_type
1477 1477 assert_equal 'test file', attachment.description
1478 1478 assert_equal 59, attachment.filesize
1479 1479 assert File.exists?(attachment.diskfile)
1480 1480 assert_equal 59, File.size(attachment.diskfile)
1481 1481 end
1482 1482
1483 1483 context "without workflow privilege" do
1484 1484 setup do
1485 1485 Workflow.delete_all(["role_id = ?", Role.anonymous.id])
1486 1486 Role.anonymous.add_permission! :add_issues, :add_issue_notes
1487 1487 end
1488 1488
1489 1489 context "#new" do
1490 1490 should "propose default status only" do
1491 1491 get :new, :project_id => 1
1492 1492 assert_response :success
1493 1493 assert_template 'new'
1494 1494 assert_tag :tag => 'select',
1495 1495 :attributes => {:name => 'issue[status_id]'},
1496 1496 :children => {:count => 1},
1497 1497 :child => {:tag => 'option', :attributes => {:value => IssueStatus.default.id.to_s}}
1498 1498 end
1499 1499
1500 1500 should "accept default status" do
1501 1501 assert_difference 'Issue.count' do
1502 1502 post :create, :project_id => 1,
1503 1503 :issue => {:tracker_id => 1,
1504 1504 :subject => 'This is an issue',
1505 1505 :status_id => 1}
1506 1506 end
1507 1507 issue = Issue.last(:order => 'id')
1508 1508 assert_equal IssueStatus.default, issue.status
1509 1509 end
1510 1510
1511 1511 should "ignore unauthorized status" do
1512 1512 assert_difference 'Issue.count' do
1513 1513 post :create, :project_id => 1,
1514 1514 :issue => {:tracker_id => 1,
1515 1515 :subject => 'This is an issue',
1516 1516 :status_id => 3}
1517 1517 end
1518 1518 issue = Issue.last(:order => 'id')
1519 1519 assert_equal IssueStatus.default, issue.status
1520 1520 end
1521 1521 end
1522 1522
1523 1523 context "#update" do
1524 1524 should "ignore status change" do
1525 1525 assert_difference 'Journal.count' do
1526 1526 put :update, :id => 1, :notes => 'just trying', :issue => {:status_id => 3}
1527 1527 end
1528 1528 assert_equal 1, Issue.find(1).status_id
1529 1529 end
1530 1530
1531 1531 should "ignore attributes changes" do
1532 1532 assert_difference 'Journal.count' do
1533 1533 put :update, :id => 1, :notes => 'just trying', :issue => {:subject => 'changed', :assigned_to_id => 2}
1534 1534 end
1535 1535 issue = Issue.find(1)
1536 1536 assert_equal "Can't print recipes", issue.subject
1537 1537 assert_nil issue.assigned_to
1538 1538 end
1539 1539 end
1540 1540 end
1541 1541
1542 1542 context "with workflow privilege" do
1543 1543 setup do
1544 1544 Workflow.delete_all(["role_id = ?", Role.anonymous.id])
1545 1545 Workflow.create!(:role => Role.anonymous, :tracker_id => 1, :old_status_id => 1, :new_status_id => 3)
1546 1546 Workflow.create!(:role => Role.anonymous, :tracker_id => 1, :old_status_id => 1, :new_status_id => 4)
1547 1547 Role.anonymous.add_permission! :add_issues, :add_issue_notes
1548 1548 end
1549 1549
1550 1550 context "#update" do
1551 1551 should "accept authorized status" do
1552 1552 assert_difference 'Journal.count' do
1553 1553 put :update, :id => 1, :notes => 'just trying', :issue => {:status_id => 3}
1554 1554 end
1555 1555 assert_equal 3, Issue.find(1).status_id
1556 1556 end
1557 1557
1558 1558 should "ignore unauthorized status" do
1559 1559 assert_difference 'Journal.count' do
1560 1560 put :update, :id => 1, :notes => 'just trying', :issue => {:status_id => 2}
1561 1561 end
1562 1562 assert_equal 1, Issue.find(1).status_id
1563 1563 end
1564 1564
1565 1565 should "accept authorized attributes changes" do
1566 1566 assert_difference 'Journal.count' do
1567 1567 put :update, :id => 1, :notes => 'just trying', :issue => {:assigned_to_id => 2}
1568 1568 end
1569 1569 issue = Issue.find(1)
1570 1570 assert_equal 2, issue.assigned_to_id
1571 1571 end
1572 1572
1573 1573 should "ignore unauthorized attributes changes" do
1574 1574 assert_difference 'Journal.count' do
1575 1575 put :update, :id => 1, :notes => 'just trying', :issue => {:subject => 'changed'}
1576 1576 end
1577 1577 issue = Issue.find(1)
1578 1578 assert_equal "Can't print recipes", issue.subject
1579 1579 end
1580 1580 end
1581 1581
1582 1582 context "and :edit_issues permission" do
1583 1583 setup do
1584 1584 Role.anonymous.add_permission! :add_issues, :edit_issues
1585 1585 end
1586 1586
1587 1587 should "accept authorized status" do
1588 1588 assert_difference 'Journal.count' do
1589 1589 put :update, :id => 1, :notes => 'just trying', :issue => {:status_id => 3}
1590 1590 end
1591 1591 assert_equal 3, Issue.find(1).status_id
1592 1592 end
1593 1593
1594 1594 should "ignore unauthorized status" do
1595 1595 assert_difference 'Journal.count' do
1596 1596 put :update, :id => 1, :notes => 'just trying', :issue => {:status_id => 2}
1597 1597 end
1598 1598 assert_equal 1, Issue.find(1).status_id
1599 1599 end
1600 1600
1601 1601 should "accept authorized attributes changes" do
1602 1602 assert_difference 'Journal.count' do
1603 1603 put :update, :id => 1, :notes => 'just trying', :issue => {:subject => 'changed', :assigned_to_id => 2}
1604 1604 end
1605 1605 issue = Issue.find(1)
1606 1606 assert_equal "changed", issue.subject
1607 1607 assert_equal 2, issue.assigned_to_id
1608 1608 end
1609 1609 end
1610 1610 end
1611 1611
1612 1612 def test_new_as_copy
1613 1613 @request.session[:user_id] = 2
1614 1614 get :new, :project_id => 1, :copy_from => 1
1615 1615
1616 1616 assert_response :success
1617 1617 assert_template 'new'
1618 1618
1619 1619 assert_not_nil assigns(:issue)
1620 1620 orig = Issue.find(1)
1621 1621 assert_equal 1, assigns(:issue).project_id
1622 1622 assert_equal orig.subject, assigns(:issue).subject
1623 1623 assert assigns(:issue).copy?
1624 1624
1625 1625 assert_tag 'form', :attributes => {:id => 'issue-form', :action => '/projects/ecookbook/issues'}
1626 1626 assert_tag 'select', :attributes => {:name => 'issue[project_id]'}
1627 1627 assert_tag 'select', :attributes => {:name => 'issue[project_id]'},
1628 1628 :child => {:tag => 'option', :attributes => {:value => '1', :selected => 'selected'}, :content => 'eCookbook'}
1629 1629 assert_tag 'select', :attributes => {:name => 'issue[project_id]'},
1630 1630 :child => {:tag => 'option', :attributes => {:value => '2', :selected => nil}, :content => 'OnlineStore'}
1631 1631 assert_tag 'input', :attributes => {:name => 'copy_from', :value => '1'}
1632 1632 end
1633 1633
1634 1634 def test_new_as_copy_with_attachments_should_show_copy_attachments_checkbox
1635 1635 @request.session[:user_id] = 2
1636 1636 issue = Issue.find(3)
1637 1637 assert issue.attachments.count > 0
1638 1638 get :new, :project_id => 1, :copy_from => 3
1639 1639
1640 1640 assert_tag 'input', :attributes => {:name => 'copy_attachments', :type => 'checkbox', :checked => 'checked', :value => '1'}
1641 1641 end
1642 1642
1643 1643 def test_new_as_copy_without_attachments_should_not_show_copy_attachments_checkbox
1644 1644 @request.session[:user_id] = 2
1645 1645 issue = Issue.find(3)
1646 1646 issue.attachments.delete_all
1647 1647 get :new, :project_id => 1, :copy_from => 3
1648 1648
1649 1649 assert_no_tag 'input', :attributes => {:name => 'copy_attachments', :type => 'checkbox', :checked => 'checked', :value => '1'}
1650 1650 end
1651 1651
1652 1652 def test_new_as_copy_with_invalid_issue_should_respond_with_404
1653 1653 @request.session[:user_id] = 2
1654 1654 get :new, :project_id => 1, :copy_from => 99999
1655 1655 assert_response 404
1656 1656 end
1657 1657
1658 1658 def test_create_as_copy_on_different_project
1659 1659 @request.session[:user_id] = 2
1660 1660 assert_difference 'Issue.count' do
1661 1661 post :create, :project_id => 1, :copy_from => 1,
1662 1662 :issue => {:project_id => '2', :tracker_id => '3', :status_id => '1', :subject => 'Copy'}
1663 1663
1664 1664 assert_not_nil assigns(:issue)
1665 1665 assert assigns(:issue).copy?
1666 1666 end
1667 1667 issue = Issue.first(:order => 'id DESC')
1668 1668 assert_redirected_to "/issues/#{issue.id}"
1669 1669
1670 1670 assert_equal 2, issue.project_id
1671 1671 assert_equal 3, issue.tracker_id
1672 1672 assert_equal 'Copy', issue.subject
1673 1673 end
1674 1674
1675 1675 def test_create_as_copy_should_copy_attachments
1676 1676 @request.session[:user_id] = 2
1677 1677 issue = Issue.find(3)
1678 1678 count = issue.attachments.count
1679 1679 assert count > 0
1680 1680
1681 1681 assert_difference 'Issue.count' do
1682 1682 assert_difference 'Attachment.count', count do
1683 1683 assert_no_difference 'Journal.count' do
1684 1684 post :create, :project_id => 1, :copy_from => 3,
1685 1685 :issue => {:project_id => '1', :tracker_id => '3', :status_id => '1', :subject => 'Copy with attachments'},
1686 1686 :copy_attachments => '1'
1687 1687 end
1688 1688 end
1689 1689 end
1690 1690 copy = Issue.first(:order => 'id DESC')
1691 1691 assert_equal count, copy.attachments.count
1692 1692 assert_equal issue.attachments.map(&:filename).sort, copy.attachments.map(&:filename).sort
1693 1693 end
1694 1694
1695 1695 def test_create_as_copy_without_copy_attachments_option_should_not_copy_attachments
1696 1696 @request.session[:user_id] = 2
1697 1697 issue = Issue.find(3)
1698 1698 count = issue.attachments.count
1699 1699 assert count > 0
1700 1700
1701 1701 assert_difference 'Issue.count' do
1702 1702 assert_no_difference 'Attachment.count' do
1703 1703 assert_no_difference 'Journal.count' do
1704 1704 post :create, :project_id => 1, :copy_from => 3,
1705 1705 :issue => {:project_id => '1', :tracker_id => '3', :status_id => '1', :subject => 'Copy with attachments'}
1706 1706 end
1707 1707 end
1708 1708 end
1709 1709 copy = Issue.first(:order => 'id DESC')
1710 1710 assert_equal 0, copy.attachments.count
1711 1711 end
1712 1712
1713 1713 def test_create_as_copy_with_attachments_should_add_new_files
1714 1714 @request.session[:user_id] = 2
1715 1715 issue = Issue.find(3)
1716 1716 count = issue.attachments.count
1717 1717 assert count > 0
1718 1718
1719 1719 assert_difference 'Issue.count' do
1720 1720 assert_difference 'Attachment.count', count + 1 do
1721 1721 assert_no_difference 'Journal.count' do
1722 1722 post :create, :project_id => 1, :copy_from => 3,
1723 1723 :issue => {:project_id => '1', :tracker_id => '3', :status_id => '1', :subject => 'Copy with attachments'},
1724 1724 :copy_attachments => '1',
1725 1725 :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain'), 'description' => 'test file'}}
1726 1726 end
1727 1727 end
1728 1728 end
1729 1729 copy = Issue.first(:order => 'id DESC')
1730 1730 assert_equal count + 1, copy.attachments.count
1731 1731 end
1732 1732
1733 1733 def test_create_as_copy_with_failure
1734 1734 @request.session[:user_id] = 2
1735 1735 post :create, :project_id => 1, :copy_from => 1,
1736 1736 :issue => {:project_id => '2', :tracker_id => '3', :status_id => '1', :subject => ''}
1737 1737
1738 1738 assert_response :success
1739 1739 assert_template 'new'
1740 1740
1741 1741 assert_not_nil assigns(:issue)
1742 1742 assert assigns(:issue).copy?
1743 1743
1744 1744 assert_tag 'form', :attributes => {:id => 'issue-form', :action => '/projects/ecookbook/issues'}
1745 1745 assert_tag 'select', :attributes => {:name => 'issue[project_id]'}
1746 1746 assert_tag 'select', :attributes => {:name => 'issue[project_id]'},
1747 1747 :child => {:tag => 'option', :attributes => {:value => '1', :selected => nil}, :content => 'eCookbook'}
1748 1748 assert_tag 'select', :attributes => {:name => 'issue[project_id]'},
1749 1749 :child => {:tag => 'option', :attributes => {:value => '2', :selected => 'selected'}, :content => 'OnlineStore'}
1750 1750 assert_tag 'input', :attributes => {:name => 'copy_from', :value => '1'}
1751 1751 end
1752 1752
1753 1753 def test_create_as_copy_on_project_without_permission_should_ignore_target_project
1754 1754 @request.session[:user_id] = 2
1755 1755 assert !User.find(2).member_of?(Project.find(4))
1756 1756
1757 1757 assert_difference 'Issue.count' do
1758 1758 post :create, :project_id => 1, :copy_from => 1,
1759 1759 :issue => {:project_id => '4', :tracker_id => '3', :status_id => '1', :subject => 'Copy'}
1760 1760 end
1761 1761 issue = Issue.first(:order => 'id DESC')
1762 1762 assert_equal 1, issue.project_id
1763 1763 end
1764 1764
1765 1765 def test_get_edit
1766 1766 @request.session[:user_id] = 2
1767 1767 get :edit, :id => 1
1768 1768 assert_response :success
1769 1769 assert_template 'edit'
1770 1770 assert_not_nil assigns(:issue)
1771 1771 assert_equal Issue.find(1), assigns(:issue)
1772 1772
1773 1773 # Be sure we don't display inactive IssuePriorities
1774 1774 assert ! IssuePriority.find(15).active?
1775 1775 assert_no_tag :option, :attributes => {:value => '15'},
1776 1776 :parent => {:tag => 'select', :attributes => {:id => 'issue_priority_id'} }
1777 1777 end
1778 1778
1779 1779 def test_get_edit_should_display_the_time_entry_form_with_log_time_permission
1780 1780 @request.session[:user_id] = 2
1781 1781 Role.find_by_name('Manager').update_attribute :permissions, [:view_issues, :edit_issues, :log_time]
1782 1782
1783 1783 get :edit, :id => 1
1784 1784 assert_tag 'input', :attributes => {:name => 'time_entry[hours]'}
1785 1785 end
1786 1786
1787 1787 def test_get_edit_should_not_display_the_time_entry_form_without_log_time_permission
1788 1788 @request.session[:user_id] = 2
1789 1789 Role.find_by_name('Manager').remove_permission! :log_time
1790 1790
1791 1791 get :edit, :id => 1
1792 1792 assert_no_tag 'input', :attributes => {:name => 'time_entry[hours]'}
1793 1793 end
1794 1794
1795 1795 def test_get_edit_with_params
1796 1796 @request.session[:user_id] = 2
1797 1797 get :edit, :id => 1, :issue => { :status_id => 5, :priority_id => 7 },
1798 1798 :time_entry => { :hours => '2.5', :comments => 'test_get_edit_with_params', :activity_id => TimeEntryActivity.first.id }
1799 1799 assert_response :success
1800 1800 assert_template 'edit'
1801 1801
1802 1802 issue = assigns(:issue)
1803 1803 assert_not_nil issue
1804 1804
1805 1805 assert_equal 5, issue.status_id
1806 1806 assert_tag :select, :attributes => { :name => 'issue[status_id]' },
1807 1807 :child => { :tag => 'option',
1808 1808 :content => 'Closed',
1809 1809 :attributes => { :selected => 'selected' } }
1810 1810
1811 1811 assert_equal 7, issue.priority_id
1812 1812 assert_tag :select, :attributes => { :name => 'issue[priority_id]' },
1813 1813 :child => { :tag => 'option',
1814 1814 :content => 'Urgent',
1815 1815 :attributes => { :selected => 'selected' } }
1816 1816
1817 1817 assert_tag :input, :attributes => { :name => 'time_entry[hours]', :value => '2.5' }
1818 1818 assert_tag :select, :attributes => { :name => 'time_entry[activity_id]' },
1819 1819 :child => { :tag => 'option',
1820 1820 :attributes => { :selected => 'selected', :value => TimeEntryActivity.first.id } }
1821 1821 assert_tag :input, :attributes => { :name => 'time_entry[comments]', :value => 'test_get_edit_with_params' }
1822 1822 end
1823 1823
1824 1824 def test_update_edit_form
1825 1825 @request.session[:user_id] = 2
1826 1826 xhr :put, :new, :project_id => 1,
1827 1827 :id => 1,
1828 1828 :issue => {:tracker_id => 2,
1829 1829 :subject => 'This is the test_new issue',
1830 1830 :description => 'This is the description',
1831 1831 :priority_id => 5}
1832 1832 assert_response :success
1833 1833 assert_template 'attributes'
1834 1834
1835 1835 issue = assigns(:issue)
1836 1836 assert_kind_of Issue, issue
1837 1837 assert_equal 1, issue.id
1838 1838 assert_equal 1, issue.project_id
1839 1839 assert_equal 2, issue.tracker_id
1840 1840 assert_equal 'This is the test_new issue', issue.subject
1841 1841 end
1842 1842
1843 1843 def test_update_edit_form_with_project_change
1844 1844 @request.session[:user_id] = 2
1845 1845 xhr :put, :new, :project_id => 1,
1846 1846 :id => 1,
1847 1847 :project_change => '1',
1848 1848 :issue => {:project_id => 2,
1849 1849 :tracker_id => 2,
1850 1850 :subject => 'This is the test_new issue',
1851 1851 :description => 'This is the description',
1852 1852 :priority_id => 5}
1853 1853 assert_response :success
1854 1854 assert_template 'form'
1855 1855
1856 1856 issue = assigns(:issue)
1857 1857 assert_kind_of Issue, issue
1858 1858 assert_equal 1, issue.id
1859 1859 assert_equal 2, issue.project_id
1860 1860 assert_equal 2, issue.tracker_id
1861 1861 assert_equal 'This is the test_new issue', issue.subject
1862 1862 end
1863 1863
1864 1864 def test_update_using_invalid_http_verbs
1865 1865 @request.session[:user_id] = 2
1866 1866 subject = 'Updated by an invalid http verb'
1867 1867
1868 1868 get :update, :id => 1, :issue => {:subject => subject}
1869 1869 assert_not_equal subject, Issue.find(1).subject
1870 1870
1871 1871 post :update, :id => 1, :issue => {:subject => subject}
1872 1872 assert_not_equal subject, Issue.find(1).subject
1873 1873
1874 1874 delete :update, :id => 1, :issue => {:subject => subject}
1875 1875 assert_not_equal subject, Issue.find(1).subject
1876 1876 end
1877 1877
1878 1878 def test_put_update_without_custom_fields_param
1879 1879 @request.session[:user_id] = 2
1880 1880 ActionMailer::Base.deliveries.clear
1881 1881
1882 1882 issue = Issue.find(1)
1883 1883 assert_equal '125', issue.custom_value_for(2).value
1884 1884 old_subject = issue.subject
1885 1885 new_subject = 'Subject modified by IssuesControllerTest#test_post_edit'
1886 1886
1887 1887 assert_difference('Journal.count') do
1888 1888 assert_difference('JournalDetail.count', 2) do
1889 1889 put :update, :id => 1, :issue => {:subject => new_subject,
1890 1890 :priority_id => '6',
1891 1891 :category_id => '1' # no change
1892 1892 }
1893 1893 end
1894 1894 end
1895 1895 assert_redirected_to :action => 'show', :id => '1'
1896 1896 issue.reload
1897 1897 assert_equal new_subject, issue.subject
1898 1898 # Make sure custom fields were not cleared
1899 1899 assert_equal '125', issue.custom_value_for(2).value
1900 1900
1901 1901 mail = ActionMailer::Base.deliveries.last
1902 1902 assert_kind_of TMail::Mail, mail
1903 1903 assert mail.subject.starts_with?("[#{issue.project.name} - #{issue.tracker.name} ##{issue.id}]")
1904 1904 assert mail.body.include?("Subject changed from #{old_subject} to #{new_subject}")
1905 1905 end
1906 1906
1907 1907 def test_put_update_with_project_change
1908 1908 @request.session[:user_id] = 2
1909 1909 ActionMailer::Base.deliveries.clear
1910 1910
1911 1911 assert_difference('Journal.count') do
1912 1912 assert_difference('JournalDetail.count', 3) do
1913 1913 put :update, :id => 1, :issue => {:project_id => '2',
1914 1914 :tracker_id => '1', # no change
1915 1915 :priority_id => '6',
1916 1916 :category_id => '3'
1917 1917 }
1918 1918 end
1919 1919 end
1920 1920 assert_redirected_to :action => 'show', :id => '1'
1921 1921 issue = Issue.find(1)
1922 1922 assert_equal 2, issue.project_id
1923 1923 assert_equal 1, issue.tracker_id
1924 1924 assert_equal 6, issue.priority_id
1925 1925 assert_equal 3, issue.category_id
1926 1926
1927 1927 mail = ActionMailer::Base.deliveries.last
1928 1928 assert_not_nil mail
1929 1929 assert mail.subject.starts_with?("[#{issue.project.name} - #{issue.tracker.name} ##{issue.id}]")
1930 1930 assert mail.body.include?("Project changed from eCookbook to OnlineStore")
1931 1931 end
1932 1932
1933 1933 def test_put_update_with_tracker_change
1934 1934 @request.session[:user_id] = 2
1935 1935 ActionMailer::Base.deliveries.clear
1936 1936
1937 1937 assert_difference('Journal.count') do
1938 1938 assert_difference('JournalDetail.count', 2) do
1939 1939 put :update, :id => 1, :issue => {:project_id => '1',
1940 1940 :tracker_id => '2',
1941 1941 :priority_id => '6'
1942 1942 }
1943 1943 end
1944 1944 end
1945 1945 assert_redirected_to :action => 'show', :id => '1'
1946 1946 issue = Issue.find(1)
1947 1947 assert_equal 1, issue.project_id
1948 1948 assert_equal 2, issue.tracker_id
1949 1949 assert_equal 6, issue.priority_id
1950 1950 assert_equal 1, issue.category_id
1951 1951
1952 1952 mail = ActionMailer::Base.deliveries.last
1953 1953 assert_not_nil mail
1954 1954 assert mail.subject.starts_with?("[#{issue.project.name} - #{issue.tracker.name} ##{issue.id}]")
1955 1955 assert mail.body.include?("Tracker changed from Bug to Feature request")
1956 1956 end
1957 1957
1958 1958 def test_put_update_with_custom_field_change
1959 1959 @request.session[:user_id] = 2
1960 1960 issue = Issue.find(1)
1961 1961 assert_equal '125', issue.custom_value_for(2).value
1962 1962
1963 1963 assert_difference('Journal.count') do
1964 1964 assert_difference('JournalDetail.count', 3) do
1965 1965 put :update, :id => 1, :issue => {:subject => 'Custom field change',
1966 1966 :priority_id => '6',
1967 1967 :category_id => '1', # no change
1968 1968 :custom_field_values => { '2' => 'New custom value' }
1969 1969 }
1970 1970 end
1971 1971 end
1972 1972 assert_redirected_to :action => 'show', :id => '1'
1973 1973 issue.reload
1974 1974 assert_equal 'New custom value', issue.custom_value_for(2).value
1975 1975
1976 1976 mail = ActionMailer::Base.deliveries.last
1977 1977 assert_kind_of TMail::Mail, mail
1978 1978 assert mail.body.include?("Searchable field changed from 125 to New custom value")
1979 1979 end
1980 1980
1981 1981 def test_put_update_with_status_and_assignee_change
1982 1982 issue = Issue.find(1)
1983 1983 assert_equal 1, issue.status_id
1984 1984 @request.session[:user_id] = 2
1985 1985 assert_difference('TimeEntry.count', 0) do
1986 1986 put :update,
1987 1987 :id => 1,
1988 1988 :issue => { :status_id => 2, :assigned_to_id => 3 },
1989 1989 :notes => 'Assigned to dlopper',
1990 1990 :time_entry => { :hours => '', :comments => '', :activity_id => TimeEntryActivity.first }
1991 1991 end
1992 1992 assert_redirected_to :action => 'show', :id => '1'
1993 1993 issue.reload
1994 1994 assert_equal 2, issue.status_id
1995 1995 j = Journal.find(:first, :order => 'id DESC')
1996 1996 assert_equal 'Assigned to dlopper', j.notes
1997 1997 assert_equal 2, j.details.size
1998 1998
1999 1999 mail = ActionMailer::Base.deliveries.last
2000 2000 assert mail.body.include?("Status changed from New to Assigned")
2001 2001 # subject should contain the new status
2002 2002 assert mail.subject.include?("(#{ IssueStatus.find(2).name })")
2003 2003 end
2004 2004
2005 2005 def test_put_update_with_note_only
2006 2006 notes = 'Note added by IssuesControllerTest#test_update_with_note_only'
2007 2007 # anonymous user
2008 2008 put :update,
2009 2009 :id => 1,
2010 2010 :notes => notes
2011 2011 assert_redirected_to :action => 'show', :id => '1'
2012 2012 j = Journal.find(:first, :order => 'id DESC')
2013 2013 assert_equal notes, j.notes
2014 2014 assert_equal 0, j.details.size
2015 2015 assert_equal User.anonymous, j.user
2016 2016
2017 2017 mail = ActionMailer::Base.deliveries.last
2018 2018 assert mail.body.include?(notes)
2019 2019 end
2020 2020
2021 2021 def test_put_update_with_note_and_spent_time
2022 2022 @request.session[:user_id] = 2
2023 2023 spent_hours_before = Issue.find(1).spent_hours
2024 2024 assert_difference('TimeEntry.count') do
2025 2025 put :update,
2026 2026 :id => 1,
2027 2027 :notes => '2.5 hours added',
2028 2028 :time_entry => { :hours => '2.5', :comments => 'test_put_update_with_note_and_spent_time', :activity_id => TimeEntryActivity.first.id }
2029 2029 end
2030 2030 assert_redirected_to :action => 'show', :id => '1'
2031 2031
2032 2032 issue = Issue.find(1)
2033 2033
2034 2034 j = Journal.find(:first, :order => 'id DESC')
2035 2035 assert_equal '2.5 hours added', j.notes
2036 2036 assert_equal 0, j.details.size
2037 2037
2038 2038 t = issue.time_entries.find_by_comments('test_put_update_with_note_and_spent_time')
2039 2039 assert_not_nil t
2040 2040 assert_equal 2.5, t.hours
2041 2041 assert_equal spent_hours_before + 2.5, issue.spent_hours
2042 2042 end
2043 2043
2044 2044 def test_put_update_with_attachment_only
2045 2045 set_tmp_attachments_directory
2046 2046
2047 2047 # Delete all fixtured journals, a race condition can occur causing the wrong
2048 2048 # journal to get fetched in the next find.
2049 2049 Journal.delete_all
2050 2050
2051 2051 # anonymous user
2052 2052 assert_difference 'Attachment.count' do
2053 2053 put :update, :id => 1,
2054 2054 :notes => '',
2055 2055 :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain'), 'description' => 'test file'}}
2056 2056 end
2057 2057
2058 2058 assert_redirected_to :action => 'show', :id => '1'
2059 2059 j = Issue.find(1).journals.find(:first, :order => 'id DESC')
2060 2060 assert j.notes.blank?
2061 2061 assert_equal 1, j.details.size
2062 2062 assert_equal 'testfile.txt', j.details.first.value
2063 2063 assert_equal User.anonymous, j.user
2064 2064
2065 2065 attachment = Attachment.first(:order => 'id DESC')
2066 2066 assert_equal Issue.find(1), attachment.container
2067 2067 assert_equal User.anonymous, attachment.author
2068 2068 assert_equal 'testfile.txt', attachment.filename
2069 2069 assert_equal 'text/plain', attachment.content_type
2070 2070 assert_equal 'test file', attachment.description
2071 2071 assert_equal 59, attachment.filesize
2072 2072 assert File.exists?(attachment.diskfile)
2073 2073 assert_equal 59, File.size(attachment.diskfile)
2074 2074
2075 2075 mail = ActionMailer::Base.deliveries.last
2076 2076 assert mail.body.include?('testfile.txt')
2077 2077 end
2078 2078
2079 2079 def test_put_update_with_attachment_that_fails_to_save
2080 2080 set_tmp_attachments_directory
2081 2081
2082 2082 # Delete all fixtured journals, a race condition can occur causing the wrong
2083 2083 # journal to get fetched in the next find.
2084 2084 Journal.delete_all
2085 2085
2086 2086 # Mock out the unsaved attachment
2087 2087 Attachment.any_instance.stubs(:create).returns(Attachment.new)
2088 2088
2089 2089 # anonymous user
2090 2090 put :update,
2091 2091 :id => 1,
2092 2092 :notes => '',
2093 2093 :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain')}}
2094 2094 assert_redirected_to :action => 'show', :id => '1'
2095 2095 assert_equal '1 file(s) could not be saved.', flash[:warning]
2096 2096
2097 2097 end if Object.const_defined?(:Mocha)
2098 2098
2099 2099 def test_put_update_with_no_change
2100 2100 issue = Issue.find(1)
2101 2101 issue.journals.clear
2102 2102 ActionMailer::Base.deliveries.clear
2103 2103
2104 2104 put :update,
2105 2105 :id => 1,
2106 2106 :notes => ''
2107 2107 assert_redirected_to :action => 'show', :id => '1'
2108 2108
2109 2109 issue.reload
2110 2110 assert issue.journals.empty?
2111 2111 # No email should be sent
2112 2112 assert ActionMailer::Base.deliveries.empty?
2113 2113 end
2114 2114
2115 2115 def test_put_update_should_send_a_notification
2116 2116 @request.session[:user_id] = 2
2117 2117 ActionMailer::Base.deliveries.clear
2118 2118 issue = Issue.find(1)
2119 2119 old_subject = issue.subject
2120 2120 new_subject = 'Subject modified by IssuesControllerTest#test_post_edit'
2121 2121
2122 2122 put :update, :id => 1, :issue => {:subject => new_subject,
2123 2123 :priority_id => '6',
2124 2124 :category_id => '1' # no change
2125 2125 }
2126 2126 assert_equal 1, ActionMailer::Base.deliveries.size
2127 2127 end
2128 2128
2129 2129 def test_put_update_with_invalid_spent_time_hours_only
2130 2130 @request.session[:user_id] = 2
2131 2131 notes = 'Note added by IssuesControllerTest#test_post_edit_with_invalid_spent_time'
2132 2132
2133 2133 assert_no_difference('Journal.count') do
2134 2134 put :update,
2135 2135 :id => 1,
2136 2136 :notes => notes,
2137 2137 :time_entry => {"comments"=>"", "activity_id"=>"", "hours"=>"2z"}
2138 2138 end
2139 2139 assert_response :success
2140 2140 assert_template 'edit'
2141 2141
2142 2142 assert_error_tag :descendant => {:content => /Activity can't be blank/}
2143 2143 assert_tag :textarea, :attributes => { :name => 'notes' }, :content => notes
2144 2144 assert_tag :input, :attributes => { :name => 'time_entry[hours]', :value => "2z" }
2145 2145 end
2146 2146
2147 2147 def test_put_update_with_invalid_spent_time_comments_only
2148 2148 @request.session[:user_id] = 2
2149 2149 notes = 'Note added by IssuesControllerTest#test_post_edit_with_invalid_spent_time'
2150 2150
2151 2151 assert_no_difference('Journal.count') do
2152 2152 put :update,
2153 2153 :id => 1,
2154 2154 :notes => notes,
2155 2155 :time_entry => {"comments"=>"this is my comment", "activity_id"=>"", "hours"=>""}
2156 2156 end
2157 2157 assert_response :success
2158 2158 assert_template 'edit'
2159 2159
2160 2160 assert_error_tag :descendant => {:content => /Activity can't be blank/}
2161 2161 assert_error_tag :descendant => {:content => /Hours can't be blank/}
2162 2162 assert_tag :textarea, :attributes => { :name => 'notes' }, :content => notes
2163 2163 assert_tag :input, :attributes => { :name => 'time_entry[comments]', :value => "this is my comment" }
2164 2164 end
2165 2165
2166 2166 def test_put_update_should_allow_fixed_version_to_be_set_to_a_subproject
2167 2167 issue = Issue.find(2)
2168 2168 @request.session[:user_id] = 2
2169 2169
2170 2170 put :update,
2171 2171 :id => issue.id,
2172 2172 :issue => {
2173 2173 :fixed_version_id => 4
2174 2174 }
2175 2175
2176 2176 assert_response :redirect
2177 2177 issue.reload
2178 2178 assert_equal 4, issue.fixed_version_id
2179 2179 assert_not_equal issue.project_id, issue.fixed_version.project_id
2180 2180 end
2181 2181
2182 2182 def test_put_update_should_redirect_back_using_the_back_url_parameter
2183 2183 issue = Issue.find(2)
2184 2184 @request.session[:user_id] = 2
2185 2185
2186 2186 put :update,
2187 2187 :id => issue.id,
2188 2188 :issue => {
2189 2189 :fixed_version_id => 4
2190 2190 },
2191 2191 :back_url => '/issues'
2192 2192
2193 2193 assert_response :redirect
2194 2194 assert_redirected_to '/issues'
2195 2195 end
2196 2196
2197 2197 def test_put_update_should_not_redirect_back_using_the_back_url_parameter_off_the_host
2198 2198 issue = Issue.find(2)
2199 2199 @request.session[:user_id] = 2
2200 2200
2201 2201 put :update,
2202 2202 :id => issue.id,
2203 2203 :issue => {
2204 2204 :fixed_version_id => 4
2205 2205 },
2206 2206 :back_url => 'http://google.com'
2207 2207
2208 2208 assert_response :redirect
2209 2209 assert_redirected_to :controller => 'issues', :action => 'show', :id => issue.id
2210 2210 end
2211 2211
2212 2212 def test_get_bulk_edit
2213 2213 @request.session[:user_id] = 2
2214 2214 get :bulk_edit, :ids => [1, 2]
2215 2215 assert_response :success
2216 2216 assert_template 'bulk_edit'
2217 2217
2218 2218 assert_tag :select, :attributes => {:name => 'issue[project_id]'}
2219 2219 assert_tag :input, :attributes => {:name => 'issue[parent_issue_id]'}
2220 2220
2221 2221 # Project specific custom field, date type
2222 2222 field = CustomField.find(9)
2223 2223 assert !field.is_for_all?
2224 2224 assert_equal 'date', field.field_format
2225 2225 assert_tag :input, :attributes => {:name => 'issue[custom_field_values][9]'}
2226 2226
2227 2227 # System wide custom field
2228 2228 assert CustomField.find(1).is_for_all?
2229 2229 assert_tag :select, :attributes => {:name => 'issue[custom_field_values][1]'}
2230 2230
2231 2231 # Be sure we don't display inactive IssuePriorities
2232 2232 assert ! IssuePriority.find(15).active?
2233 2233 assert_no_tag :option, :attributes => {:value => '15'},
2234 2234 :parent => {:tag => 'select', :attributes => {:id => 'issue_priority_id'} }
2235 2235 end
2236 2236
2237 2237 def test_get_bulk_edit_on_different_projects
2238 2238 @request.session[:user_id] = 2
2239 2239 get :bulk_edit, :ids => [1, 2, 6]
2240 2240 assert_response :success
2241 2241 assert_template 'bulk_edit'
2242 2242
2243 2243 # Can not set issues from different projects as children of an issue
2244 2244 assert_no_tag :input, :attributes => {:name => 'issue[parent_issue_id]'}
2245 2245
2246 2246 # Project specific custom field, date type
2247 2247 field = CustomField.find(9)
2248 2248 assert !field.is_for_all?
2249 2249 assert !field.project_ids.include?(Issue.find(6).project_id)
2250 2250 assert_no_tag :input, :attributes => {:name => 'issue[custom_field_values][9]'}
2251 2251 end
2252 2252
2253 2253 def test_get_bulk_edit_with_user_custom_field
2254 2254 field = IssueCustomField.create!(:name => 'Tester', :field_format => 'user', :is_for_all => true)
2255 2255
2256 2256 @request.session[:user_id] = 2
2257 2257 get :bulk_edit, :ids => [1, 2]
2258 2258 assert_response :success
2259 2259 assert_template 'bulk_edit'
2260 2260
2261 2261 assert_tag :select,
2262 2262 :attributes => {:name => "issue[custom_field_values][#{field.id}]"},
2263 2263 :children => {
2264 2264 :only => {:tag => 'option'},
2265 2265 :count => Project.find(1).users.count + 1
2266 2266 }
2267 2267 end
2268 2268
2269 2269 def test_get_bulk_edit_with_version_custom_field
2270 2270 field = IssueCustomField.create!(:name => 'Affected version', :field_format => 'version', :is_for_all => true)
2271 2271
2272 2272 @request.session[:user_id] = 2
2273 2273 get :bulk_edit, :ids => [1, 2]
2274 2274 assert_response :success
2275 2275 assert_template 'bulk_edit'
2276 2276
2277 2277 assert_tag :select,
2278 2278 :attributes => {:name => "issue[custom_field_values][#{field.id}]"},
2279 2279 :children => {
2280 2280 :only => {:tag => 'option'},
2281 2281 :count => Project.find(1).shared_versions.count + 1
2282 2282 }
2283 2283 end
2284 2284
2285 2285 def test_bulk_update
2286 2286 @request.session[:user_id] = 2
2287 2287 # update issues priority
2288 2288 post :bulk_update, :ids => [1, 2], :notes => 'Bulk editing',
2289 2289 :issue => {:priority_id => 7,
2290 2290 :assigned_to_id => '',
2291 2291 :custom_field_values => {'2' => ''}}
2292 2292
2293 2293 assert_response 302
2294 2294 # check that the issues were updated
2295 2295 assert_equal [7, 7], Issue.find_all_by_id([1, 2]).collect {|i| i.priority.id}
2296 2296
2297 2297 issue = Issue.find(1)
2298 2298 journal = issue.journals.find(:first, :order => 'created_on DESC')
2299 2299 assert_equal '125', issue.custom_value_for(2).value
2300 2300 assert_equal 'Bulk editing', journal.notes
2301 2301 assert_equal 1, journal.details.size
2302 2302 end
2303 2303
2304 2304 def test_bulk_update_with_group_assignee
2305 2305 group = Group.find(11)
2306 2306 project = Project.find(1)
2307 2307 project.members << Member.new(:principal => group, :roles => [Role.first])
2308 2308
2309 2309 @request.session[:user_id] = 2
2310 2310 # update issues assignee
2311 2311 post :bulk_update, :ids => [1, 2], :notes => 'Bulk editing',
2312 2312 :issue => {:priority_id => '',
2313 2313 :assigned_to_id => group.id,
2314 2314 :custom_field_values => {'2' => ''}}
2315 2315
2316 2316 assert_response 302
2317 2317 assert_equal [group, group], Issue.find_all_by_id([1, 2]).collect {|i| i.assigned_to}
2318 2318 end
2319 2319
2320 2320 def test_bulk_update_on_different_projects
2321 2321 @request.session[:user_id] = 2
2322 2322 # update issues priority
2323 2323 post :bulk_update, :ids => [1, 2, 6], :notes => 'Bulk editing',
2324 2324 :issue => {:priority_id => 7,
2325 2325 :assigned_to_id => '',
2326 2326 :custom_field_values => {'2' => ''}}
2327 2327
2328 2328 assert_response 302
2329 2329 # check that the issues were updated
2330 2330 assert_equal [7, 7, 7], Issue.find([1,2,6]).map(&:priority_id)
2331 2331
2332 2332 issue = Issue.find(1)
2333 2333 journal = issue.journals.find(:first, :order => 'created_on DESC')
2334 2334 assert_equal '125', issue.custom_value_for(2).value
2335 2335 assert_equal 'Bulk editing', journal.notes
2336 2336 assert_equal 1, journal.details.size
2337 2337 end
2338 2338
2339 2339 def test_bulk_update_on_different_projects_without_rights
2340 2340 @request.session[:user_id] = 3
2341 2341 user = User.find(3)
2342 2342 action = { :controller => "issues", :action => "bulk_update" }
2343 2343 assert user.allowed_to?(action, Issue.find(1).project)
2344 2344 assert ! user.allowed_to?(action, Issue.find(6).project)
2345 2345 post :bulk_update, :ids => [1, 6], :notes => 'Bulk should fail',
2346 2346 :issue => {:priority_id => 7,
2347 2347 :assigned_to_id => '',
2348 2348 :custom_field_values => {'2' => ''}}
2349 2349 assert_response 403
2350 2350 assert_not_equal "Bulk should fail", Journal.last.notes
2351 2351 end
2352 2352
2353 2353 def test_bullk_update_should_send_a_notification
2354 2354 @request.session[:user_id] = 2
2355 2355 ActionMailer::Base.deliveries.clear
2356 2356 post(:bulk_update,
2357 2357 {
2358 2358 :ids => [1, 2],
2359 2359 :notes => 'Bulk editing',
2360 2360 :issue => {
2361 2361 :priority_id => 7,
2362 2362 :assigned_to_id => '',
2363 2363 :custom_field_values => {'2' => ''}
2364 2364 }
2365 2365 })
2366 2366
2367 2367 assert_response 302
2368 2368 assert_equal 2, ActionMailer::Base.deliveries.size
2369 2369 end
2370 2370
2371 2371 def test_bulk_update_project
2372 2372 @request.session[:user_id] = 2
2373 2373 post :bulk_update, :ids => [1, 2], :issue => {:project_id => '2'}
2374 2374 assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook'
2375 2375 # Issues moved to project 2
2376 2376 assert_equal 2, Issue.find(1).project_id
2377 2377 assert_equal 2, Issue.find(2).project_id
2378 2378 # No tracker change
2379 2379 assert_equal 1, Issue.find(1).tracker_id
2380 2380 assert_equal 2, Issue.find(2).tracker_id
2381 2381 end
2382 2382
2383 2383 def test_bulk_update_project_on_single_issue_should_follow_when_needed
2384 2384 @request.session[:user_id] = 2
2385 2385 post :bulk_update, :id => 1, :issue => {:project_id => '2'}, :follow => '1'
2386 2386 assert_redirected_to '/issues/1'
2387 2387 end
2388 2388
2389 2389 def test_bulk_update_project_on_multiple_issues_should_follow_when_needed
2390 2390 @request.session[:user_id] = 2
2391 2391 post :bulk_update, :id => [1, 2], :issue => {:project_id => '2'}, :follow => '1'
2392 2392 assert_redirected_to '/projects/onlinestore/issues'
2393 2393 end
2394 2394
2395 2395 def test_bulk_update_tracker
2396 2396 @request.session[:user_id] = 2
2397 2397 post :bulk_update, :ids => [1, 2], :issue => {:tracker_id => '2'}
2398 2398 assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook'
2399 2399 assert_equal 2, Issue.find(1).tracker_id
2400 2400 assert_equal 2, Issue.find(2).tracker_id
2401 2401 end
2402 2402
2403 2403 def test_bulk_update_status
2404 2404 @request.session[:user_id] = 2
2405 2405 # update issues priority
2406 2406 post :bulk_update, :ids => [1, 2], :notes => 'Bulk editing status',
2407 2407 :issue => {:priority_id => '',
2408 2408 :assigned_to_id => '',
2409 2409 :status_id => '5'}
2410 2410
2411 2411 assert_response 302
2412 2412 issue = Issue.find(1)
2413 2413 assert issue.closed?
2414 2414 end
2415 2415
2416 2416 def test_bulk_update_priority
2417 2417 @request.session[:user_id] = 2
2418 2418 post :bulk_update, :ids => [1, 2], :issue => {:priority_id => 6}
2419 2419
2420 2420 assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook'
2421 2421 assert_equal 6, Issue.find(1).priority_id
2422 2422 assert_equal 6, Issue.find(2).priority_id
2423 2423 end
2424 2424
2425 2425 def test_bulk_update_with_notes
2426 2426 @request.session[:user_id] = 2
2427 2427 post :bulk_update, :ids => [1, 2], :notes => 'Moving two issues'
2428 2428
2429 2429 assert_redirected_to :controller => 'issues', :action => 'index', :project_id => 'ecookbook'
2430 2430 assert_equal 'Moving two issues', Issue.find(1).journals.sort_by(&:id).last.notes
2431 2431 assert_equal 'Moving two issues', Issue.find(2).journals.sort_by(&:id).last.notes
2432 2432 end
2433 2433
2434 2434 def test_bulk_update_parent_id
2435 2435 @request.session[:user_id] = 2
2436 2436 post :bulk_update, :ids => [1, 3],
2437 2437 :notes => 'Bulk editing parent',
2438 2438 :issue => {:priority_id => '', :assigned_to_id => '', :status_id => '', :parent_issue_id => '2'}
2439 2439
2440 2440 assert_response 302
2441 2441 parent = Issue.find(2)
2442 2442 assert_equal parent.id, Issue.find(1).parent_id
2443 2443 assert_equal parent.id, Issue.find(3).parent_id
2444 2444 assert_equal [1, 3], parent.children.collect(&:id).sort
2445 2445 end
2446 2446
2447 2447 def test_bulk_update_custom_field
2448 2448 @request.session[:user_id] = 2
2449 2449 # update issues priority
2450 2450 post :bulk_update, :ids => [1, 2], :notes => 'Bulk editing custom field',
2451 2451 :issue => {:priority_id => '',
2452 2452 :assigned_to_id => '',
2453 2453 :custom_field_values => {'2' => '777'}}
2454 2454
2455 2455 assert_response 302
2456 2456
2457 2457 issue = Issue.find(1)
2458 2458 journal = issue.journals.find(:first, :order => 'created_on DESC')
2459 2459 assert_equal '777', issue.custom_value_for(2).value
2460 2460 assert_equal 1, journal.details.size
2461 2461 assert_equal '125', journal.details.first.old_value
2462 2462 assert_equal '777', journal.details.first.value
2463 2463 end
2464 2464
2465 2465 def test_bulk_update_unassign
2466 2466 assert_not_nil Issue.find(2).assigned_to
2467 2467 @request.session[:user_id] = 2
2468 2468 # unassign issues
2469 2469 post :bulk_update, :ids => [1, 2], :notes => 'Bulk unassigning', :issue => {:assigned_to_id => 'none'}
2470 2470 assert_response 302
2471 2471 # check that the issues were updated
2472 2472 assert_nil Issue.find(2).assigned_to
2473 2473 end
2474 2474
2475 2475 def test_post_bulk_update_should_allow_fixed_version_to_be_set_to_a_subproject
2476 2476 @request.session[:user_id] = 2
2477 2477
2478 2478 post :bulk_update, :ids => [1,2], :issue => {:fixed_version_id => 4}
2479 2479
2480 2480 assert_response :redirect
2481 2481 issues = Issue.find([1,2])
2482 2482 issues.each do |issue|
2483 2483 assert_equal 4, issue.fixed_version_id
2484 2484 assert_not_equal issue.project_id, issue.fixed_version.project_id
2485 2485 end
2486 2486 end
2487 2487
2488 2488 def test_post_bulk_update_should_redirect_back_using_the_back_url_parameter
2489 2489 @request.session[:user_id] = 2
2490 2490 post :bulk_update, :ids => [1,2], :back_url => '/issues'
2491 2491
2492 2492 assert_response :redirect
2493 2493 assert_redirected_to '/issues'
2494 2494 end
2495 2495
2496 2496 def test_post_bulk_update_should_not_redirect_back_using_the_back_url_parameter_off_the_host
2497 2497 @request.session[:user_id] = 2
2498 2498 post :bulk_update, :ids => [1,2], :back_url => 'http://google.com'
2499 2499
2500 2500 assert_response :redirect
2501 2501 assert_redirected_to :controller => 'issues', :action => 'index', :project_id => Project.find(1).identifier
2502 2502 end
2503 2503
2504 2504 def test_bulk_copy_to_another_project
2505 2505 @request.session[:user_id] = 2
2506 2506 assert_difference 'Issue.count', 2 do
2507 2507 assert_no_difference 'Project.find(1).issues.count' do
2508 2508 post :bulk_update, :ids => [1, 2], :issue => {:project_id => '2'}, :copy => '1'
2509 2509 end
2510 2510 end
2511 2511 assert_redirected_to '/projects/ecookbook/issues'
2512 2512 end
2513 2513
2514 2514 def test_bulk_copy_should_allow_not_changing_the_issue_attributes
2515 2515 @request.session[:user_id] = 2
2516 2516 issue_before_move = Issue.find(1)
2517 2517 assert_difference 'Issue.count', 1 do
2518 2518 assert_no_difference 'Project.find(1).issues.count' do
2519 2519 post :bulk_update, :ids => [1], :copy => '1',
2520 2520 :issue => {
2521 2521 :project_id => '2', :tracker_id => '', :assigned_to_id => '',
2522 2522 :status_id => '', :start_date => '', :due_date => ''
2523 2523 }
2524 2524 end
2525 2525 end
2526 2526 issue_after_move = Issue.first(:order => 'id desc', :conditions => {:project_id => 2})
2527 2527 assert_equal issue_before_move.tracker_id, issue_after_move.tracker_id
2528 2528 assert_equal issue_before_move.status_id, issue_after_move.status_id
2529 2529 assert_equal issue_before_move.assigned_to_id, issue_after_move.assigned_to_id
2530 2530 end
2531 2531
2532 2532 def test_bulk_copy_should_allow_changing_the_issue_attributes
2533 2533 # Fixes random test failure with Mysql
2534 2534 # where Issue.all(:limit => 2, :order => 'id desc', :conditions => {:project_id => 2})
2535 2535 # doesn't return the expected results
2536 2536 Issue.delete_all("project_id=2")
2537 2537
2538 2538 @request.session[:user_id] = 2
2539 2539 assert_difference 'Issue.count', 2 do
2540 2540 assert_no_difference 'Project.find(1).issues.count' do
2541 2541 post :bulk_update, :ids => [1, 2], :copy => '1',
2542 2542 :issue => {
2543 2543 :project_id => '2', :tracker_id => '', :assigned_to_id => '4',
2544 2544 :status_id => '3', :start_date => '2009-12-01', :due_date => '2009-12-31'
2545 2545 }
2546 2546 end
2547 2547 end
2548 2548
2549 2549 copied_issues = Issue.all(:limit => 2, :order => 'id desc', :conditions => {:project_id => 2})
2550 2550 assert_equal 2, copied_issues.size
2551 2551 copied_issues.each do |issue|
2552 2552 assert_equal 2, issue.project_id, "Project is incorrect"
2553 2553 assert_equal 4, issue.assigned_to_id, "Assigned to is incorrect"
2554 2554 assert_equal 3, issue.status_id, "Status is incorrect"
2555 2555 assert_equal '2009-12-01', issue.start_date.to_s, "Start date is incorrect"
2556 2556 assert_equal '2009-12-31', issue.due_date.to_s, "Due date is incorrect"
2557 2557 end
2558 2558 end
2559 2559
2560 2560 def test_bulk_copy_should_allow_adding_a_note
2561 2561 @request.session[:user_id] = 2
2562 2562 assert_difference 'Issue.count', 1 do
2563 2563 post :bulk_update, :ids => [1], :copy => '1',
2564 2564 :notes => 'Copying one issue',
2565 2565 :issue => {
2566 2566 :project_id => '', :tracker_id => '', :assigned_to_id => '4',
2567 2567 :status_id => '3', :start_date => '2009-12-01', :due_date => '2009-12-31'
2568 2568 }
2569 2569 end
2570 2570
2571 2571 issue = Issue.first(:order => 'id DESC')
2572 2572 assert_equal 1, issue.journals.size
2573 2573 journal = issue.journals.first
2574 2574 assert_equal 0, journal.details.size
2575 2575 assert_equal 'Copying one issue', journal.notes
2576 2576 end
2577 2577
2578 2578 def test_bulk_copy_to_another_project_should_follow_when_needed
2579 2579 @request.session[:user_id] = 2
2580 2580 post :bulk_update, :ids => [1], :copy => '1', :issue => {:project_id => 2}, :follow => '1'
2581 2581 issue = Issue.first(:order => 'id DESC')
2582 2582 assert_redirected_to :controller => 'issues', :action => 'show', :id => issue
2583 2583 end
2584 2584
2585 2585 def test_destroy_issue_with_no_time_entries
2586 2586 assert_nil TimeEntry.find_by_issue_id(2)
2587 2587 @request.session[:user_id] = 2
2588 2588
2589 2589 assert_difference 'Issue.count', -1 do
2590 2590 delete :destroy, :id => 2
2591 2591 end
2592 2592 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
2593 2593 assert_nil Issue.find_by_id(2)
2594 2594 end
2595 2595
2596 2596 def test_destroy_issues_with_time_entries
2597 2597 @request.session[:user_id] = 2
2598 2598
2599 2599 assert_no_difference 'Issue.count' do
2600 2600 delete :destroy, :ids => [1, 3]
2601 2601 end
2602 2602 assert_response :success
2603 2603 assert_template 'destroy'
2604 2604 assert_not_nil assigns(:hours)
2605 2605 assert Issue.find_by_id(1) && Issue.find_by_id(3)
2606 2606 assert_tag 'form',
2607 2607 :descendant => {:tag => 'input', :attributes => {:name => '_method', :value => 'delete'}}
2608 2608 end
2609 2609
2610 2610 def test_destroy_issues_and_destroy_time_entries
2611 2611 @request.session[:user_id] = 2
2612 2612
2613 2613 assert_difference 'Issue.count', -2 do
2614 2614 assert_difference 'TimeEntry.count', -3 do
2615 2615 delete :destroy, :ids => [1, 3], :todo => 'destroy'
2616 2616 end
2617 2617 end
2618 2618 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
2619 2619 assert !(Issue.find_by_id(1) || Issue.find_by_id(3))
2620 2620 assert_nil TimeEntry.find_by_id([1, 2])
2621 2621 end
2622 2622
2623 2623 def test_destroy_issues_and_assign_time_entries_to_project
2624 2624 @request.session[:user_id] = 2
2625 2625
2626 2626 assert_difference 'Issue.count', -2 do
2627 2627 assert_no_difference 'TimeEntry.count' do
2628 2628 delete :destroy, :ids => [1, 3], :todo => 'nullify'
2629 2629 end
2630 2630 end
2631 2631 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
2632 2632 assert !(Issue.find_by_id(1) || Issue.find_by_id(3))
2633 2633 assert_nil TimeEntry.find(1).issue_id
2634 2634 assert_nil TimeEntry.find(2).issue_id
2635 2635 end
2636 2636
2637 2637 def test_destroy_issues_and_reassign_time_entries_to_another_issue
2638 2638 @request.session[:user_id] = 2
2639 2639
2640 2640 assert_difference 'Issue.count', -2 do
2641 2641 assert_no_difference 'TimeEntry.count' do
2642 2642 delete :destroy, :ids => [1, 3], :todo => 'reassign', :reassign_to_id => 2
2643 2643 end
2644 2644 end
2645 2645 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
2646 2646 assert !(Issue.find_by_id(1) || Issue.find_by_id(3))
2647 2647 assert_equal 2, TimeEntry.find(1).issue_id
2648 2648 assert_equal 2, TimeEntry.find(2).issue_id
2649 2649 end
2650 2650
2651 2651 def test_destroy_issues_from_different_projects
2652 2652 @request.session[:user_id] = 2
2653 2653
2654 2654 assert_difference 'Issue.count', -3 do
2655 2655 delete :destroy, :ids => [1, 2, 6], :todo => 'destroy'
2656 2656 end
2657 2657 assert_redirected_to :controller => 'issues', :action => 'index'
2658 2658 assert !(Issue.find_by_id(1) || Issue.find_by_id(2) || Issue.find_by_id(6))
2659 2659 end
2660 2660
2661 2661 def test_destroy_parent_and_child_issues
2662 2662 parent = Issue.generate!(:project_id => 1, :tracker_id => 1)
2663 2663 child = Issue.generate!(:project_id => 1, :tracker_id => 1, :parent_issue_id => parent.id)
2664 2664 assert child.is_descendant_of?(parent.reload)
2665 2665
2666 2666 @request.session[:user_id] = 2
2667 2667 assert_difference 'Issue.count', -2 do
2668 2668 delete :destroy, :ids => [parent.id, child.id], :todo => 'destroy'
2669 2669 end
2670 2670 assert_response 302
2671 2671 end
2672 2672
2673 2673 def test_default_search_scope
2674 2674 get :index
2675 2675 assert_tag :div, :attributes => {:id => 'quick-search'},
2676 2676 :child => {:tag => 'form',
2677 2677 :child => {:tag => 'input', :attributes => {:name => 'issues', :type => 'hidden', :value => '1'}}}
2678 2678 end
2679 2679 end
General Comments 0
You need to be logged in to leave comments. Login now