##// END OF EJS Templates
Fix tests broken by r1243 (Redirect to issue page after creating a new issue)....
Jean-Philippe Lang -
r1242:83061e9ca29a
parent child
Show More
@@ -1,486 +1,486
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 41 :time_entries
42 42
43 43 def setup
44 44 @controller = IssuesController.new
45 45 @request = ActionController::TestRequest.new
46 46 @response = ActionController::TestResponse.new
47 47 User.current = nil
48 48 end
49 49
50 50 def test_index
51 51 get :index
52 52 assert_response :success
53 53 assert_template 'index.rhtml'
54 54 assert_not_nil assigns(:issues)
55 55 assert_nil assigns(:project)
56 56 end
57 57
58 58 def test_index_with_project
59 59 get :index, :project_id => 1
60 60 assert_response :success
61 61 assert_template 'index.rhtml'
62 62 assert_not_nil assigns(:issues)
63 63 end
64 64
65 65 def test_index_with_project_and_filter
66 66 get :index, :project_id => 1, :set_filter => 1
67 67 assert_response :success
68 68 assert_template 'index.rhtml'
69 69 assert_not_nil assigns(:issues)
70 70 end
71 71
72 72 def test_index_csv_with_project
73 73 get :index, :format => 'csv'
74 74 assert_response :success
75 75 assert_not_nil assigns(:issues)
76 76 assert_equal 'text/csv', @response.content_type
77 77
78 78 get :index, :project_id => 1, :format => 'csv'
79 79 assert_response :success
80 80 assert_not_nil assigns(:issues)
81 81 assert_equal 'text/csv', @response.content_type
82 82 end
83 83
84 84 def test_index_pdf
85 85 get :index, :format => 'pdf'
86 86 assert_response :success
87 87 assert_not_nil assigns(:issues)
88 88 assert_equal 'application/pdf', @response.content_type
89 89
90 90 get :index, :project_id => 1, :format => 'pdf'
91 91 assert_response :success
92 92 assert_not_nil assigns(:issues)
93 93 assert_equal 'application/pdf', @response.content_type
94 94 end
95 95
96 96 def test_changes
97 97 get :changes, :project_id => 1
98 98 assert_response :success
99 99 assert_not_nil assigns(:journals)
100 100 assert_equal 'application/atom+xml', @response.content_type
101 101 end
102 102
103 103 def test_show_by_anonymous
104 104 get :show, :id => 1
105 105 assert_response :success
106 106 assert_template 'show.rhtml'
107 107 assert_not_nil assigns(:issue)
108 108 assert_equal Issue.find(1), assigns(:issue)
109 109
110 110 # anonymous role is allowed to add a note
111 111 assert_tag :tag => 'form',
112 112 :descendant => { :tag => 'fieldset',
113 113 :child => { :tag => 'legend',
114 114 :content => /Notes/ } }
115 115 end
116 116
117 117 def test_show_by_manager
118 118 @request.session[:user_id] = 2
119 119 get :show, :id => 1
120 120 assert_response :success
121 121
122 122 assert_tag :tag => 'form',
123 123 :descendant => { :tag => 'fieldset',
124 124 :child => { :tag => 'legend',
125 125 :content => /Change properties/ } },
126 126 :descendant => { :tag => 'fieldset',
127 127 :child => { :tag => 'legend',
128 128 :content => /Log time/ } },
129 129 :descendant => { :tag => 'fieldset',
130 130 :child => { :tag => 'legend',
131 131 :content => /Notes/ } }
132 132 end
133 133
134 134 def test_get_new
135 135 @request.session[:user_id] = 2
136 136 get :new, :project_id => 1, :tracker_id => 1
137 137 assert_response :success
138 138 assert_template 'new'
139 139
140 140 assert_tag :tag => 'input', :attributes => { :name => 'custom_fields[2]',
141 141 :value => 'Default string' }
142 142 end
143 143
144 144 def test_get_new_without_tracker_id
145 145 @request.session[:user_id] = 2
146 146 get :new, :project_id => 1
147 147 assert_response :success
148 148 assert_template 'new'
149 149
150 150 issue = assigns(:issue)
151 151 assert_not_nil issue
152 152 assert_equal Project.find(1).trackers.first, issue.tracker
153 153 end
154 154
155 155 def test_update_new_form
156 156 @request.session[:user_id] = 2
157 157 xhr :post, :new, :project_id => 1,
158 158 :issue => {:tracker_id => 2,
159 159 :subject => 'This is the test_new issue',
160 160 :description => 'This is the description',
161 161 :priority_id => 5}
162 162 assert_response :success
163 163 assert_template 'new'
164 164 end
165 165
166 166 def test_post_new
167 167 @request.session[:user_id] = 2
168 168 post :new, :project_id => 1,
169 169 :issue => {:tracker_id => 1,
170 170 :subject => 'This is the test_new issue',
171 171 :description => 'This is the description',
172 172 :priority_id => 5},
173 173 :custom_fields => {'2' => 'Value for field 2'}
174 assert_redirected_to 'projects/ecookbook/issues'
174 assert_redirected_to 'issues/show'
175 175
176 176 issue = Issue.find_by_subject('This is the test_new issue')
177 177 assert_not_nil issue
178 178 assert_equal 2, issue.author_id
179 179 v = issue.custom_values.find_by_custom_field_id(2)
180 180 assert_not_nil v
181 181 assert_equal 'Value for field 2', v.value
182 182 end
183 183
184 184 def test_copy_issue
185 185 @request.session[:user_id] = 2
186 186 get :new, :project_id => 1, :copy_from => 1
187 187 assert_template 'new'
188 188 assert_not_nil assigns(:issue)
189 189 orig = Issue.find(1)
190 190 assert_equal orig.subject, assigns(:issue).subject
191 191 end
192 192
193 193 def test_get_edit
194 194 @request.session[:user_id] = 2
195 195 get :edit, :id => 1
196 196 assert_response :success
197 197 assert_template 'edit'
198 198 assert_not_nil assigns(:issue)
199 199 assert_equal Issue.find(1), assigns(:issue)
200 200 end
201 201
202 202 def test_get_edit_with_params
203 203 @request.session[:user_id] = 2
204 204 get :edit, :id => 1, :issue => { :status_id => 5, :priority_id => 7 }
205 205 assert_response :success
206 206 assert_template 'edit'
207 207
208 208 issue = assigns(:issue)
209 209 assert_not_nil issue
210 210
211 211 assert_equal 5, issue.status_id
212 212 assert_tag :select, :attributes => { :name => 'issue[status_id]' },
213 213 :child => { :tag => 'option',
214 214 :content => 'Closed',
215 215 :attributes => { :selected => 'selected' } }
216 216
217 217 assert_equal 7, issue.priority_id
218 218 assert_tag :select, :attributes => { :name => 'issue[priority_id]' },
219 219 :child => { :tag => 'option',
220 220 :content => 'Urgent',
221 221 :attributes => { :selected => 'selected' } }
222 222 end
223 223
224 224 def test_post_edit
225 225 @request.session[:user_id] = 2
226 226 ActionMailer::Base.deliveries.clear
227 227
228 228 issue = Issue.find(1)
229 229 old_subject = issue.subject
230 230 new_subject = 'Subject modified by IssuesControllerTest#test_post_edit'
231 231
232 232 post :edit, :id => 1, :issue => {:subject => new_subject}
233 233 assert_redirected_to 'issues/show/1'
234 234 issue.reload
235 235 assert_equal new_subject, issue.subject
236 236
237 237 mail = ActionMailer::Base.deliveries.last
238 238 assert_kind_of TMail::Mail, mail
239 239 assert mail.subject.starts_with?("[#{issue.project.name} - #{issue.tracker.name} ##{issue.id}]")
240 240 assert mail.body.include?("Subject changed from #{old_subject} to #{new_subject}")
241 241 end
242 242
243 243 def test_post_edit_with_status_and_assignee_change
244 244 issue = Issue.find(1)
245 245 assert_equal 1, issue.status_id
246 246 @request.session[:user_id] = 2
247 247 post :edit,
248 248 :id => 1,
249 249 :issue => { :status_id => 2, :assigned_to_id => 3 },
250 250 :notes => 'Assigned to dlopper'
251 251 assert_redirected_to 'issues/show/1'
252 252 issue.reload
253 253 assert_equal 2, issue.status_id
254 254 j = issue.journals.find(:first, :order => 'id DESC')
255 255 assert_equal 'Assigned to dlopper', j.notes
256 256 assert_equal 2, j.details.size
257 257
258 258 mail = ActionMailer::Base.deliveries.last
259 259 assert mail.body.include?("Status changed from New to Assigned")
260 260 end
261 261
262 262 def test_post_edit_with_note_only
263 263 notes = 'Note added by IssuesControllerTest#test_update_with_note_only'
264 264 # anonymous user
265 265 post :edit,
266 266 :id => 1,
267 267 :notes => notes
268 268 assert_redirected_to 'issues/show/1'
269 269 j = Issue.find(1).journals.find(:first, :order => 'id DESC')
270 270 assert_equal notes, j.notes
271 271 assert_equal 0, j.details.size
272 272 assert_equal User.anonymous, j.user
273 273
274 274 mail = ActionMailer::Base.deliveries.last
275 275 assert mail.body.include?(notes)
276 276 end
277 277
278 278 def test_post_edit_with_note_and_spent_time
279 279 @request.session[:user_id] = 2
280 280 spent_hours_before = Issue.find(1).spent_hours
281 281 post :edit,
282 282 :id => 1,
283 283 :notes => '2.5 hours added',
284 284 :time_entry => { :hours => '2.5', :comments => '', :activity_id => Enumeration.get_values('ACTI').first }
285 285 assert_redirected_to 'issues/show/1'
286 286
287 287 issue = Issue.find(1)
288 288
289 289 j = issue.journals.find(:first, :order => 'id DESC')
290 290 assert_equal '2.5 hours added', j.notes
291 291 assert_equal 0, j.details.size
292 292
293 293 t = issue.time_entries.find(:first, :order => 'id DESC')
294 294 assert_not_nil t
295 295 assert_equal 2.5, t.hours
296 296 assert_equal spent_hours_before + 2.5, issue.spent_hours
297 297 end
298 298
299 299 def test_post_edit_with_attachment_only
300 300 # anonymous user
301 301 post :edit,
302 302 :id => 1,
303 303 :notes => '',
304 304 :attachments => {'1' => {'file' => test_uploaded_file('testfile.txt', 'text/plain')}}
305 305 assert_redirected_to 'issues/show/1'
306 306 j = Issue.find(1).journals.find(:first, :order => 'id DESC')
307 307 assert j.notes.blank?
308 308 assert_equal 1, j.details.size
309 309 assert_equal 'testfile.txt', j.details.first.value
310 310 assert_equal User.anonymous, j.user
311 311
312 312 mail = ActionMailer::Base.deliveries.last
313 313 assert mail.body.include?('testfile.txt')
314 314 end
315 315
316 316 def test_post_edit_with_no_change
317 317 issue = Issue.find(1)
318 318 issue.journals.clear
319 319 ActionMailer::Base.deliveries.clear
320 320
321 321 post :edit,
322 322 :id => 1,
323 323 :notes => ''
324 324 assert_redirected_to 'issues/show/1'
325 325
326 326 issue.reload
327 327 assert issue.journals.empty?
328 328 # No email should be sent
329 329 assert ActionMailer::Base.deliveries.empty?
330 330 end
331 331
332 332 def test_bulk_edit
333 333 @request.session[:user_id] = 2
334 334 # update issues priority
335 335 post :bulk_edit, :ids => [1, 2], :priority_id => 7, :notes => 'Bulk editing', :assigned_to_id => ''
336 336 assert_response 302
337 337 # check that the issues were updated
338 338 assert_equal [7, 7], Issue.find_all_by_id([1, 2]).collect {|i| i.priority.id}
339 339 assert_equal 'Bulk editing', Issue.find(1).journals.find(:first, :order => 'created_on DESC').notes
340 340 end
341 341
342 342 def test_move_one_issue_to_another_project
343 343 @request.session[:user_id] = 1
344 344 post :move, :id => 1, :new_project_id => 2
345 345 assert_redirected_to 'projects/ecookbook/issues'
346 346 assert_equal 2, Issue.find(1).project_id
347 347 end
348 348
349 349 def test_bulk_move_to_another_project
350 350 @request.session[:user_id] = 1
351 351 post :move, :ids => [1, 2], :new_project_id => 2
352 352 assert_redirected_to 'projects/ecookbook/issues'
353 353 # Issues moved to project 2
354 354 assert_equal 2, Issue.find(1).project_id
355 355 assert_equal 2, Issue.find(2).project_id
356 356 # No tracker change
357 357 assert_equal 1, Issue.find(1).tracker_id
358 358 assert_equal 2, Issue.find(2).tracker_id
359 359 end
360 360
361 361 def test_bulk_move_to_another_tracker
362 362 @request.session[:user_id] = 1
363 363 post :move, :ids => [1, 2], :new_tracker_id => 2
364 364 assert_redirected_to 'projects/ecookbook/issues'
365 365 assert_equal 2, Issue.find(1).tracker_id
366 366 assert_equal 2, Issue.find(2).tracker_id
367 367 end
368 368
369 369 def test_context_menu_one_issue
370 370 @request.session[:user_id] = 2
371 371 get :context_menu, :ids => [1]
372 372 assert_response :success
373 373 assert_template 'context_menu'
374 374 assert_tag :tag => 'a', :content => 'Edit',
375 375 :attributes => { :href => '/issues/edit/1',
376 376 :class => 'icon-edit' }
377 377 assert_tag :tag => 'a', :content => 'Closed',
378 378 :attributes => { :href => '/issues/edit/1?issue%5Bstatus_id%5D=5',
379 379 :class => '' }
380 380 assert_tag :tag => 'a', :content => 'Immediate',
381 381 :attributes => { :href => '/issues/edit/1?issue%5Bpriority_id%5D=8',
382 382 :class => '' }
383 383 assert_tag :tag => 'a', :content => 'Dave Lopper',
384 384 :attributes => { :href => '/issues/edit/1?issue%5Bassigned_to_id%5D=3',
385 385 :class => '' }
386 386 assert_tag :tag => 'a', :content => 'Copy',
387 387 :attributes => { :href => '/projects/ecookbook/issues/new?copy_from=1',
388 388 :class => 'icon-copy' }
389 389 assert_tag :tag => 'a', :content => 'Move',
390 390 :attributes => { :href => '/issues/move?ids%5B%5D=1',
391 391 :class => 'icon-move' }
392 392 assert_tag :tag => 'a', :content => 'Delete',
393 393 :attributes => { :href => '/issues/destroy?ids%5B%5D=1',
394 394 :class => 'icon-del' }
395 395 end
396 396
397 397 def test_context_menu_one_issue_by_anonymous
398 398 get :context_menu, :ids => [1]
399 399 assert_response :success
400 400 assert_template 'context_menu'
401 401 assert_tag :tag => 'a', :content => 'Delete',
402 402 :attributes => { :href => '#',
403 403 :class => 'icon-del disabled' }
404 404 end
405 405
406 406 def test_context_menu_multiple_issues_of_same_project
407 407 @request.session[:user_id] = 2
408 408 get :context_menu, :ids => [1, 2]
409 409 assert_response :success
410 410 assert_template 'context_menu'
411 411 assert_tag :tag => 'a', :content => 'Edit',
412 412 :attributes => { :href => '/issues/bulk_edit?ids%5B%5D=1&amp;ids%5B%5D=2',
413 413 :class => 'icon-edit' }
414 414 assert_tag :tag => 'a', :content => 'Move',
415 415 :attributes => { :href => '/issues/move?ids%5B%5D=1&amp;ids%5B%5D=2',
416 416 :class => 'icon-move' }
417 417 assert_tag :tag => 'a', :content => 'Delete',
418 418 :attributes => { :href => '/issues/destroy?ids%5B%5D=1&amp;ids%5B%5D=2',
419 419 :class => 'icon-del' }
420 420 end
421 421
422 422 def test_context_menu_multiple_issues_of_different_project
423 423 @request.session[:user_id] = 2
424 424 get :context_menu, :ids => [1, 2, 4]
425 425 assert_response :success
426 426 assert_template 'context_menu'
427 427 assert_tag :tag => 'a', :content => 'Delete',
428 428 :attributes => { :href => '#',
429 429 :class => 'icon-del disabled' }
430 430 end
431 431
432 432 def test_destroy_issue_with_no_time_entries
433 433 @request.session[:user_id] = 2
434 434 post :destroy, :id => 3
435 435 assert_redirected_to 'projects/ecookbook/issues'
436 436 assert_nil Issue.find_by_id(3)
437 437 end
438 438
439 439 def test_destroy_issues_with_time_entries
440 440 @request.session[:user_id] = 2
441 441 post :destroy, :ids => [1, 3]
442 442 assert_response :success
443 443 assert_template 'destroy'
444 444 assert_not_nil assigns(:hours)
445 445 assert Issue.find_by_id(1) && Issue.find_by_id(3)
446 446 end
447 447
448 448 def test_destroy_issues_and_destroy_time_entries
449 449 @request.session[:user_id] = 2
450 450 post :destroy, :ids => [1, 3], :todo => 'destroy'
451 451 assert_redirected_to 'projects/ecookbook/issues'
452 452 assert !(Issue.find_by_id(1) || Issue.find_by_id(3))
453 453 assert_nil TimeEntry.find_by_id([1, 2])
454 454 end
455 455
456 456 def test_destroy_issues_and_assign_time_entries_to_project
457 457 @request.session[:user_id] = 2
458 458 post :destroy, :ids => [1, 3], :todo => 'nullify'
459 459 assert_redirected_to 'projects/ecookbook/issues'
460 460 assert !(Issue.find_by_id(1) || Issue.find_by_id(3))
461 461 assert_nil TimeEntry.find(1).issue_id
462 462 assert_nil TimeEntry.find(2).issue_id
463 463 end
464 464
465 465 def test_destroy_issues_and_reassign_time_entries_to_another_issue
466 466 @request.session[:user_id] = 2
467 467 post :destroy, :ids => [1, 3], :todo => 'reassign', :reassign_to_id => 2
468 468 assert_redirected_to 'projects/ecookbook/issues'
469 469 assert !(Issue.find_by_id(1) || Issue.find_by_id(3))
470 470 assert_equal 2, TimeEntry.find(1).issue_id
471 471 assert_equal 2, TimeEntry.find(2).issue_id
472 472 end
473 473
474 474 def test_destroy_attachment
475 475 issue = Issue.find(3)
476 476 a = issue.attachments.size
477 477 @request.session[:user_id] = 2
478 478 post :destroy_attachment, :id => 3, :attachment_id => 1
479 479 assert_redirected_to 'issues/show/3'
480 480 assert_nil Attachment.find_by_id(1)
481 481 issue.reload
482 482 assert_equal((a-1), issue.attachments.size)
483 483 j = issue.journals.find(:first, :order => 'created_on DESC')
484 484 assert_equal 'attachment', j.details.first.property
485 485 end
486 486 end
@@ -1,71 +1,71
1 1 require "#{File.dirname(__FILE__)}/../test_helper"
2 2
3 3 class IssuesTest < ActionController::IntegrationTest
4 4 fixtures :projects,
5 5 :users,
6 6 :trackers,
7 7 :projects_trackers,
8 8 :issue_statuses,
9 9 :issues,
10 10 :enumerations,
11 11 :custom_fields,
12 12 :custom_values,
13 13 :custom_fields_trackers
14 14
15 15 # create an issue
16 16 def test_add_issue
17 17 log_user('jsmith', 'jsmith')
18 18 get 'projects/1/issues/new', :tracker_id => '1'
19 19 assert_response :success
20 20 assert_template 'issues/new'
21 21
22 22 post 'projects/1/issues/new', :tracker_id => "1",
23 23 :issue => { :start_date => "2006-12-26",
24 24 :priority_id => "3",
25 25 :subject => "new test issue",
26 26 :category_id => "",
27 27 :description => "new issue",
28 28 :done_ratio => "0",
29 29 :due_date => "",
30 30 :assigned_to_id => "" },
31 31 :custom_fields => {'2' => 'Value for field 2'}
32 32 # find created issue
33 33 issue = Issue.find_by_subject("new test issue")
34 34 assert_kind_of Issue, issue
35 35
36 36 # check redirection
37 assert_redirected_to "projects/ecookbook/issues"
37 assert_redirected_to "issues/show"
38 38 follow_redirect!
39 assert assigns(:issues).include?(issue)
39 assert_equal issue, assigns(:issue)
40 40
41 41 # check issue attributes
42 42 assert_equal 'jsmith', issue.author.login
43 43 assert_equal 1, issue.project.id
44 44 assert_equal 1, issue.status.id
45 45 end
46 46
47 47 # add then remove 2 attachments to an issue
48 48 def test_issue_attachements
49 49 log_user('jsmith', 'jsmith')
50 50
51 51 post 'issues/edit/1',
52 52 :notes => 'Some notes',
53 53 :attachments => {'1' => {'file' => test_uploaded_file('testfile.txt', 'text/plain'), 'description' => 'This is an attachment'}}
54 54 assert_redirected_to "issues/show/1"
55 55
56 56 # make sure attachment was saved
57 57 attachment = Issue.find(1).attachments.find_by_filename("testfile.txt")
58 58 assert_kind_of Attachment, attachment
59 59 assert_equal Issue.find(1), attachment.container
60 60 assert_equal 'This is an attachment', attachment.description
61 61 # verify the size of the attachment stored in db
62 62 #assert_equal file_data_1.length, attachment.filesize
63 63 # verify that the attachment was written to disk
64 64 assert File.exist?(attachment.diskfile)
65 65
66 66 # remove the attachments
67 67 Issue.find(1).attachments.each(&:destroy)
68 68 assert_equal 0, Issue.find(1).attachments.length
69 69 end
70 70
71 71 end
General Comments 0
You need to be logged in to leave comments. Login now