##// END OF EJS Templates
Fixes functional tests broken by r1501....
Jean-Philippe Lang -
r1490:383da1e6d610
parent child
Show More
@@ -1,561 +1,561
1 1 # redMine - project management software
2 2 # Copyright (C) 2006-2007 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 :trackers,
32 32 :projects_trackers,
33 33 :issue_categories,
34 34 :enabled_modules,
35 35 :enumerations,
36 36 :attachments,
37 37 :workflows,
38 38 :custom_fields,
39 39 :custom_values,
40 40 :custom_fields_trackers,
41 :time_entries
41 :time_entries,
42 :journals,
43 :journal_details
42 44
43 45 def setup
44 46 @controller = IssuesController.new
45 47 @request = ActionController::TestRequest.new
46 48 @response = ActionController::TestResponse.new
47 49 User.current = nil
48 50 end
49 51
50 52 def test_index
51 53 get :index
52 54 assert_response :success
53 55 assert_template 'index.rhtml'
54 56 assert_not_nil assigns(:issues)
55 57 assert_nil assigns(:project)
56 58 assert_tag :tag => 'a', :content => /Can't print recipes/
57 59 assert_tag :tag => 'a', :content => /Subproject issue/
58 60 # private projects hidden
59 61 assert_no_tag :tag => 'a', :content => /Issue of a private subproject/
60 62 assert_no_tag :tag => 'a', :content => /Issue on project 2/
61 63 end
62 64
63 65 def test_index_with_project
64 66 Setting.display_subprojects_issues = 0
65 67 get :index, :project_id => 1
66 68 assert_response :success
67 69 assert_template 'index.rhtml'
68 70 assert_not_nil assigns(:issues)
69 71 assert_tag :tag => 'a', :content => /Can't print recipes/
70 72 assert_no_tag :tag => 'a', :content => /Subproject issue/
71 73 end
72 74
73 75 def test_index_with_project_and_subprojects
74 76 Setting.display_subprojects_issues = 1
75 77 get :index, :project_id => 1
76 78 assert_response :success
77 79 assert_template 'index.rhtml'
78 80 assert_not_nil assigns(:issues)
79 81 assert_tag :tag => 'a', :content => /Can't print recipes/
80 82 assert_tag :tag => 'a', :content => /Subproject issue/
81 83 assert_no_tag :tag => 'a', :content => /Issue of a private subproject/
82 84 end
83 85
84 86 def test_index_with_project_and_subprojects_should_show_private_subprojects
85 87 @request.session[:user_id] = 2
86 88 Setting.display_subprojects_issues = 1
87 89 get :index, :project_id => 1
88 90 assert_response :success
89 91 assert_template 'index.rhtml'
90 92 assert_not_nil assigns(:issues)
91 93 assert_tag :tag => 'a', :content => /Can't print recipes/
92 94 assert_tag :tag => 'a', :content => /Subproject issue/
93 95 assert_tag :tag => 'a', :content => /Issue of a private subproject/
94 96 end
95 97
96 98 def test_index_with_project_and_filter
97 99 get :index, :project_id => 1, :set_filter => 1
98 100 assert_response :success
99 101 assert_template 'index.rhtml'
100 102 assert_not_nil assigns(:issues)
101 103 end
102 104
103 105 def test_index_csv_with_project
104 106 get :index, :format => 'csv'
105 107 assert_response :success
106 108 assert_not_nil assigns(:issues)
107 109 assert_equal 'text/csv', @response.content_type
108 110
109 111 get :index, :project_id => 1, :format => 'csv'
110 112 assert_response :success
111 113 assert_not_nil assigns(:issues)
112 114 assert_equal 'text/csv', @response.content_type
113 115 end
114 116
115 117 def test_index_pdf
116 118 get :index, :format => 'pdf'
117 119 assert_response :success
118 120 assert_not_nil assigns(:issues)
119 121 assert_equal 'application/pdf', @response.content_type
120 122
121 123 get :index, :project_id => 1, :format => 'pdf'
122 124 assert_response :success
123 125 assert_not_nil assigns(:issues)
124 126 assert_equal 'application/pdf', @response.content_type
125 127 end
126 128
127 129 def test_changes
128 130 get :changes, :project_id => 1
129 131 assert_response :success
130 132 assert_not_nil assigns(:journals)
131 133 assert_equal 'application/atom+xml', @response.content_type
132 134 end
133 135
134 136 def test_show_by_anonymous
135 137 get :show, :id => 1
136 138 assert_response :success
137 139 assert_template 'show.rhtml'
138 140 assert_not_nil assigns(:issue)
139 141 assert_equal Issue.find(1), assigns(:issue)
140 142
141 143 # anonymous role is allowed to add a note
142 144 assert_tag :tag => 'form',
143 145 :descendant => { :tag => 'fieldset',
144 146 :child => { :tag => 'legend',
145 147 :content => /Notes/ } }
146 148 end
147 149
148 150 def test_show_by_manager
149 151 @request.session[:user_id] = 2
150 152 get :show, :id => 1
151 153 assert_response :success
152 154
153 155 assert_tag :tag => 'form',
154 156 :descendant => { :tag => 'fieldset',
155 157 :child => { :tag => 'legend',
156 158 :content => /Change properties/ } },
157 159 :descendant => { :tag => 'fieldset',
158 160 :child => { :tag => 'legend',
159 161 :content => /Log time/ } },
160 162 :descendant => { :tag => 'fieldset',
161 163 :child => { :tag => 'legend',
162 164 :content => /Notes/ } }
163 165 end
164 166
165 167 def test_get_new
166 168 @request.session[:user_id] = 2
167 169 get :new, :project_id => 1, :tracker_id => 1
168 170 assert_response :success
169 171 assert_template 'new'
170 172
171 173 assert_tag :tag => 'input', :attributes => { :name => 'custom_fields[2]',
172 174 :value => 'Default string' }
173 175 end
174 176
175 177 def test_get_new_without_tracker_id
176 178 @request.session[:user_id] = 2
177 179 get :new, :project_id => 1
178 180 assert_response :success
179 181 assert_template 'new'
180 182
181 183 issue = assigns(:issue)
182 184 assert_not_nil issue
183 185 assert_equal Project.find(1).trackers.first, issue.tracker
184 186 end
185 187
186 188 def test_update_new_form
187 189 @request.session[:user_id] = 2
188 190 xhr :post, :new, :project_id => 1,
189 191 :issue => {:tracker_id => 2,
190 192 :subject => 'This is the test_new issue',
191 193 :description => 'This is the description',
192 194 :priority_id => 5}
193 195 assert_response :success
194 196 assert_template 'new'
195 197 end
196 198
197 199 def test_post_new
198 200 @request.session[:user_id] = 2
199 201 post :new, :project_id => 1,
200 202 :issue => {:tracker_id => 1,
201 203 :subject => 'This is the test_new issue',
202 204 :description => 'This is the description',
203 205 :priority_id => 5,
204 206 :estimated_hours => ''},
205 207 :custom_fields => {'2' => 'Value for field 2'}
206 208 assert_redirected_to 'issues/show'
207 209
208 210 issue = Issue.find_by_subject('This is the test_new issue')
209 211 assert_not_nil issue
210 212 assert_equal 2, issue.author_id
211 213 assert_nil issue.estimated_hours
212 214 v = issue.custom_values.find_by_custom_field_id(2)
213 215 assert_not_nil v
214 216 assert_equal 'Value for field 2', v.value
215 217 end
216 218
217 219 def test_post_new_without_custom_fields_param
218 220 @request.session[:user_id] = 2
219 221 post :new, :project_id => 1,
220 222 :issue => {:tracker_id => 1,
221 223 :subject => 'This is the test_new issue',
222 224 :description => 'This is the description',
223 225 :priority_id => 5}
224 226 assert_redirected_to 'issues/show'
225 227 end
226 228
227 229 def test_copy_issue
228 230 @request.session[:user_id] = 2
229 231 get :new, :project_id => 1, :copy_from => 1
230 232 assert_template 'new'
231 233 assert_not_nil assigns(:issue)
232 234 orig = Issue.find(1)
233 235 assert_equal orig.subject, assigns(:issue).subject
234 236 end
235 237
236 238 def test_get_edit
237 239 @request.session[:user_id] = 2
238 240 get :edit, :id => 1
239 241 assert_response :success
240 242 assert_template 'edit'
241 243 assert_not_nil assigns(:issue)
242 244 assert_equal Issue.find(1), assigns(:issue)
243 245 end
244 246
245 247 def test_get_edit_with_params
246 248 @request.session[:user_id] = 2
247 249 get :edit, :id => 1, :issue => { :status_id => 5, :priority_id => 7 }
248 250 assert_response :success
249 251 assert_template 'edit'
250 252
251 253 issue = assigns(:issue)
252 254 assert_not_nil issue
253 255
254 256 assert_equal 5, issue.status_id
255 257 assert_tag :select, :attributes => { :name => 'issue[status_id]' },
256 258 :child => { :tag => 'option',
257 259 :content => 'Closed',
258 260 :attributes => { :selected => 'selected' } }
259 261
260 262 assert_equal 7, issue.priority_id
261 263 assert_tag :select, :attributes => { :name => 'issue[priority_id]' },
262 264 :child => { :tag => 'option',
263 265 :content => 'Urgent',
264 266 :attributes => { :selected => 'selected' } }
265 267 end
266 268
267 269 def test_reply_to_issue
268 270 @request.session[:user_id] = 2
269 271 get :reply, :id => 1
270 272 assert_response :success
271 273 assert_select_rjs :show, "update"
272 assert_select_rjs :replace_html, "notes"
273 274 end
274 275
275 276 def test_reply_to_note
276 277 @request.session[:user_id] = 2
277 278 get :reply, :id => 1, :journal_id => 2
278 279 assert_response :success
279 280 assert_select_rjs :show, "update"
280 assert_select_rjs :replace_html, "notes"
281 281 end
282 282
283 283 def test_post_edit
284 284 @request.session[:user_id] = 2
285 285 ActionMailer::Base.deliveries.clear
286 286
287 287 issue = Issue.find(1)
288 288 old_subject = issue.subject
289 289 new_subject = 'Subject modified by IssuesControllerTest#test_post_edit'
290 290
291 291 post :edit, :id => 1, :issue => {:subject => new_subject}
292 292 assert_redirected_to 'issues/show/1'
293 293 issue.reload
294 294 assert_equal new_subject, issue.subject
295 295
296 296 mail = ActionMailer::Base.deliveries.last
297 297 assert_kind_of TMail::Mail, mail
298 298 assert mail.subject.starts_with?("[#{issue.project.name} - #{issue.tracker.name} ##{issue.id}]")
299 299 assert mail.body.include?("Subject changed from #{old_subject} to #{new_subject}")
300 300 end
301 301
302 302 def test_post_edit_with_status_and_assignee_change
303 303 issue = Issue.find(1)
304 304 assert_equal 1, issue.status_id
305 305 @request.session[:user_id] = 2
306 306 assert_difference('TimeEntry.count', 0) do
307 307 post :edit,
308 308 :id => 1,
309 309 :issue => { :status_id => 2, :assigned_to_id => 3 },
310 310 :notes => 'Assigned to dlopper',
311 311 :time_entry => { :hours => '', :comments => '', :activity_id => Enumeration.get_values('ACTI').first }
312 312 end
313 313 assert_redirected_to 'issues/show/1'
314 314 issue.reload
315 315 assert_equal 2, issue.status_id
316 316 j = issue.journals.find(:first, :order => 'id DESC')
317 317 assert_equal 'Assigned to dlopper', j.notes
318 318 assert_equal 2, j.details.size
319 319
320 320 mail = ActionMailer::Base.deliveries.last
321 321 assert mail.body.include?("Status changed from New to Assigned")
322 322 end
323 323
324 324 def test_post_edit_with_note_only
325 325 notes = 'Note added by IssuesControllerTest#test_update_with_note_only'
326 326 # anonymous user
327 327 post :edit,
328 328 :id => 1,
329 329 :notes => notes
330 330 assert_redirected_to 'issues/show/1'
331 331 j = Issue.find(1).journals.find(:first, :order => 'id DESC')
332 332 assert_equal notes, j.notes
333 333 assert_equal 0, j.details.size
334 334 assert_equal User.anonymous, j.user
335 335
336 336 mail = ActionMailer::Base.deliveries.last
337 337 assert mail.body.include?(notes)
338 338 end
339 339
340 340 def test_post_edit_with_note_and_spent_time
341 341 @request.session[:user_id] = 2
342 342 spent_hours_before = Issue.find(1).spent_hours
343 343 assert_difference('TimeEntry.count') do
344 344 post :edit,
345 345 :id => 1,
346 346 :notes => '2.5 hours added',
347 347 :time_entry => { :hours => '2.5', :comments => '', :activity_id => Enumeration.get_values('ACTI').first }
348 348 end
349 349 assert_redirected_to 'issues/show/1'
350 350
351 351 issue = Issue.find(1)
352 352
353 353 j = issue.journals.find(:first, :order => 'id DESC')
354 354 assert_equal '2.5 hours added', j.notes
355 355 assert_equal 0, j.details.size
356 356
357 357 t = issue.time_entries.find(:first, :order => 'id DESC')
358 358 assert_not_nil t
359 359 assert_equal 2.5, t.hours
360 360 assert_equal spent_hours_before + 2.5, issue.spent_hours
361 361 end
362 362
363 363 def test_post_edit_with_attachment_only
364 364 # anonymous user
365 365 post :edit,
366 366 :id => 1,
367 367 :notes => '',
368 368 :attachments => {'1' => {'file' => test_uploaded_file('testfile.txt', 'text/plain')}}
369 369 assert_redirected_to 'issues/show/1'
370 370 j = Issue.find(1).journals.find(:first, :order => 'id DESC')
371 371 assert j.notes.blank?
372 372 assert_equal 1, j.details.size
373 373 assert_equal 'testfile.txt', j.details.first.value
374 374 assert_equal User.anonymous, j.user
375 375
376 376 mail = ActionMailer::Base.deliveries.last
377 377 assert mail.body.include?('testfile.txt')
378 378 end
379 379
380 380 def test_post_edit_with_no_change
381 381 issue = Issue.find(1)
382 382 issue.journals.clear
383 383 ActionMailer::Base.deliveries.clear
384 384
385 385 post :edit,
386 386 :id => 1,
387 387 :notes => ''
388 388 assert_redirected_to 'issues/show/1'
389 389
390 390 issue.reload
391 391 assert issue.journals.empty?
392 392 # No email should be sent
393 393 assert ActionMailer::Base.deliveries.empty?
394 394 end
395 395
396 396 def test_bulk_edit
397 397 @request.session[:user_id] = 2
398 398 # update issues priority
399 399 post :bulk_edit, :ids => [1, 2], :priority_id => 7, :notes => 'Bulk editing', :assigned_to_id => ''
400 400 assert_response 302
401 401 # check that the issues were updated
402 402 assert_equal [7, 7], Issue.find_all_by_id([1, 2]).collect {|i| i.priority.id}
403 403 assert_equal 'Bulk editing', Issue.find(1).journals.find(:first, :order => 'created_on DESC').notes
404 404 end
405 405
406 406 def test_bulk_unassign
407 407 assert_not_nil Issue.find(2).assigned_to
408 408 @request.session[:user_id] = 2
409 409 # unassign issues
410 410 post :bulk_edit, :ids => [1, 2], :notes => 'Bulk unassigning', :assigned_to_id => 'none'
411 411 assert_response 302
412 412 # check that the issues were updated
413 413 assert_nil Issue.find(2).assigned_to
414 414 end
415 415
416 416 def test_move_one_issue_to_another_project
417 417 @request.session[:user_id] = 1
418 418 post :move, :id => 1, :new_project_id => 2
419 419 assert_redirected_to 'projects/ecookbook/issues'
420 420 assert_equal 2, Issue.find(1).project_id
421 421 end
422 422
423 423 def test_bulk_move_to_another_project
424 424 @request.session[:user_id] = 1
425 425 post :move, :ids => [1, 2], :new_project_id => 2
426 426 assert_redirected_to 'projects/ecookbook/issues'
427 427 # Issues moved to project 2
428 428 assert_equal 2, Issue.find(1).project_id
429 429 assert_equal 2, Issue.find(2).project_id
430 430 # No tracker change
431 431 assert_equal 1, Issue.find(1).tracker_id
432 432 assert_equal 2, Issue.find(2).tracker_id
433 433 end
434 434
435 435 def test_bulk_move_to_another_tracker
436 436 @request.session[:user_id] = 1
437 437 post :move, :ids => [1, 2], :new_tracker_id => 2
438 438 assert_redirected_to 'projects/ecookbook/issues'
439 439 assert_equal 2, Issue.find(1).tracker_id
440 440 assert_equal 2, Issue.find(2).tracker_id
441 441 end
442 442
443 443 def test_context_menu_one_issue
444 444 @request.session[:user_id] = 2
445 445 get :context_menu, :ids => [1]
446 446 assert_response :success
447 447 assert_template 'context_menu'
448 448 assert_tag :tag => 'a', :content => 'Edit',
449 449 :attributes => { :href => '/issues/edit/1',
450 450 :class => 'icon-edit' }
451 451 assert_tag :tag => 'a', :content => 'Closed',
452 452 :attributes => { :href => '/issues/edit/1?issue%5Bstatus_id%5D=5',
453 453 :class => '' }
454 454 assert_tag :tag => 'a', :content => 'Immediate',
455 455 :attributes => { :href => '/issues/edit/1?issue%5Bpriority_id%5D=8',
456 456 :class => '' }
457 457 assert_tag :tag => 'a', :content => 'Dave Lopper',
458 458 :attributes => { :href => '/issues/edit/1?issue%5Bassigned_to_id%5D=3',
459 459 :class => '' }
460 460 assert_tag :tag => 'a', :content => 'Copy',
461 461 :attributes => { :href => '/projects/ecookbook/issues/new?copy_from=1',
462 462 :class => 'icon-copy' }
463 463 assert_tag :tag => 'a', :content => 'Move',
464 464 :attributes => { :href => '/issues/move?ids%5B%5D=1',
465 465 :class => 'icon-move' }
466 466 assert_tag :tag => 'a', :content => 'Delete',
467 467 :attributes => { :href => '/issues/destroy?ids%5B%5D=1',
468 468 :class => 'icon-del' }
469 469 end
470 470
471 471 def test_context_menu_one_issue_by_anonymous
472 472 get :context_menu, :ids => [1]
473 473 assert_response :success
474 474 assert_template 'context_menu'
475 475 assert_tag :tag => 'a', :content => 'Delete',
476 476 :attributes => { :href => '#',
477 477 :class => 'icon-del disabled' }
478 478 end
479 479
480 480 def test_context_menu_multiple_issues_of_same_project
481 481 @request.session[:user_id] = 2
482 482 get :context_menu, :ids => [1, 2]
483 483 assert_response :success
484 484 assert_template 'context_menu'
485 485 assert_tag :tag => 'a', :content => 'Edit',
486 486 :attributes => { :href => '/issues/bulk_edit?ids%5B%5D=1&amp;ids%5B%5D=2',
487 487 :class => 'icon-edit' }
488 488 assert_tag :tag => 'a', :content => 'Move',
489 489 :attributes => { :href => '/issues/move?ids%5B%5D=1&amp;ids%5B%5D=2',
490 490 :class => 'icon-move' }
491 491 assert_tag :tag => 'a', :content => 'Delete',
492 492 :attributes => { :href => '/issues/destroy?ids%5B%5D=1&amp;ids%5B%5D=2',
493 493 :class => 'icon-del' }
494 494 end
495 495
496 496 def test_context_menu_multiple_issues_of_different_project
497 497 @request.session[:user_id] = 2
498 498 get :context_menu, :ids => [1, 2, 4]
499 499 assert_response :success
500 500 assert_template 'context_menu'
501 501 assert_tag :tag => 'a', :content => 'Delete',
502 502 :attributes => { :href => '#',
503 503 :class => 'icon-del disabled' }
504 504 end
505 505
506 506 def test_destroy_issue_with_no_time_entries
507 507 assert_nil TimeEntry.find_by_issue_id(2)
508 508 @request.session[:user_id] = 2
509 509 post :destroy, :id => 2
510 510 assert_redirected_to 'projects/ecookbook/issues'
511 511 assert_nil Issue.find_by_id(2)
512 512 end
513 513
514 514 def test_destroy_issues_with_time_entries
515 515 @request.session[:user_id] = 2
516 516 post :destroy, :ids => [1, 3]
517 517 assert_response :success
518 518 assert_template 'destroy'
519 519 assert_not_nil assigns(:hours)
520 520 assert Issue.find_by_id(1) && Issue.find_by_id(3)
521 521 end
522 522
523 523 def test_destroy_issues_and_destroy_time_entries
524 524 @request.session[:user_id] = 2
525 525 post :destroy, :ids => [1, 3], :todo => 'destroy'
526 526 assert_redirected_to 'projects/ecookbook/issues'
527 527 assert !(Issue.find_by_id(1) || Issue.find_by_id(3))
528 528 assert_nil TimeEntry.find_by_id([1, 2])
529 529 end
530 530
531 531 def test_destroy_issues_and_assign_time_entries_to_project
532 532 @request.session[:user_id] = 2
533 533 post :destroy, :ids => [1, 3], :todo => 'nullify'
534 534 assert_redirected_to 'projects/ecookbook/issues'
535 535 assert !(Issue.find_by_id(1) || Issue.find_by_id(3))
536 536 assert_nil TimeEntry.find(1).issue_id
537 537 assert_nil TimeEntry.find(2).issue_id
538 538 end
539 539
540 540 def test_destroy_issues_and_reassign_time_entries_to_another_issue
541 541 @request.session[:user_id] = 2
542 542 post :destroy, :ids => [1, 3], :todo => 'reassign', :reassign_to_id => 2
543 543 assert_redirected_to 'projects/ecookbook/issues'
544 544 assert !(Issue.find_by_id(1) || Issue.find_by_id(3))
545 545 assert_equal 2, TimeEntry.find(1).issue_id
546 546 assert_equal 2, TimeEntry.find(2).issue_id
547 547 end
548 548
549 549 def test_destroy_attachment
550 550 issue = Issue.find(3)
551 551 a = issue.attachments.size
552 552 @request.session[:user_id] = 2
553 553 post :destroy_attachment, :id => 3, :attachment_id => 1
554 554 assert_redirected_to 'issues/show/3'
555 555 assert_nil Attachment.find_by_id(1)
556 556 issue.reload
557 557 assert_equal((a-1), issue.attachments.size)
558 558 j = issue.journals.find(:first, :order => 'created_on DESC')
559 559 assert_equal 'attachment', j.details.first.property
560 560 end
561 561 end
General Comments 0
You need to be logged in to leave comments. Login now