##// END OF EJS Templates
Fixes functional test broken by r2246....
Jean-Philippe Lang -
r2246:a64928fa6be2
parent child
Show More
@@ -1,759 +1,759
1 1 # Redmine - project management software
2 2 # Copyright (C) 2006-2008 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.dirname(__FILE__) + '/../test_helper'
19 19 require 'issues_controller'
20 20
21 21 # Re-raise errors caught by the controller.
22 22 class IssuesController; def rescue_action(e) raise e end; end
23 23
24 24 class IssuesControllerTest < Test::Unit::TestCase
25 25 fixtures :projects,
26 26 :users,
27 27 :roles,
28 28 :members,
29 29 :issues,
30 30 :issue_statuses,
31 31 :versions,
32 32 :trackers,
33 33 :projects_trackers,
34 34 :issue_categories,
35 35 :enabled_modules,
36 36 :enumerations,
37 37 :attachments,
38 38 :workflows,
39 39 :custom_fields,
40 40 :custom_values,
41 41 :custom_fields_trackers,
42 42 :time_entries,
43 43 :journals,
44 44 :journal_details
45 45
46 46 def setup
47 47 @controller = IssuesController.new
48 48 @request = ActionController::TestRequest.new
49 49 @response = ActionController::TestResponse.new
50 50 User.current = nil
51 51 end
52 52
53 53 def test_index
54 54 get :index
55 55 assert_response :success
56 56 assert_template 'index.rhtml'
57 57 assert_not_nil assigns(:issues)
58 58 assert_nil assigns(:project)
59 59 assert_tag :tag => 'a', :content => /Can't print recipes/
60 60 assert_tag :tag => 'a', :content => /Subproject issue/
61 61 # private projects hidden
62 62 assert_no_tag :tag => 'a', :content => /Issue of a private subproject/
63 63 assert_no_tag :tag => 'a', :content => /Issue on project 2/
64 64 end
65 65
66 66 def test_index_should_not_list_issues_when_module_disabled
67 67 EnabledModule.delete_all("name = 'issue_tracking' AND project_id = 1")
68 68 get :index
69 69 assert_response :success
70 70 assert_template 'index.rhtml'
71 71 assert_not_nil assigns(:issues)
72 72 assert_nil assigns(:project)
73 73 assert_no_tag :tag => 'a', :content => /Can't print recipes/
74 74 assert_tag :tag => 'a', :content => /Subproject issue/
75 75 end
76 76
77 77 def test_index_with_project
78 78 Setting.display_subprojects_issues = 0
79 79 get :index, :project_id => 1
80 80 assert_response :success
81 81 assert_template 'index.rhtml'
82 82 assert_not_nil assigns(:issues)
83 83 assert_tag :tag => 'a', :content => /Can't print recipes/
84 84 assert_no_tag :tag => 'a', :content => /Subproject issue/
85 85 end
86 86
87 87 def test_index_with_project_and_subprojects
88 88 Setting.display_subprojects_issues = 1
89 89 get :index, :project_id => 1
90 90 assert_response :success
91 91 assert_template 'index.rhtml'
92 92 assert_not_nil assigns(:issues)
93 93 assert_tag :tag => 'a', :content => /Can't print recipes/
94 94 assert_tag :tag => 'a', :content => /Subproject issue/
95 95 assert_no_tag :tag => 'a', :content => /Issue of a private subproject/
96 96 end
97 97
98 98 def test_index_with_project_and_subprojects_should_show_private_subprojects
99 99 @request.session[:user_id] = 2
100 100 Setting.display_subprojects_issues = 1
101 101 get :index, :project_id => 1
102 102 assert_response :success
103 103 assert_template 'index.rhtml'
104 104 assert_not_nil assigns(:issues)
105 105 assert_tag :tag => 'a', :content => /Can't print recipes/
106 106 assert_tag :tag => 'a', :content => /Subproject issue/
107 107 assert_tag :tag => 'a', :content => /Issue of a private subproject/
108 108 end
109 109
110 110 def test_index_with_project_and_filter
111 111 get :index, :project_id => 1, :set_filter => 1
112 112 assert_response :success
113 113 assert_template 'index.rhtml'
114 114 assert_not_nil assigns(:issues)
115 115 end
116 116
117 117 def test_index_csv_with_project
118 118 get :index, :format => 'csv'
119 119 assert_response :success
120 120 assert_not_nil assigns(:issues)
121 121 assert_equal 'text/csv', @response.content_type
122 122
123 123 get :index, :project_id => 1, :format => 'csv'
124 124 assert_response :success
125 125 assert_not_nil assigns(:issues)
126 126 assert_equal 'text/csv', @response.content_type
127 127 end
128 128
129 129 def test_index_pdf
130 130 get :index, :format => 'pdf'
131 131 assert_response :success
132 132 assert_not_nil assigns(:issues)
133 133 assert_equal 'application/pdf', @response.content_type
134 134
135 135 get :index, :project_id => 1, :format => 'pdf'
136 136 assert_response :success
137 137 assert_not_nil assigns(:issues)
138 138 assert_equal 'application/pdf', @response.content_type
139 139 end
140 140
141 141 def test_index_sort
142 142 get :index, :sort_key => 'tracker'
143 143 assert_response :success
144 144
145 145 sort_params = @request.session['issuesindex_sort']
146 146 assert sort_params.is_a?(Hash)
147 147 assert_equal 'tracker', sort_params[:key]
148 148 assert_equal 'ASC', sort_params[:order]
149 149 end
150 150
151 151 def test_gantt
152 152 get :gantt, :project_id => 1
153 153 assert_response :success
154 154 assert_template 'gantt.rhtml'
155 155 assert_not_nil assigns(:gantt)
156 156 events = assigns(:gantt).events
157 157 assert_not_nil events
158 158 # Issue with start and due dates
159 159 i = Issue.find(1)
160 160 assert_not_nil i.due_date
161 161 assert events.include?(Issue.find(1))
162 162 # Issue with without due date but targeted to a version with date
163 163 i = Issue.find(2)
164 164 assert_nil i.due_date
165 165 assert events.include?(i)
166 166 end
167 167
168 168 def test_cross_project_gantt
169 169 get :gantt
170 170 assert_response :success
171 171 assert_template 'gantt.rhtml'
172 172 assert_not_nil assigns(:gantt)
173 173 events = assigns(:gantt).events
174 174 assert_not_nil events
175 175 end
176 176
177 177 def test_gantt_export_to_pdf
178 178 get :gantt, :project_id => 1, :format => 'pdf'
179 179 assert_response :success
180 180 assert_equal 'application/pdf', @response.content_type
181 181 assert @response.body.starts_with?('%PDF')
182 182 assert_not_nil assigns(:gantt)
183 183 end
184 184
185 185 def test_cross_project_gantt_export_to_pdf
186 186 get :gantt, :format => 'pdf'
187 187 assert_response :success
188 188 assert_equal 'application/pdf', @response.content_type
189 189 assert @response.body.starts_with?('%PDF')
190 190 assert_not_nil assigns(:gantt)
191 191 end
192 192
193 193 if Object.const_defined?(:Magick)
194 194 def test_gantt_image
195 195 get :gantt, :project_id => 1, :format => 'png'
196 196 assert_response :success
197 197 assert_equal 'image/png', @response.content_type
198 198 end
199 199 else
200 200 puts "RMagick not installed. Skipping tests !!!"
201 201 end
202 202
203 203 def test_calendar
204 204 get :calendar, :project_id => 1
205 205 assert_response :success
206 206 assert_template 'calendar'
207 207 assert_not_nil assigns(:calendar)
208 208 end
209 209
210 210 def test_cross_project_calendar
211 211 get :calendar
212 212 assert_response :success
213 213 assert_template 'calendar'
214 214 assert_not_nil assigns(:calendar)
215 215 end
216 216
217 217 def test_changes
218 218 get :changes, :project_id => 1
219 219 assert_response :success
220 220 assert_not_nil assigns(:journals)
221 221 assert_equal 'application/atom+xml', @response.content_type
222 222 end
223 223
224 224 def test_show_by_anonymous
225 225 get :show, :id => 1
226 226 assert_response :success
227 227 assert_template 'show.rhtml'
228 228 assert_not_nil assigns(:issue)
229 229 assert_equal Issue.find(1), assigns(:issue)
230 230
231 231 # anonymous role is allowed to add a note
232 232 assert_tag :tag => 'form',
233 233 :descendant => { :tag => 'fieldset',
234 234 :child => { :tag => 'legend',
235 235 :content => /Notes/ } }
236 236 end
237 237
238 238 def test_show_by_manager
239 239 @request.session[:user_id] = 2
240 240 get :show, :id => 1
241 241 assert_response :success
242 242
243 243 assert_tag :tag => 'form',
244 244 :descendant => { :tag => 'fieldset',
245 245 :child => { :tag => 'legend',
246 246 :content => /Change properties/ } },
247 247 :descendant => { :tag => 'fieldset',
248 248 :child => { :tag => 'legend',
249 249 :content => /Log time/ } },
250 250 :descendant => { :tag => 'fieldset',
251 251 :child => { :tag => 'legend',
252 252 :content => /Notes/ } }
253 253 end
254 254
255 255 def test_show_export_to_pdf
256 256 get :show, :id => 1, :format => 'pdf'
257 257 assert_response :success
258 258 assert_equal 'application/pdf', @response.content_type
259 259 assert @response.body.starts_with?('%PDF')
260 260 assert_not_nil assigns(:issue)
261 261 end
262 262
263 263 def test_get_new
264 264 @request.session[:user_id] = 2
265 265 get :new, :project_id => 1, :tracker_id => 1
266 266 assert_response :success
267 267 assert_template 'new'
268 268
269 269 assert_tag :tag => 'input', :attributes => { :name => 'issue[custom_field_values][2]',
270 270 :value => 'Default string' }
271 271 end
272 272
273 273 def test_get_new_without_tracker_id
274 274 @request.session[:user_id] = 2
275 275 get :new, :project_id => 1
276 276 assert_response :success
277 277 assert_template 'new'
278 278
279 279 issue = assigns(:issue)
280 280 assert_not_nil issue
281 281 assert_equal Project.find(1).trackers.first, issue.tracker
282 282 end
283 283
284 284 def test_update_new_form
285 285 @request.session[:user_id] = 2
286 286 xhr :post, :new, :project_id => 1,
287 287 :issue => {:tracker_id => 2,
288 288 :subject => 'This is the test_new issue',
289 289 :description => 'This is the description',
290 290 :priority_id => 5}
291 291 assert_response :success
292 292 assert_template 'new'
293 293 end
294 294
295 295 def test_post_new
296 296 @request.session[:user_id] = 2
297 297 post :new, :project_id => 1,
298 298 :issue => {:tracker_id => 3,
299 299 :subject => 'This is the test_new issue',
300 300 :description => 'This is the description',
301 301 :priority_id => 5,
302 302 :estimated_hours => '',
303 303 :custom_field_values => {'2' => 'Value for field 2'}}
304 304 assert_redirected_to :controller => 'issues', :action => 'show'
305 305
306 306 issue = Issue.find_by_subject('This is the test_new issue')
307 307 assert_not_nil issue
308 308 assert_equal 2, issue.author_id
309 309 assert_equal 3, issue.tracker_id
310 310 assert_nil issue.estimated_hours
311 311 v = issue.custom_values.find(:first, :conditions => {:custom_field_id => 2})
312 312 assert_not_nil v
313 313 assert_equal 'Value for field 2', v.value
314 314 end
315 315
316 316 def test_post_new_without_custom_fields_param
317 317 @request.session[:user_id] = 2
318 318 post :new, :project_id => 1,
319 319 :issue => {:tracker_id => 1,
320 320 :subject => 'This is the test_new issue',
321 321 :description => 'This is the description',
322 322 :priority_id => 5}
323 323 assert_redirected_to :controller => 'issues', :action => 'show'
324 324 end
325 325
326 326 def test_post_new_with_required_custom_field_and_without_custom_fields_param
327 327 field = IssueCustomField.find_by_name('Database')
328 328 field.update_attribute(:is_required, true)
329 329
330 330 @request.session[:user_id] = 2
331 331 post :new, :project_id => 1,
332 332 :issue => {:tracker_id => 1,
333 333 :subject => 'This is the test_new issue',
334 334 :description => 'This is the description',
335 335 :priority_id => 5}
336 336 assert_response :success
337 337 assert_template 'new'
338 338 issue = assigns(:issue)
339 339 assert_not_nil issue
340 340 assert_equal 'activerecord_error_invalid', issue.errors.on(:custom_values)
341 341 end
342 342
343 343 def test_post_new_with_watchers
344 344 @request.session[:user_id] = 2
345 345 ActionMailer::Base.deliveries.clear
346 346
347 347 assert_difference 'Watcher.count', 2 do
348 348 post :new, :project_id => 1,
349 349 :issue => {:tracker_id => 1,
350 350 :subject => 'This is a new issue with watchers',
351 351 :description => 'This is the description',
352 352 :priority_id => 5,
353 353 :watcher_user_ids => ['2', '3']}
354 354 end
355 355 issue = Issue.find_by_subject('This is a new issue with watchers')
356 356 assert_not_nil issue
357 357 assert_redirected_to :controller => 'issues', :action => 'show', :id => issue
358 358
359 359 # Watchers added
360 360 assert_equal [2, 3], issue.watcher_user_ids.sort
361 361 assert issue.watched_by?(User.find(3))
362 362 # Watchers notified
363 363 mail = ActionMailer::Base.deliveries.last
364 364 assert_kind_of TMail::Mail, mail
365 365 assert [mail.bcc, mail.cc].flatten.include?(User.find(3).mail)
366 366 end
367 367
368 368 def test_post_should_preserve_fields_values_on_validation_failure
369 369 @request.session[:user_id] = 2
370 370 post :new, :project_id => 1,
371 371 :issue => {:tracker_id => 1,
372 :subject => 'This is the test_new issue',
373 # empty description
374 :description => '',
372 # empty subject
373 :subject => '',
374 :description => 'This is a description',
375 375 :priority_id => 6,
376 376 :custom_field_values => {'1' => 'Oracle', '2' => 'Value for field 2'}}
377 377 assert_response :success
378 378 assert_template 'new'
379 379
380 assert_tag :input, :attributes => { :name => 'issue[subject]',
381 :value => 'This is the test_new issue' }
380 assert_tag :textarea, :attributes => { :name => 'issue[description]' },
381 :content => 'This is a description'
382 382 assert_tag :select, :attributes => { :name => 'issue[priority_id]' },
383 383 :child => { :tag => 'option', :attributes => { :selected => 'selected',
384 384 :value => '6' },
385 385 :content => 'High' }
386 386 # Custom fields
387 387 assert_tag :select, :attributes => { :name => 'issue[custom_field_values][1]' },
388 388 :child => { :tag => 'option', :attributes => { :selected => 'selected',
389 389 :value => 'Oracle' },
390 390 :content => 'Oracle' }
391 391 assert_tag :input, :attributes => { :name => 'issue[custom_field_values][2]',
392 392 :value => 'Value for field 2'}
393 393 end
394 394
395 395 def test_copy_issue
396 396 @request.session[:user_id] = 2
397 397 get :new, :project_id => 1, :copy_from => 1
398 398 assert_template 'new'
399 399 assert_not_nil assigns(:issue)
400 400 orig = Issue.find(1)
401 401 assert_equal orig.subject, assigns(:issue).subject
402 402 end
403 403
404 404 def test_get_edit
405 405 @request.session[:user_id] = 2
406 406 get :edit, :id => 1
407 407 assert_response :success
408 408 assert_template 'edit'
409 409 assert_not_nil assigns(:issue)
410 410 assert_equal Issue.find(1), assigns(:issue)
411 411 end
412 412
413 413 def test_get_edit_with_params
414 414 @request.session[:user_id] = 2
415 415 get :edit, :id => 1, :issue => { :status_id => 5, :priority_id => 7 }
416 416 assert_response :success
417 417 assert_template 'edit'
418 418
419 419 issue = assigns(:issue)
420 420 assert_not_nil issue
421 421
422 422 assert_equal 5, issue.status_id
423 423 assert_tag :select, :attributes => { :name => 'issue[status_id]' },
424 424 :child => { :tag => 'option',
425 425 :content => 'Closed',
426 426 :attributes => { :selected => 'selected' } }
427 427
428 428 assert_equal 7, issue.priority_id
429 429 assert_tag :select, :attributes => { :name => 'issue[priority_id]' },
430 430 :child => { :tag => 'option',
431 431 :content => 'Urgent',
432 432 :attributes => { :selected => 'selected' } }
433 433 end
434 434
435 435 def test_reply_to_issue
436 436 @request.session[:user_id] = 2
437 437 get :reply, :id => 1
438 438 assert_response :success
439 439 assert_select_rjs :show, "update"
440 440 end
441 441
442 442 def test_reply_to_note
443 443 @request.session[:user_id] = 2
444 444 get :reply, :id => 1, :journal_id => 2
445 445 assert_response :success
446 446 assert_select_rjs :show, "update"
447 447 end
448 448
449 449 def test_post_edit_without_custom_fields_param
450 450 @request.session[:user_id] = 2
451 451 ActionMailer::Base.deliveries.clear
452 452
453 453 issue = Issue.find(1)
454 454 assert_equal '125', issue.custom_value_for(2).value
455 455 old_subject = issue.subject
456 456 new_subject = 'Subject modified by IssuesControllerTest#test_post_edit'
457 457
458 458 assert_difference('Journal.count') do
459 459 assert_difference('JournalDetail.count', 2) do
460 460 post :edit, :id => 1, :issue => {:subject => new_subject,
461 461 :priority_id => '6',
462 462 :category_id => '1' # no change
463 463 }
464 464 end
465 465 end
466 466 assert_redirected_to 'issues/show/1'
467 467 issue.reload
468 468 assert_equal new_subject, issue.subject
469 469 # Make sure custom fields were not cleared
470 470 assert_equal '125', issue.custom_value_for(2).value
471 471
472 472 mail = ActionMailer::Base.deliveries.last
473 473 assert_kind_of TMail::Mail, mail
474 474 assert mail.subject.starts_with?("[#{issue.project.name} - #{issue.tracker.name} ##{issue.id}]")
475 475 assert mail.body.include?("Subject changed from #{old_subject} to #{new_subject}")
476 476 end
477 477
478 478 def test_post_edit_with_custom_field_change
479 479 @request.session[:user_id] = 2
480 480 issue = Issue.find(1)
481 481 assert_equal '125', issue.custom_value_for(2).value
482 482
483 483 assert_difference('Journal.count') do
484 484 assert_difference('JournalDetail.count', 3) do
485 485 post :edit, :id => 1, :issue => {:subject => 'Custom field change',
486 486 :priority_id => '6',
487 487 :category_id => '1', # no change
488 488 :custom_field_values => { '2' => 'New custom value' }
489 489 }
490 490 end
491 491 end
492 492 assert_redirected_to 'issues/show/1'
493 493 issue.reload
494 494 assert_equal 'New custom value', issue.custom_value_for(2).value
495 495
496 496 mail = ActionMailer::Base.deliveries.last
497 497 assert_kind_of TMail::Mail, mail
498 498 assert mail.body.include?("Searchable field changed from 125 to New custom value")
499 499 end
500 500
501 501 def test_post_edit_with_status_and_assignee_change
502 502 issue = Issue.find(1)
503 503 assert_equal 1, issue.status_id
504 504 @request.session[:user_id] = 2
505 505 assert_difference('TimeEntry.count', 0) do
506 506 post :edit,
507 507 :id => 1,
508 508 :issue => { :status_id => 2, :assigned_to_id => 3 },
509 509 :notes => 'Assigned to dlopper',
510 510 :time_entry => { :hours => '', :comments => '', :activity_id => Enumeration.get_values('ACTI').first }
511 511 end
512 512 assert_redirected_to 'issues/show/1'
513 513 issue.reload
514 514 assert_equal 2, issue.status_id
515 515 j = issue.journals.find(:first, :order => 'id DESC')
516 516 assert_equal 'Assigned to dlopper', j.notes
517 517 assert_equal 2, j.details.size
518 518
519 519 mail = ActionMailer::Base.deliveries.last
520 520 assert mail.body.include?("Status changed from New to Assigned")
521 521 end
522 522
523 523 def test_post_edit_with_note_only
524 524 notes = 'Note added by IssuesControllerTest#test_update_with_note_only'
525 525 # anonymous user
526 526 post :edit,
527 527 :id => 1,
528 528 :notes => notes
529 529 assert_redirected_to 'issues/show/1'
530 530 j = Issue.find(1).journals.find(:first, :order => 'id DESC')
531 531 assert_equal notes, j.notes
532 532 assert_equal 0, j.details.size
533 533 assert_equal User.anonymous, j.user
534 534
535 535 mail = ActionMailer::Base.deliveries.last
536 536 assert mail.body.include?(notes)
537 537 end
538 538
539 539 def test_post_edit_with_note_and_spent_time
540 540 @request.session[:user_id] = 2
541 541 spent_hours_before = Issue.find(1).spent_hours
542 542 assert_difference('TimeEntry.count') do
543 543 post :edit,
544 544 :id => 1,
545 545 :notes => '2.5 hours added',
546 546 :time_entry => { :hours => '2.5', :comments => '', :activity_id => Enumeration.get_values('ACTI').first }
547 547 end
548 548 assert_redirected_to 'issues/show/1'
549 549
550 550 issue = Issue.find(1)
551 551
552 552 j = issue.journals.find(:first, :order => 'id DESC')
553 553 assert_equal '2.5 hours added', j.notes
554 554 assert_equal 0, j.details.size
555 555
556 556 t = issue.time_entries.find(:first, :order => 'id DESC')
557 557 assert_not_nil t
558 558 assert_equal 2.5, t.hours
559 559 assert_equal spent_hours_before + 2.5, issue.spent_hours
560 560 end
561 561
562 562 def test_post_edit_with_attachment_only
563 563 set_tmp_attachments_directory
564 564
565 565 # Delete all fixtured journals, a race condition can occur causing the wrong
566 566 # journal to get fetched in the next find.
567 567 Journal.delete_all
568 568
569 569 # anonymous user
570 570 post :edit,
571 571 :id => 1,
572 572 :notes => '',
573 573 :attachments => {'1' => {'file' => test_uploaded_file('testfile.txt', 'text/plain')}}
574 574 assert_redirected_to 'issues/show/1'
575 575 j = Issue.find(1).journals.find(:first, :order => 'id DESC')
576 576 assert j.notes.blank?
577 577 assert_equal 1, j.details.size
578 578 assert_equal 'testfile.txt', j.details.first.value
579 579 assert_equal User.anonymous, j.user
580 580
581 581 mail = ActionMailer::Base.deliveries.last
582 582 assert mail.body.include?('testfile.txt')
583 583 end
584 584
585 585 def test_post_edit_with_no_change
586 586 issue = Issue.find(1)
587 587 issue.journals.clear
588 588 ActionMailer::Base.deliveries.clear
589 589
590 590 post :edit,
591 591 :id => 1,
592 592 :notes => ''
593 593 assert_redirected_to 'issues/show/1'
594 594
595 595 issue.reload
596 596 assert issue.journals.empty?
597 597 # No email should be sent
598 598 assert ActionMailer::Base.deliveries.empty?
599 599 end
600 600
601 601 def test_bulk_edit
602 602 @request.session[:user_id] = 2
603 603 # update issues priority
604 604 post :bulk_edit, :ids => [1, 2], :priority_id => 7, :notes => 'Bulk editing', :assigned_to_id => ''
605 605 assert_response 302
606 606 # check that the issues were updated
607 607 assert_equal [7, 7], Issue.find_all_by_id([1, 2]).collect {|i| i.priority.id}
608 608 assert_equal 'Bulk editing', Issue.find(1).journals.find(:first, :order => 'created_on DESC').notes
609 609 end
610 610
611 611 def test_bulk_unassign
612 612 assert_not_nil Issue.find(2).assigned_to
613 613 @request.session[:user_id] = 2
614 614 # unassign issues
615 615 post :bulk_edit, :ids => [1, 2], :notes => 'Bulk unassigning', :assigned_to_id => 'none'
616 616 assert_response 302
617 617 # check that the issues were updated
618 618 assert_nil Issue.find(2).assigned_to
619 619 end
620 620
621 621 def test_move_one_issue_to_another_project
622 622 @request.session[:user_id] = 1
623 623 post :move, :id => 1, :new_project_id => 2
624 624 assert_redirected_to 'projects/ecookbook/issues'
625 625 assert_equal 2, Issue.find(1).project_id
626 626 end
627 627
628 628 def test_bulk_move_to_another_project
629 629 @request.session[:user_id] = 1
630 630 post :move, :ids => [1, 2], :new_project_id => 2
631 631 assert_redirected_to 'projects/ecookbook/issues'
632 632 # Issues moved to project 2
633 633 assert_equal 2, Issue.find(1).project_id
634 634 assert_equal 2, Issue.find(2).project_id
635 635 # No tracker change
636 636 assert_equal 1, Issue.find(1).tracker_id
637 637 assert_equal 2, Issue.find(2).tracker_id
638 638 end
639 639
640 640 def test_bulk_move_to_another_tracker
641 641 @request.session[:user_id] = 1
642 642 post :move, :ids => [1, 2], :new_tracker_id => 2
643 643 assert_redirected_to 'projects/ecookbook/issues'
644 644 assert_equal 2, Issue.find(1).tracker_id
645 645 assert_equal 2, Issue.find(2).tracker_id
646 646 end
647 647
648 648 def test_context_menu_one_issue
649 649 @request.session[:user_id] = 2
650 650 get :context_menu, :ids => [1]
651 651 assert_response :success
652 652 assert_template 'context_menu'
653 653 assert_tag :tag => 'a', :content => 'Edit',
654 654 :attributes => { :href => '/issues/edit/1',
655 655 :class => 'icon-edit' }
656 656 assert_tag :tag => 'a', :content => 'Closed',
657 657 :attributes => { :href => '/issues/edit/1?issue%5Bstatus_id%5D=5',
658 658 :class => '' }
659 659 assert_tag :tag => 'a', :content => 'Immediate',
660 660 :attributes => { :href => '/issues/bulk_edit?ids%5B%5D=1&amp;priority_id=8',
661 661 :class => '' }
662 662 assert_tag :tag => 'a', :content => 'Dave Lopper',
663 663 :attributes => { :href => '/issues/bulk_edit?assigned_to_id=3&amp;ids%5B%5D=1',
664 664 :class => '' }
665 665 assert_tag :tag => 'a', :content => 'Copy',
666 666 :attributes => { :href => '/projects/ecookbook/issues/new?copy_from=1',
667 667 :class => 'icon-copy' }
668 668 assert_tag :tag => 'a', :content => 'Move',
669 669 :attributes => { :href => '/issues/move?ids%5B%5D=1',
670 670 :class => 'icon-move' }
671 671 assert_tag :tag => 'a', :content => 'Delete',
672 672 :attributes => { :href => '/issues/destroy?ids%5B%5D=1',
673 673 :class => 'icon-del' }
674 674 end
675 675
676 676 def test_context_menu_one_issue_by_anonymous
677 677 get :context_menu, :ids => [1]
678 678 assert_response :success
679 679 assert_template 'context_menu'
680 680 assert_tag :tag => 'a', :content => 'Delete',
681 681 :attributes => { :href => '#',
682 682 :class => 'icon-del disabled' }
683 683 end
684 684
685 685 def test_context_menu_multiple_issues_of_same_project
686 686 @request.session[:user_id] = 2
687 687 get :context_menu, :ids => [1, 2]
688 688 assert_response :success
689 689 assert_template 'context_menu'
690 690 assert_tag :tag => 'a', :content => 'Edit',
691 691 :attributes => { :href => '/issues/bulk_edit?ids%5B%5D=1&amp;ids%5B%5D=2',
692 692 :class => 'icon-edit' }
693 693 assert_tag :tag => 'a', :content => 'Immediate',
694 694 :attributes => { :href => '/issues/bulk_edit?ids%5B%5D=1&amp;ids%5B%5D=2&amp;priority_id=8',
695 695 :class => '' }
696 696 assert_tag :tag => 'a', :content => 'Dave Lopper',
697 697 :attributes => { :href => '/issues/bulk_edit?assigned_to_id=3&amp;ids%5B%5D=1&amp;ids%5B%5D=2',
698 698 :class => '' }
699 699 assert_tag :tag => 'a', :content => 'Move',
700 700 :attributes => { :href => '/issues/move?ids%5B%5D=1&amp;ids%5B%5D=2',
701 701 :class => 'icon-move' }
702 702 assert_tag :tag => 'a', :content => 'Delete',
703 703 :attributes => { :href => '/issues/destroy?ids%5B%5D=1&amp;ids%5B%5D=2',
704 704 :class => 'icon-del' }
705 705 end
706 706
707 707 def test_context_menu_multiple_issues_of_different_project
708 708 @request.session[:user_id] = 2
709 709 get :context_menu, :ids => [1, 2, 4]
710 710 assert_response :success
711 711 assert_template 'context_menu'
712 712 assert_tag :tag => 'a', :content => 'Delete',
713 713 :attributes => { :href => '#',
714 714 :class => 'icon-del disabled' }
715 715 end
716 716
717 717 def test_destroy_issue_with_no_time_entries
718 718 assert_nil TimeEntry.find_by_issue_id(2)
719 719 @request.session[:user_id] = 2
720 720 post :destroy, :id => 2
721 721 assert_redirected_to 'projects/ecookbook/issues'
722 722 assert_nil Issue.find_by_id(2)
723 723 end
724 724
725 725 def test_destroy_issues_with_time_entries
726 726 @request.session[:user_id] = 2
727 727 post :destroy, :ids => [1, 3]
728 728 assert_response :success
729 729 assert_template 'destroy'
730 730 assert_not_nil assigns(:hours)
731 731 assert Issue.find_by_id(1) && Issue.find_by_id(3)
732 732 end
733 733
734 734 def test_destroy_issues_and_destroy_time_entries
735 735 @request.session[:user_id] = 2
736 736 post :destroy, :ids => [1, 3], :todo => 'destroy'
737 737 assert_redirected_to 'projects/ecookbook/issues'
738 738 assert !(Issue.find_by_id(1) || Issue.find_by_id(3))
739 739 assert_nil TimeEntry.find_by_id([1, 2])
740 740 end
741 741
742 742 def test_destroy_issues_and_assign_time_entries_to_project
743 743 @request.session[:user_id] = 2
744 744 post :destroy, :ids => [1, 3], :todo => 'nullify'
745 745 assert_redirected_to 'projects/ecookbook/issues'
746 746 assert !(Issue.find_by_id(1) || Issue.find_by_id(3))
747 747 assert_nil TimeEntry.find(1).issue_id
748 748 assert_nil TimeEntry.find(2).issue_id
749 749 end
750 750
751 751 def test_destroy_issues_and_reassign_time_entries_to_another_issue
752 752 @request.session[:user_id] = 2
753 753 post :destroy, :ids => [1, 3], :todo => 'reassign', :reassign_to_id => 2
754 754 assert_redirected_to 'projects/ecookbook/issues'
755 755 assert !(Issue.find_by_id(1) || Issue.find_by_id(3))
756 756 assert_equal 2, TimeEntry.find(1).issue_id
757 757 assert_equal 2, TimeEntry.find(2).issue_id
758 758 end
759 759 end
General Comments 0
You need to be logged in to leave comments. Login now