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