##// END OF EJS Templates
Add failing test for #4302....
Jean-Philippe Lang -
r2982:ae082205e21e
parent child
Show More
@@ -1,1153 +1,1158
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 < ActionController::TestCase
25 25 fixtures :projects,
26 26 :users,
27 27 :roles,
28 28 :members,
29 29 :member_roles,
30 30 :issues,
31 31 :issue_statuses,
32 32 :versions,
33 33 :trackers,
34 34 :projects_trackers,
35 35 :issue_categories,
36 36 :enabled_modules,
37 37 :enumerations,
38 38 :attachments,
39 39 :workflows,
40 40 :custom_fields,
41 41 :custom_values,
42 42 :custom_fields_trackers,
43 43 :time_entries,
44 44 :journals,
45 45 :journal_details,
46 46 :queries
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_routing
56 56 assert_routing(
57 57 {:method => :get, :path => '/issues'},
58 58 :controller => 'issues', :action => 'index'
59 59 )
60 60 end
61 61
62 62 def test_index
63 63 Setting.default_language = 'en'
64 64
65 65 get :index
66 66 assert_response :success
67 67 assert_template 'index.rhtml'
68 68 assert_not_nil assigns(:issues)
69 69 assert_nil assigns(:project)
70 70 assert_tag :tag => 'a', :content => /Can't print recipes/
71 71 assert_tag :tag => 'a', :content => /Subproject issue/
72 72 # private projects hidden
73 73 assert_no_tag :tag => 'a', :content => /Issue of a private subproject/
74 74 assert_no_tag :tag => 'a', :content => /Issue on project 2/
75 75 # project column
76 76 assert_tag :tag => 'th', :content => /Project/
77 77 end
78 78
79 79 def test_index_should_not_list_issues_when_module_disabled
80 80 EnabledModule.delete_all("name = 'issue_tracking' AND project_id = 1")
81 81 get :index
82 82 assert_response :success
83 83 assert_template 'index.rhtml'
84 84 assert_not_nil assigns(:issues)
85 85 assert_nil assigns(:project)
86 86 assert_no_tag :tag => 'a', :content => /Can't print recipes/
87 87 assert_tag :tag => 'a', :content => /Subproject issue/
88 88 end
89 89
90 90 def test_index_with_project_routing
91 91 assert_routing(
92 92 {:method => :get, :path => '/projects/23/issues'},
93 93 :controller => 'issues', :action => 'index', :project_id => '23'
94 94 )
95 95 end
96 96
97 97 def test_index_should_not_list_issues_when_module_disabled
98 98 EnabledModule.delete_all("name = 'issue_tracking' AND project_id = 1")
99 99 get :index
100 100 assert_response :success
101 101 assert_template 'index.rhtml'
102 102 assert_not_nil assigns(:issues)
103 103 assert_nil assigns(:project)
104 104 assert_no_tag :tag => 'a', :content => /Can't print recipes/
105 105 assert_tag :tag => 'a', :content => /Subproject issue/
106 106 end
107 107
108 108 def test_index_with_project_routing
109 109 assert_routing(
110 110 {:method => :get, :path => 'projects/23/issues'},
111 111 :controller => 'issues', :action => 'index', :project_id => '23'
112 112 )
113 113 end
114 114
115 115 def test_index_with_project
116 116 Setting.display_subprojects_issues = 0
117 117 get :index, :project_id => 1
118 118 assert_response :success
119 119 assert_template 'index.rhtml'
120 120 assert_not_nil assigns(:issues)
121 121 assert_tag :tag => 'a', :content => /Can't print recipes/
122 122 assert_no_tag :tag => 'a', :content => /Subproject issue/
123 123 end
124 124
125 125 def test_index_with_project_and_subprojects
126 126 Setting.display_subprojects_issues = 1
127 127 get :index, :project_id => 1
128 128 assert_response :success
129 129 assert_template 'index.rhtml'
130 130 assert_not_nil assigns(:issues)
131 131 assert_tag :tag => 'a', :content => /Can't print recipes/
132 132 assert_tag :tag => 'a', :content => /Subproject issue/
133 133 assert_no_tag :tag => 'a', :content => /Issue of a private subproject/
134 134 end
135 135
136 136 def test_index_with_project_and_subprojects_should_show_private_subprojects
137 137 @request.session[:user_id] = 2
138 138 Setting.display_subprojects_issues = 1
139 139 get :index, :project_id => 1
140 140 assert_response :success
141 141 assert_template 'index.rhtml'
142 142 assert_not_nil assigns(:issues)
143 143 assert_tag :tag => 'a', :content => /Can't print recipes/
144 144 assert_tag :tag => 'a', :content => /Subproject issue/
145 145 assert_tag :tag => 'a', :content => /Issue of a private subproject/
146 146 end
147 147
148 148 def test_index_with_project_routing_formatted
149 149 assert_routing(
150 150 {:method => :get, :path => 'projects/23/issues.pdf'},
151 151 :controller => 'issues', :action => 'index', :project_id => '23', :format => 'pdf'
152 152 )
153 153 assert_routing(
154 154 {:method => :get, :path => 'projects/23/issues.atom'},
155 155 :controller => 'issues', :action => 'index', :project_id => '23', :format => 'atom'
156 156 )
157 157 end
158 158
159 159 def test_index_with_project_and_filter
160 160 get :index, :project_id => 1, :set_filter => 1
161 161 assert_response :success
162 162 assert_template 'index.rhtml'
163 163 assert_not_nil assigns(:issues)
164 164 end
165 165
166 166 def test_index_with_query
167 167 get :index, :project_id => 1, :query_id => 5
168 168 assert_response :success
169 169 assert_template 'index.rhtml'
170 170 assert_not_nil assigns(:issues)
171 171 assert_nil assigns(:issue_count_by_group)
172 172 end
173 173
174 174 def test_index_with_query_grouped_by_tracker
175 175 get :index, :project_id => 1, :query_id => 6
176 176 assert_response :success
177 177 assert_template 'index.rhtml'
178 178 assert_not_nil assigns(:issues)
179 179 count_by_group = assigns(:issue_count_by_group)
180 180 assert_kind_of Hash, count_by_group
181 181 assert_kind_of Tracker, count_by_group.keys.first
182 182 assert_not_nil count_by_group[Tracker.find(1)]
183 183 end
184 184
185 185 def test_index_with_query_grouped_by_list_custom_field
186 186 get :index, :project_id => 1, :query_id => 9
187 187 assert_response :success
188 188 assert_template 'index.rhtml'
189 189 assert_not_nil assigns(:issues)
190 190 count_by_group = assigns(:issue_count_by_group)
191 191 assert_kind_of Hash, count_by_group
192 192 assert_kind_of String, count_by_group.keys.first
193 193 assert_not_nil count_by_group['MySQL']
194 194 end
195 195
196 def test_index_sort_by_field_not_included_in_columns
197 Setting.issue_list_default_columns = %w(subject author)
198 get :index, :sort => 'tracker'
199 end
200
196 201 def test_index_csv_with_project
197 202 Setting.default_language = 'en'
198 203
199 204 get :index, :format => 'csv'
200 205 assert_response :success
201 206 assert_not_nil assigns(:issues)
202 207 assert_equal 'text/csv', @response.content_type
203 208 assert @response.body.starts_with?("#,")
204 209
205 210 get :index, :project_id => 1, :format => 'csv'
206 211 assert_response :success
207 212 assert_not_nil assigns(:issues)
208 213 assert_equal 'text/csv', @response.content_type
209 214 end
210 215
211 216 def test_index_formatted
212 217 assert_routing(
213 218 {:method => :get, :path => 'issues.pdf'},
214 219 :controller => 'issues', :action => 'index', :format => 'pdf'
215 220 )
216 221 assert_routing(
217 222 {:method => :get, :path => 'issues.atom'},
218 223 :controller => 'issues', :action => 'index', :format => 'atom'
219 224 )
220 225 end
221 226
222 227 def test_index_pdf
223 228 get :index, :format => 'pdf'
224 229 assert_response :success
225 230 assert_not_nil assigns(:issues)
226 231 assert_equal 'application/pdf', @response.content_type
227 232
228 233 get :index, :project_id => 1, :format => 'pdf'
229 234 assert_response :success
230 235 assert_not_nil assigns(:issues)
231 236 assert_equal 'application/pdf', @response.content_type
232 237
233 238 get :index, :project_id => 1, :query_id => 6, :format => 'pdf'
234 239 assert_response :success
235 240 assert_not_nil assigns(:issues)
236 241 assert_equal 'application/pdf', @response.content_type
237 242 end
238 243
239 244 def test_index_sort
240 245 get :index, :sort => 'tracker,id:desc'
241 246 assert_response :success
242 247
243 248 sort_params = @request.session['issues_index_sort']
244 249 assert sort_params.is_a?(String)
245 250 assert_equal 'tracker,id:desc', sort_params
246 251
247 252 issues = assigns(:issues)
248 253 assert_not_nil issues
249 254 assert !issues.empty?
250 255 assert_equal issues.sort {|a,b| a.tracker == b.tracker ? b.id <=> a.id : a.tracker <=> b.tracker }.collect(&:id), issues.collect(&:id)
251 256 end
252 257
253 258 def test_gantt
254 259 get :gantt, :project_id => 1
255 260 assert_response :success
256 261 assert_template 'gantt.rhtml'
257 262 assert_not_nil assigns(:gantt)
258 263 events = assigns(:gantt).events
259 264 assert_not_nil events
260 265 # Issue with start and due dates
261 266 i = Issue.find(1)
262 267 assert_not_nil i.due_date
263 268 assert events.include?(Issue.find(1))
264 269 # Issue with without due date but targeted to a version with date
265 270 i = Issue.find(2)
266 271 assert_nil i.due_date
267 272 assert events.include?(i)
268 273 end
269 274
270 275 def test_cross_project_gantt
271 276 get :gantt
272 277 assert_response :success
273 278 assert_template 'gantt.rhtml'
274 279 assert_not_nil assigns(:gantt)
275 280 events = assigns(:gantt).events
276 281 assert_not_nil events
277 282 end
278 283
279 284 def test_gantt_export_to_pdf
280 285 get :gantt, :project_id => 1, :format => 'pdf'
281 286 assert_response :success
282 287 assert_equal 'application/pdf', @response.content_type
283 288 assert @response.body.starts_with?('%PDF')
284 289 assert_not_nil assigns(:gantt)
285 290 end
286 291
287 292 def test_cross_project_gantt_export_to_pdf
288 293 get :gantt, :format => 'pdf'
289 294 assert_response :success
290 295 assert_equal 'application/pdf', @response.content_type
291 296 assert @response.body.starts_with?('%PDF')
292 297 assert_not_nil assigns(:gantt)
293 298 end
294 299
295 300 if Object.const_defined?(:Magick)
296 301 def test_gantt_image
297 302 get :gantt, :project_id => 1, :format => 'png'
298 303 assert_response :success
299 304 assert_equal 'image/png', @response.content_type
300 305 end
301 306 else
302 307 puts "RMagick not installed. Skipping tests !!!"
303 308 end
304 309
305 310 def test_calendar
306 311 get :calendar, :project_id => 1
307 312 assert_response :success
308 313 assert_template 'calendar'
309 314 assert_not_nil assigns(:calendar)
310 315 end
311 316
312 317 def test_cross_project_calendar
313 318 get :calendar
314 319 assert_response :success
315 320 assert_template 'calendar'
316 321 assert_not_nil assigns(:calendar)
317 322 end
318 323
319 324 def test_changes
320 325 get :changes, :project_id => 1
321 326 assert_response :success
322 327 assert_not_nil assigns(:journals)
323 328 assert_equal 'application/atom+xml', @response.content_type
324 329 end
325 330
326 331 def test_show_routing
327 332 assert_routing(
328 333 {:method => :get, :path => '/issues/64'},
329 334 :controller => 'issues', :action => 'show', :id => '64'
330 335 )
331 336 end
332 337
333 338 def test_show_routing_formatted
334 339 assert_routing(
335 340 {:method => :get, :path => '/issues/2332.pdf'},
336 341 :controller => 'issues', :action => 'show', :id => '2332', :format => 'pdf'
337 342 )
338 343 assert_routing(
339 344 {:method => :get, :path => '/issues/23123.atom'},
340 345 :controller => 'issues', :action => 'show', :id => '23123', :format => 'atom'
341 346 )
342 347 end
343 348
344 349 def test_show_by_anonymous
345 350 get :show, :id => 1
346 351 assert_response :success
347 352 assert_template 'show.rhtml'
348 353 assert_not_nil assigns(:issue)
349 354 assert_equal Issue.find(1), assigns(:issue)
350 355
351 356 # anonymous role is allowed to add a note
352 357 assert_tag :tag => 'form',
353 358 :descendant => { :tag => 'fieldset',
354 359 :child => { :tag => 'legend',
355 360 :content => /Notes/ } }
356 361 end
357 362
358 363 def test_show_by_manager
359 364 @request.session[:user_id] = 2
360 365 get :show, :id => 1
361 366 assert_response :success
362 367
363 368 assert_tag :tag => 'form',
364 369 :descendant => { :tag => 'fieldset',
365 370 :child => { :tag => 'legend',
366 371 :content => /Change properties/ } },
367 372 :descendant => { :tag => 'fieldset',
368 373 :child => { :tag => 'legend',
369 374 :content => /Log time/ } },
370 375 :descendant => { :tag => 'fieldset',
371 376 :child => { :tag => 'legend',
372 377 :content => /Notes/ } }
373 378 end
374 379
375 380 def test_show_should_deny_anonymous_access_without_permission
376 381 Role.anonymous.remove_permission!(:view_issues)
377 382 get :show, :id => 1
378 383 assert_response :redirect
379 384 end
380 385
381 386 def test_show_should_deny_non_member_access_without_permission
382 387 Role.non_member.remove_permission!(:view_issues)
383 388 @request.session[:user_id] = 9
384 389 get :show, :id => 1
385 390 assert_response 403
386 391 end
387 392
388 393 def test_show_should_deny_member_access_without_permission
389 394 Role.find(1).remove_permission!(:view_issues)
390 395 @request.session[:user_id] = 2
391 396 get :show, :id => 1
392 397 assert_response 403
393 398 end
394 399
395 400 def test_show_should_not_disclose_relations_to_invisible_issues
396 401 Setting.cross_project_issue_relations = '1'
397 402 IssueRelation.create!(:issue_from => Issue.find(1), :issue_to => Issue.find(2), :relation_type => 'relates')
398 403 # Relation to a private project issue
399 404 IssueRelation.create!(:issue_from => Issue.find(1), :issue_to => Issue.find(4), :relation_type => 'relates')
400 405
401 406 get :show, :id => 1
402 407 assert_response :success
403 408
404 409 assert_tag :div, :attributes => { :id => 'relations' },
405 410 :descendant => { :tag => 'a', :content => /#2$/ }
406 411 assert_no_tag :div, :attributes => { :id => 'relations' },
407 412 :descendant => { :tag => 'a', :content => /#4$/ }
408 413 end
409 414
410 415 def test_show_atom
411 416 get :show, :id => 2, :format => 'atom'
412 417 assert_response :success
413 418 assert_template 'changes.rxml'
414 419 # Inline image
415 420 assert @response.body.include?("&lt;img src=\"http://test.host/attachments/download/10\" alt=\"\" /&gt;"), "Body did not match. Body: #{@response.body}"
416 421 end
417 422
418 423 def test_new_routing
419 424 assert_routing(
420 425 {:method => :get, :path => '/projects/1/issues/new'},
421 426 :controller => 'issues', :action => 'new', :project_id => '1'
422 427 )
423 428 assert_recognizes(
424 429 {:controller => 'issues', :action => 'new', :project_id => '1'},
425 430 {:method => :post, :path => '/projects/1/issues'}
426 431 )
427 432 end
428 433
429 434 def test_show_export_to_pdf
430 435 get :show, :id => 3, :format => 'pdf'
431 436 assert_response :success
432 437 assert_equal 'application/pdf', @response.content_type
433 438 assert @response.body.starts_with?('%PDF')
434 439 assert_not_nil assigns(:issue)
435 440 end
436 441
437 442 def test_get_new
438 443 @request.session[:user_id] = 2
439 444 get :new, :project_id => 1, :tracker_id => 1
440 445 assert_response :success
441 446 assert_template 'new'
442 447
443 448 assert_tag :tag => 'input', :attributes => { :name => 'issue[custom_field_values][2]',
444 449 :value => 'Default string' }
445 450 end
446 451
447 452 def test_get_new_without_tracker_id
448 453 @request.session[:user_id] = 2
449 454 get :new, :project_id => 1
450 455 assert_response :success
451 456 assert_template 'new'
452 457
453 458 issue = assigns(:issue)
454 459 assert_not_nil issue
455 460 assert_equal Project.find(1).trackers.first, issue.tracker
456 461 end
457 462
458 463 def test_get_new_with_no_default_status_should_display_an_error
459 464 @request.session[:user_id] = 2
460 465 IssueStatus.delete_all
461 466
462 467 get :new, :project_id => 1
463 468 assert_response 500
464 469 assert_not_nil flash[:error]
465 470 assert_tag :tag => 'div', :attributes => { :class => /error/ },
466 471 :content => /No default issue/
467 472 end
468 473
469 474 def test_get_new_with_no_tracker_should_display_an_error
470 475 @request.session[:user_id] = 2
471 476 Tracker.delete_all
472 477
473 478 get :new, :project_id => 1
474 479 assert_response 500
475 480 assert_not_nil flash[:error]
476 481 assert_tag :tag => 'div', :attributes => { :class => /error/ },
477 482 :content => /No tracker/
478 483 end
479 484
480 485 def test_update_new_form
481 486 @request.session[:user_id] = 2
482 487 xhr :post, :new, :project_id => 1,
483 488 :issue => {:tracker_id => 2,
484 489 :subject => 'This is the test_new issue',
485 490 :description => 'This is the description',
486 491 :priority_id => 5}
487 492 assert_response :success
488 493 assert_template 'new'
489 494 end
490 495
491 496 def test_post_new
492 497 @request.session[:user_id] = 2
493 498 assert_difference 'Issue.count' do
494 499 post :new, :project_id => 1,
495 500 :issue => {:tracker_id => 3,
496 501 :subject => 'This is the test_new issue',
497 502 :description => 'This is the description',
498 503 :priority_id => 5,
499 504 :estimated_hours => '',
500 505 :custom_field_values => {'2' => 'Value for field 2'}}
501 506 end
502 507 assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id
503 508
504 509 issue = Issue.find_by_subject('This is the test_new issue')
505 510 assert_not_nil issue
506 511 assert_equal 2, issue.author_id
507 512 assert_equal 3, issue.tracker_id
508 513 assert_nil issue.estimated_hours
509 514 v = issue.custom_values.find(:first, :conditions => {:custom_field_id => 2})
510 515 assert_not_nil v
511 516 assert_equal 'Value for field 2', v.value
512 517 end
513 518
514 519 def test_post_new_and_continue
515 520 @request.session[:user_id] = 2
516 521 post :new, :project_id => 1,
517 522 :issue => {:tracker_id => 3,
518 523 :subject => 'This is first issue',
519 524 :priority_id => 5},
520 525 :continue => ''
521 526 assert_redirected_to :controller => 'issues', :action => 'new', :tracker_id => 3
522 527 end
523 528
524 529 def test_post_new_without_custom_fields_param
525 530 @request.session[:user_id] = 2
526 531 assert_difference 'Issue.count' do
527 532 post :new, :project_id => 1,
528 533 :issue => {:tracker_id => 1,
529 534 :subject => 'This is the test_new issue',
530 535 :description => 'This is the description',
531 536 :priority_id => 5}
532 537 end
533 538 assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id
534 539 end
535 540
536 541 def test_post_new_with_required_custom_field_and_without_custom_fields_param
537 542 field = IssueCustomField.find_by_name('Database')
538 543 field.update_attribute(:is_required, true)
539 544
540 545 @request.session[:user_id] = 2
541 546 post :new, :project_id => 1,
542 547 :issue => {:tracker_id => 1,
543 548 :subject => 'This is the test_new issue',
544 549 :description => 'This is the description',
545 550 :priority_id => 5}
546 551 assert_response :success
547 552 assert_template 'new'
548 553 issue = assigns(:issue)
549 554 assert_not_nil issue
550 555 assert_equal I18n.translate('activerecord.errors.messages.invalid'), issue.errors.on(:custom_values)
551 556 end
552 557
553 558 def test_post_new_with_watchers
554 559 @request.session[:user_id] = 2
555 560 ActionMailer::Base.deliveries.clear
556 561
557 562 assert_difference 'Watcher.count', 2 do
558 563 post :new, :project_id => 1,
559 564 :issue => {:tracker_id => 1,
560 565 :subject => 'This is a new issue with watchers',
561 566 :description => 'This is the description',
562 567 :priority_id => 5,
563 568 :watcher_user_ids => ['2', '3']}
564 569 end
565 570 issue = Issue.find_by_subject('This is a new issue with watchers')
566 571 assert_not_nil issue
567 572 assert_redirected_to :controller => 'issues', :action => 'show', :id => issue
568 573
569 574 # Watchers added
570 575 assert_equal [2, 3], issue.watcher_user_ids.sort
571 576 assert issue.watched_by?(User.find(3))
572 577 # Watchers notified
573 578 mail = ActionMailer::Base.deliveries.last
574 579 assert_kind_of TMail::Mail, mail
575 580 assert [mail.bcc, mail.cc].flatten.include?(User.find(3).mail)
576 581 end
577 582
578 583 def test_post_new_should_send_a_notification
579 584 ActionMailer::Base.deliveries.clear
580 585 @request.session[:user_id] = 2
581 586 assert_difference 'Issue.count' do
582 587 post :new, :project_id => 1,
583 588 :issue => {:tracker_id => 3,
584 589 :subject => 'This is the test_new issue',
585 590 :description => 'This is the description',
586 591 :priority_id => 5,
587 592 :estimated_hours => '',
588 593 :custom_field_values => {'2' => 'Value for field 2'}}
589 594 end
590 595 assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id
591 596
592 597 assert_equal 1, ActionMailer::Base.deliveries.size
593 598 end
594 599
595 600 def test_post_should_preserve_fields_values_on_validation_failure
596 601 @request.session[:user_id] = 2
597 602 post :new, :project_id => 1,
598 603 :issue => {:tracker_id => 1,
599 604 # empty subject
600 605 :subject => '',
601 606 :description => 'This is a description',
602 607 :priority_id => 6,
603 608 :custom_field_values => {'1' => 'Oracle', '2' => 'Value for field 2'}}
604 609 assert_response :success
605 610 assert_template 'new'
606 611
607 612 assert_tag :textarea, :attributes => { :name => 'issue[description]' },
608 613 :content => 'This is a description'
609 614 assert_tag :select, :attributes => { :name => 'issue[priority_id]' },
610 615 :child => { :tag => 'option', :attributes => { :selected => 'selected',
611 616 :value => '6' },
612 617 :content => 'High' }
613 618 # Custom fields
614 619 assert_tag :select, :attributes => { :name => 'issue[custom_field_values][1]' },
615 620 :child => { :tag => 'option', :attributes => { :selected => 'selected',
616 621 :value => 'Oracle' },
617 622 :content => 'Oracle' }
618 623 assert_tag :input, :attributes => { :name => 'issue[custom_field_values][2]',
619 624 :value => 'Value for field 2'}
620 625 end
621 626
622 627 def test_copy_routing
623 628 assert_routing(
624 629 {:method => :get, :path => '/projects/world_domination/issues/567/copy'},
625 630 :controller => 'issues', :action => 'new', :project_id => 'world_domination', :copy_from => '567'
626 631 )
627 632 end
628 633
629 634 def test_copy_issue
630 635 @request.session[:user_id] = 2
631 636 get :new, :project_id => 1, :copy_from => 1
632 637 assert_template 'new'
633 638 assert_not_nil assigns(:issue)
634 639 orig = Issue.find(1)
635 640 assert_equal orig.subject, assigns(:issue).subject
636 641 end
637 642
638 643 def test_edit_routing
639 644 assert_routing(
640 645 {:method => :get, :path => '/issues/1/edit'},
641 646 :controller => 'issues', :action => 'edit', :id => '1'
642 647 )
643 648 assert_recognizes( #TODO: use a PUT on the issue URI isntead, need to adjust form
644 649 {:controller => 'issues', :action => 'edit', :id => '1'},
645 650 {:method => :post, :path => '/issues/1/edit'}
646 651 )
647 652 end
648 653
649 654 def test_get_edit
650 655 @request.session[:user_id] = 2
651 656 get :edit, :id => 1
652 657 assert_response :success
653 658 assert_template 'edit'
654 659 assert_not_nil assigns(:issue)
655 660 assert_equal Issue.find(1), assigns(:issue)
656 661 end
657 662
658 663 def test_get_edit_with_params
659 664 @request.session[:user_id] = 2
660 665 get :edit, :id => 1, :issue => { :status_id => 5, :priority_id => 7 }
661 666 assert_response :success
662 667 assert_template 'edit'
663 668
664 669 issue = assigns(:issue)
665 670 assert_not_nil issue
666 671
667 672 assert_equal 5, issue.status_id
668 673 assert_tag :select, :attributes => { :name => 'issue[status_id]' },
669 674 :child => { :tag => 'option',
670 675 :content => 'Closed',
671 676 :attributes => { :selected => 'selected' } }
672 677
673 678 assert_equal 7, issue.priority_id
674 679 assert_tag :select, :attributes => { :name => 'issue[priority_id]' },
675 680 :child => { :tag => 'option',
676 681 :content => 'Urgent',
677 682 :attributes => { :selected => 'selected' } }
678 683 end
679 684
680 685 def test_reply_routing
681 686 assert_routing(
682 687 {:method => :post, :path => '/issues/1/quoted'},
683 688 :controller => 'issues', :action => 'reply', :id => '1'
684 689 )
685 690 end
686 691
687 692 def test_reply_to_issue
688 693 @request.session[:user_id] = 2
689 694 get :reply, :id => 1
690 695 assert_response :success
691 696 assert_select_rjs :show, "update"
692 697 end
693 698
694 699 def test_reply_to_note
695 700 @request.session[:user_id] = 2
696 701 get :reply, :id => 1, :journal_id => 2
697 702 assert_response :success
698 703 assert_select_rjs :show, "update"
699 704 end
700 705
701 706 def test_post_edit_without_custom_fields_param
702 707 @request.session[:user_id] = 2
703 708 ActionMailer::Base.deliveries.clear
704 709
705 710 issue = Issue.find(1)
706 711 assert_equal '125', issue.custom_value_for(2).value
707 712 old_subject = issue.subject
708 713 new_subject = 'Subject modified by IssuesControllerTest#test_post_edit'
709 714
710 715 assert_difference('Journal.count') do
711 716 assert_difference('JournalDetail.count', 2) do
712 717 post :edit, :id => 1, :issue => {:subject => new_subject,
713 718 :priority_id => '6',
714 719 :category_id => '1' # no change
715 720 }
716 721 end
717 722 end
718 723 assert_redirected_to :action => 'show', :id => '1'
719 724 issue.reload
720 725 assert_equal new_subject, issue.subject
721 726 # Make sure custom fields were not cleared
722 727 assert_equal '125', issue.custom_value_for(2).value
723 728
724 729 mail = ActionMailer::Base.deliveries.last
725 730 assert_kind_of TMail::Mail, mail
726 731 assert mail.subject.starts_with?("[#{issue.project.name} - #{issue.tracker.name} ##{issue.id}]")
727 732 assert mail.body.include?("Subject changed from #{old_subject} to #{new_subject}")
728 733 end
729 734
730 735 def test_post_edit_with_custom_field_change
731 736 @request.session[:user_id] = 2
732 737 issue = Issue.find(1)
733 738 assert_equal '125', issue.custom_value_for(2).value
734 739
735 740 assert_difference('Journal.count') do
736 741 assert_difference('JournalDetail.count', 3) do
737 742 post :edit, :id => 1, :issue => {:subject => 'Custom field change',
738 743 :priority_id => '6',
739 744 :category_id => '1', # no change
740 745 :custom_field_values => { '2' => 'New custom value' }
741 746 }
742 747 end
743 748 end
744 749 assert_redirected_to :action => 'show', :id => '1'
745 750 issue.reload
746 751 assert_equal 'New custom value', issue.custom_value_for(2).value
747 752
748 753 mail = ActionMailer::Base.deliveries.last
749 754 assert_kind_of TMail::Mail, mail
750 755 assert mail.body.include?("Searchable field changed from 125 to New custom value")
751 756 end
752 757
753 758 def test_post_edit_with_status_and_assignee_change
754 759 issue = Issue.find(1)
755 760 assert_equal 1, issue.status_id
756 761 @request.session[:user_id] = 2
757 762 assert_difference('TimeEntry.count', 0) do
758 763 post :edit,
759 764 :id => 1,
760 765 :issue => { :status_id => 2, :assigned_to_id => 3 },
761 766 :notes => 'Assigned to dlopper',
762 767 :time_entry => { :hours => '', :comments => '', :activity_id => TimeEntryActivity.first }
763 768 end
764 769 assert_redirected_to :action => 'show', :id => '1'
765 770 issue.reload
766 771 assert_equal 2, issue.status_id
767 772 j = issue.journals.find(:first, :order => 'id DESC')
768 773 assert_equal 'Assigned to dlopper', j.notes
769 774 assert_equal 2, j.details.size
770 775
771 776 mail = ActionMailer::Base.deliveries.last
772 777 assert mail.body.include?("Status changed from New to Assigned")
773 778 # subject should contain the new status
774 779 assert mail.subject.include?("(#{ IssueStatus.find(2).name })")
775 780 end
776 781
777 782 def test_post_edit_with_note_only
778 783 notes = 'Note added by IssuesControllerTest#test_update_with_note_only'
779 784 # anonymous user
780 785 post :edit,
781 786 :id => 1,
782 787 :notes => notes
783 788 assert_redirected_to :action => 'show', :id => '1'
784 789 j = Issue.find(1).journals.find(:first, :order => 'id DESC')
785 790 assert_equal notes, j.notes
786 791 assert_equal 0, j.details.size
787 792 assert_equal User.anonymous, j.user
788 793
789 794 mail = ActionMailer::Base.deliveries.last
790 795 assert mail.body.include?(notes)
791 796 end
792 797
793 798 def test_post_edit_with_note_and_spent_time
794 799 @request.session[:user_id] = 2
795 800 spent_hours_before = Issue.find(1).spent_hours
796 801 assert_difference('TimeEntry.count') do
797 802 post :edit,
798 803 :id => 1,
799 804 :notes => '2.5 hours added',
800 805 :time_entry => { :hours => '2.5', :comments => '', :activity_id => TimeEntryActivity.first }
801 806 end
802 807 assert_redirected_to :action => 'show', :id => '1'
803 808
804 809 issue = Issue.find(1)
805 810
806 811 j = issue.journals.find(:first, :order => 'id DESC')
807 812 assert_equal '2.5 hours added', j.notes
808 813 assert_equal 0, j.details.size
809 814
810 815 t = issue.time_entries.find(:first, :order => 'id DESC')
811 816 assert_not_nil t
812 817 assert_equal 2.5, t.hours
813 818 assert_equal spent_hours_before + 2.5, issue.spent_hours
814 819 end
815 820
816 821 def test_post_edit_with_attachment_only
817 822 set_tmp_attachments_directory
818 823
819 824 # Delete all fixtured journals, a race condition can occur causing the wrong
820 825 # journal to get fetched in the next find.
821 826 Journal.delete_all
822 827
823 828 # anonymous user
824 829 post :edit,
825 830 :id => 1,
826 831 :notes => '',
827 832 :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain')}}
828 833 assert_redirected_to :action => 'show', :id => '1'
829 834 j = Issue.find(1).journals.find(:first, :order => 'id DESC')
830 835 assert j.notes.blank?
831 836 assert_equal 1, j.details.size
832 837 assert_equal 'testfile.txt', j.details.first.value
833 838 assert_equal User.anonymous, j.user
834 839
835 840 mail = ActionMailer::Base.deliveries.last
836 841 assert mail.body.include?('testfile.txt')
837 842 end
838 843
839 844 def test_post_edit_with_no_change
840 845 issue = Issue.find(1)
841 846 issue.journals.clear
842 847 ActionMailer::Base.deliveries.clear
843 848
844 849 post :edit,
845 850 :id => 1,
846 851 :notes => ''
847 852 assert_redirected_to :action => 'show', :id => '1'
848 853
849 854 issue.reload
850 855 assert issue.journals.empty?
851 856 # No email should be sent
852 857 assert ActionMailer::Base.deliveries.empty?
853 858 end
854 859
855 860 def test_post_edit_should_send_a_notification
856 861 @request.session[:user_id] = 2
857 862 ActionMailer::Base.deliveries.clear
858 863 issue = Issue.find(1)
859 864 old_subject = issue.subject
860 865 new_subject = 'Subject modified by IssuesControllerTest#test_post_edit'
861 866
862 867 post :edit, :id => 1, :issue => {:subject => new_subject,
863 868 :priority_id => '6',
864 869 :category_id => '1' # no change
865 870 }
866 871 assert_equal 1, ActionMailer::Base.deliveries.size
867 872 end
868 873
869 874 def test_post_edit_with_invalid_spent_time
870 875 @request.session[:user_id] = 2
871 876 notes = 'Note added by IssuesControllerTest#test_post_edit_with_invalid_spent_time'
872 877
873 878 assert_no_difference('Journal.count') do
874 879 post :edit,
875 880 :id => 1,
876 881 :notes => notes,
877 882 :time_entry => {"comments"=>"", "activity_id"=>"", "hours"=>"2z"}
878 883 end
879 884 assert_response :success
880 885 assert_template 'edit'
881 886
882 887 assert_tag :textarea, :attributes => { :name => 'notes' },
883 888 :content => notes
884 889 assert_tag :input, :attributes => { :name => 'time_entry[hours]', :value => "2z" }
885 890 end
886 891
887 892 def test_get_bulk_edit
888 893 @request.session[:user_id] = 2
889 894 get :bulk_edit, :ids => [1, 2]
890 895 assert_response :success
891 896 assert_template 'bulk_edit'
892 897 end
893 898
894 899 def test_bulk_edit
895 900 @request.session[:user_id] = 2
896 901 # update issues priority
897 902 post :bulk_edit, :ids => [1, 2], :priority_id => 7,
898 903 :assigned_to_id => '',
899 904 :custom_field_values => {'2' => ''},
900 905 :notes => 'Bulk editing'
901 906 assert_response 302
902 907 # check that the issues were updated
903 908 assert_equal [7, 7], Issue.find_all_by_id([1, 2]).collect {|i| i.priority.id}
904 909
905 910 issue = Issue.find(1)
906 911 journal = issue.journals.find(:first, :order => 'created_on DESC')
907 912 assert_equal '125', issue.custom_value_for(2).value
908 913 assert_equal 'Bulk editing', journal.notes
909 914 assert_equal 1, journal.details.size
910 915 end
911 916
912 917 def test_bullk_edit_should_send_a_notification
913 918 @request.session[:user_id] = 2
914 919 ActionMailer::Base.deliveries.clear
915 920 post(:bulk_edit,
916 921 {
917 922 :ids => [1, 2],
918 923 :priority_id => 7,
919 924 :assigned_to_id => '',
920 925 :custom_field_values => {'2' => ''},
921 926 :notes => 'Bulk editing'
922 927 })
923 928
924 929 assert_response 302
925 930 assert_equal 2, ActionMailer::Base.deliveries.size
926 931 end
927 932
928 933 def test_bulk_edit_status
929 934 @request.session[:user_id] = 2
930 935 # update issues priority
931 936 post :bulk_edit, :ids => [1, 2], :priority_id => '',
932 937 :assigned_to_id => '',
933 938 :status_id => '5',
934 939 :notes => 'Bulk editing status'
935 940 assert_response 302
936 941 issue = Issue.find(1)
937 942 assert issue.closed?
938 943 end
939 944
940 945 def test_bulk_edit_custom_field
941 946 @request.session[:user_id] = 2
942 947 # update issues priority
943 948 post :bulk_edit, :ids => [1, 2], :priority_id => '',
944 949 :assigned_to_id => '',
945 950 :custom_field_values => {'2' => '777'},
946 951 :notes => 'Bulk editing custom field'
947 952 assert_response 302
948 953
949 954 issue = Issue.find(1)
950 955 journal = issue.journals.find(:first, :order => 'created_on DESC')
951 956 assert_equal '777', issue.custom_value_for(2).value
952 957 assert_equal 1, journal.details.size
953 958 assert_equal '125', journal.details.first.old_value
954 959 assert_equal '777', journal.details.first.value
955 960 end
956 961
957 962 def test_bulk_unassign
958 963 assert_not_nil Issue.find(2).assigned_to
959 964 @request.session[:user_id] = 2
960 965 # unassign issues
961 966 post :bulk_edit, :ids => [1, 2], :notes => 'Bulk unassigning', :assigned_to_id => 'none'
962 967 assert_response 302
963 968 # check that the issues were updated
964 969 assert_nil Issue.find(2).assigned_to
965 970 end
966 971
967 972 def test_move_routing
968 973 assert_routing(
969 974 {:method => :get, :path => '/issues/1/move'},
970 975 :controller => 'issues', :action => 'move', :id => '1'
971 976 )
972 977 assert_recognizes(
973 978 {:controller => 'issues', :action => 'move', :id => '1'},
974 979 {:method => :post, :path => '/issues/1/move'}
975 980 )
976 981 end
977 982
978 983 def test_move_one_issue_to_another_project
979 984 @request.session[:user_id] = 2
980 985 post :move, :id => 1, :new_project_id => 2
981 986 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
982 987 assert_equal 2, Issue.find(1).project_id
983 988 end
984 989
985 990 def test_move_one_issue_to_another_project_should_follow_when_needed
986 991 @request.session[:user_id] = 2
987 992 post :move, :id => 1, :new_project_id => 2, :follow => '1'
988 993 assert_redirected_to '/issues/1'
989 994 end
990 995
991 996 def test_bulk_move_to_another_project
992 997 @request.session[:user_id] = 2
993 998 post :move, :ids => [1, 2], :new_project_id => 2
994 999 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
995 1000 # Issues moved to project 2
996 1001 assert_equal 2, Issue.find(1).project_id
997 1002 assert_equal 2, Issue.find(2).project_id
998 1003 # No tracker change
999 1004 assert_equal 1, Issue.find(1).tracker_id
1000 1005 assert_equal 2, Issue.find(2).tracker_id
1001 1006 end
1002 1007
1003 1008 def test_bulk_move_to_another_tracker
1004 1009 @request.session[:user_id] = 2
1005 1010 post :move, :ids => [1, 2], :new_tracker_id => 2
1006 1011 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
1007 1012 assert_equal 2, Issue.find(1).tracker_id
1008 1013 assert_equal 2, Issue.find(2).tracker_id
1009 1014 end
1010 1015
1011 1016 def test_bulk_copy_to_another_project
1012 1017 @request.session[:user_id] = 2
1013 1018 assert_difference 'Issue.count', 2 do
1014 1019 assert_no_difference 'Project.find(1).issues.count' do
1015 1020 post :move, :ids => [1, 2], :new_project_id => 2, :copy_options => {:copy => '1'}
1016 1021 end
1017 1022 end
1018 1023 assert_redirected_to 'projects/ecookbook/issues'
1019 1024 end
1020 1025
1021 1026 def test_copy_to_another_project_should_follow_when_needed
1022 1027 @request.session[:user_id] = 2
1023 1028 post :move, :ids => [1], :new_project_id => 2, :copy_options => {:copy => '1'}, :follow => '1'
1024 1029 issue = Issue.first(:order => 'id DESC')
1025 1030 assert_redirected_to :controller => 'issues', :action => 'show', :id => issue
1026 1031 end
1027 1032
1028 1033 def test_context_menu_one_issue
1029 1034 @request.session[:user_id] = 2
1030 1035 get :context_menu, :ids => [1]
1031 1036 assert_response :success
1032 1037 assert_template 'context_menu'
1033 1038 assert_tag :tag => 'a', :content => 'Edit',
1034 1039 :attributes => { :href => '/issues/1/edit',
1035 1040 :class => 'icon-edit' }
1036 1041 assert_tag :tag => 'a', :content => 'Closed',
1037 1042 :attributes => { :href => '/issues/1/edit?issue%5Bstatus_id%5D=5',
1038 1043 :class => '' }
1039 1044 assert_tag :tag => 'a', :content => 'Immediate',
1040 1045 :attributes => { :href => '/issues/bulk_edit?ids%5B%5D=1&amp;priority_id=8',
1041 1046 :class => '' }
1042 1047 assert_tag :tag => 'a', :content => 'Dave Lopper',
1043 1048 :attributes => { :href => '/issues/bulk_edit?assigned_to_id=3&amp;ids%5B%5D=1',
1044 1049 :class => '' }
1045 1050 assert_tag :tag => 'a', :content => 'Copy',
1046 1051 :attributes => { :href => '/projects/ecookbook/issues/1/copy',
1047 1052 :class => 'icon-copy' }
1048 1053 assert_tag :tag => 'a', :content => 'Move',
1049 1054 :attributes => { :href => '/issues/move?ids%5B%5D=1',
1050 1055 :class => 'icon-move' }
1051 1056 assert_tag :tag => 'a', :content => 'Delete',
1052 1057 :attributes => { :href => '/issues/destroy?ids%5B%5D=1',
1053 1058 :class => 'icon-del' }
1054 1059 end
1055 1060
1056 1061 def test_context_menu_one_issue_by_anonymous
1057 1062 get :context_menu, :ids => [1]
1058 1063 assert_response :success
1059 1064 assert_template 'context_menu'
1060 1065 assert_tag :tag => 'a', :content => 'Delete',
1061 1066 :attributes => { :href => '#',
1062 1067 :class => 'icon-del disabled' }
1063 1068 end
1064 1069
1065 1070 def test_context_menu_multiple_issues_of_same_project
1066 1071 @request.session[:user_id] = 2
1067 1072 get :context_menu, :ids => [1, 2]
1068 1073 assert_response :success
1069 1074 assert_template 'context_menu'
1070 1075 assert_tag :tag => 'a', :content => 'Edit',
1071 1076 :attributes => { :href => '/issues/bulk_edit?ids%5B%5D=1&amp;ids%5B%5D=2',
1072 1077 :class => 'icon-edit' }
1073 1078 assert_tag :tag => 'a', :content => 'Immediate',
1074 1079 :attributes => { :href => '/issues/bulk_edit?ids%5B%5D=1&amp;ids%5B%5D=2&amp;priority_id=8',
1075 1080 :class => '' }
1076 1081 assert_tag :tag => 'a', :content => 'Dave Lopper',
1077 1082 :attributes => { :href => '/issues/bulk_edit?assigned_to_id=3&amp;ids%5B%5D=1&amp;ids%5B%5D=2',
1078 1083 :class => '' }
1079 1084 assert_tag :tag => 'a', :content => 'Move',
1080 1085 :attributes => { :href => '/issues/move?ids%5B%5D=1&amp;ids%5B%5D=2',
1081 1086 :class => 'icon-move' }
1082 1087 assert_tag :tag => 'a', :content => 'Delete',
1083 1088 :attributes => { :href => '/issues/destroy?ids%5B%5D=1&amp;ids%5B%5D=2',
1084 1089 :class => 'icon-del' }
1085 1090 end
1086 1091
1087 1092 def test_context_menu_multiple_issues_of_different_project
1088 1093 @request.session[:user_id] = 2
1089 1094 get :context_menu, :ids => [1, 2, 4]
1090 1095 assert_response :success
1091 1096 assert_template 'context_menu'
1092 1097 assert_tag :tag => 'a', :content => 'Delete',
1093 1098 :attributes => { :href => '#',
1094 1099 :class => 'icon-del disabled' }
1095 1100 end
1096 1101
1097 1102 def test_destroy_routing
1098 1103 assert_recognizes( #TODO: use DELETE on issue URI (need to change forms)
1099 1104 {:controller => 'issues', :action => 'destroy', :id => '1'},
1100 1105 {:method => :post, :path => '/issues/1/destroy'}
1101 1106 )
1102 1107 end
1103 1108
1104 1109 def test_destroy_issue_with_no_time_entries
1105 1110 assert_nil TimeEntry.find_by_issue_id(2)
1106 1111 @request.session[:user_id] = 2
1107 1112 post :destroy, :id => 2
1108 1113 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
1109 1114 assert_nil Issue.find_by_id(2)
1110 1115 end
1111 1116
1112 1117 def test_destroy_issues_with_time_entries
1113 1118 @request.session[:user_id] = 2
1114 1119 post :destroy, :ids => [1, 3]
1115 1120 assert_response :success
1116 1121 assert_template 'destroy'
1117 1122 assert_not_nil assigns(:hours)
1118 1123 assert Issue.find_by_id(1) && Issue.find_by_id(3)
1119 1124 end
1120 1125
1121 1126 def test_destroy_issues_and_destroy_time_entries
1122 1127 @request.session[:user_id] = 2
1123 1128 post :destroy, :ids => [1, 3], :todo => 'destroy'
1124 1129 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
1125 1130 assert !(Issue.find_by_id(1) || Issue.find_by_id(3))
1126 1131 assert_nil TimeEntry.find_by_id([1, 2])
1127 1132 end
1128 1133
1129 1134 def test_destroy_issues_and_assign_time_entries_to_project
1130 1135 @request.session[:user_id] = 2
1131 1136 post :destroy, :ids => [1, 3], :todo => 'nullify'
1132 1137 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
1133 1138 assert !(Issue.find_by_id(1) || Issue.find_by_id(3))
1134 1139 assert_nil TimeEntry.find(1).issue_id
1135 1140 assert_nil TimeEntry.find(2).issue_id
1136 1141 end
1137 1142
1138 1143 def test_destroy_issues_and_reassign_time_entries_to_another_issue
1139 1144 @request.session[:user_id] = 2
1140 1145 post :destroy, :ids => [1, 3], :todo => 'reassign', :reassign_to_id => 2
1141 1146 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
1142 1147 assert !(Issue.find_by_id(1) || Issue.find_by_id(3))
1143 1148 assert_equal 2, TimeEntry.find(1).issue_id
1144 1149 assert_equal 2, TimeEntry.find(2).issue_id
1145 1150 end
1146 1151
1147 1152 def test_default_search_scope
1148 1153 get :index
1149 1154 assert_tag :div, :attributes => {:id => 'quick-search'},
1150 1155 :child => {:tag => 'form',
1151 1156 :child => {:tag => 'input', :attributes => {:name => 'issues', :type => 'hidden', :value => '1'}}}
1152 1157 end
1153 1158 end
General Comments 0
You need to be logged in to leave comments. Login now