##// END OF EJS Templates
Removed a duplicate test....
Jean-Philippe Lang -
r5209:c9a3700cfc28
parent child
Show More
@@ -1,1344 +1,1333
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.expand_path('../../test_helper', __FILE__)
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_projects,
43 43 :custom_fields_trackers,
44 44 :time_entries,
45 45 :journals,
46 46 :journal_details,
47 47 :queries
48 48
49 49 def setup
50 50 @controller = IssuesController.new
51 51 @request = ActionController::TestRequest.new
52 52 @response = ActionController::TestResponse.new
53 53 User.current = nil
54 54 end
55 55
56 56 def test_index
57 57 Setting.default_language = 'en'
58 58
59 59 get :index
60 60 assert_response :success
61 61 assert_template 'index.rhtml'
62 62 assert_not_nil assigns(:issues)
63 63 assert_nil assigns(:project)
64 64 assert_tag :tag => 'a', :content => /Can't print recipes/
65 65 assert_tag :tag => 'a', :content => /Subproject issue/
66 66 # private projects hidden
67 67 assert_no_tag :tag => 'a', :content => /Issue of a private subproject/
68 68 assert_no_tag :tag => 'a', :content => /Issue on project 2/
69 69 # project column
70 70 assert_tag :tag => 'th', :content => /Project/
71 71 end
72 72
73 73 def test_index_should_not_list_issues_when_module_disabled
74 74 EnabledModule.delete_all("name = 'issue_tracking' AND project_id = 1")
75 75 get :index
76 76 assert_response :success
77 77 assert_template 'index.rhtml'
78 78 assert_not_nil assigns(:issues)
79 79 assert_nil assigns(:project)
80 80 assert_no_tag :tag => 'a', :content => /Can't print recipes/
81 81 assert_tag :tag => 'a', :content => /Subproject issue/
82 82 end
83 83
84 84 def test_index_should_not_list_issues_when_module_disabled
85 85 EnabledModule.delete_all("name = 'issue_tracking' AND project_id = 1")
86 86 get :index
87 87 assert_response :success
88 88 assert_template 'index.rhtml'
89 89 assert_not_nil assigns(:issues)
90 90 assert_nil assigns(:project)
91 91 assert_no_tag :tag => 'a', :content => /Can't print recipes/
92 92 assert_tag :tag => 'a', :content => /Subproject issue/
93 93 end
94 94
95 95 def test_index_with_project
96 96 Setting.display_subprojects_issues = 0
97 97 get :index, :project_id => 1
98 98 assert_response :success
99 99 assert_template 'index.rhtml'
100 100 assert_not_nil assigns(:issues)
101 101 assert_tag :tag => 'a', :content => /Can't print recipes/
102 102 assert_no_tag :tag => 'a', :content => /Subproject issue/
103 103 end
104 104
105 105 def test_index_with_project_and_subprojects
106 106 Setting.display_subprojects_issues = 1
107 107 get :index, :project_id => 1
108 108 assert_response :success
109 109 assert_template 'index.rhtml'
110 110 assert_not_nil assigns(:issues)
111 111 assert_tag :tag => 'a', :content => /Can't print recipes/
112 112 assert_tag :tag => 'a', :content => /Subproject issue/
113 113 assert_no_tag :tag => 'a', :content => /Issue of a private subproject/
114 114 end
115 115
116 116 def test_index_with_project_and_subprojects_should_show_private_subprojects
117 117 @request.session[:user_id] = 2
118 118 Setting.display_subprojects_issues = 1
119 119 get :index, :project_id => 1
120 120 assert_response :success
121 121 assert_template 'index.rhtml'
122 122 assert_not_nil assigns(:issues)
123 123 assert_tag :tag => 'a', :content => /Can't print recipes/
124 124 assert_tag :tag => 'a', :content => /Subproject issue/
125 125 assert_tag :tag => 'a', :content => /Issue of a private subproject/
126 126 end
127 127
128 128 def test_index_with_project_and_default_filter
129 129 get :index, :project_id => 1, :set_filter => 1
130 130 assert_response :success
131 131 assert_template 'index.rhtml'
132 132 assert_not_nil assigns(:issues)
133 133
134 134 query = assigns(:query)
135 135 assert_not_nil query
136 136 # default filter
137 137 assert_equal({'status_id' => {:operator => 'o', :values => ['']}}, query.filters)
138 138 end
139 139
140 140 def test_index_with_project_and_filter
141 141 get :index, :project_id => 1, :set_filter => 1,
142 142 :f => ['tracker_id'],
143 143 :op => {'tracker_id' => '='},
144 144 :v => {'tracker_id' => ['1']}
145 145 assert_response :success
146 146 assert_template 'index.rhtml'
147 147 assert_not_nil assigns(:issues)
148 148
149 149 query = assigns(:query)
150 150 assert_not_nil query
151 151 assert_equal({'tracker_id' => {:operator => '=', :values => ['1']}}, query.filters)
152 152 end
153 153
154 154 def test_index_with_project_and_empty_filters
155 155 get :index, :project_id => 1, :set_filter => 1, :fields => ['']
156 156 assert_response :success
157 157 assert_template 'index.rhtml'
158 158 assert_not_nil assigns(:issues)
159 159
160 160 query = assigns(:query)
161 161 assert_not_nil query
162 162 # no filter
163 163 assert_equal({}, query.filters)
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 assert_not_nil assigns(:issue_count_by_group)
180 180 end
181 181
182 182 def test_index_with_query_grouped_by_list_custom_field
183 183 get :index, :project_id => 1, :query_id => 9
184 184 assert_response :success
185 185 assert_template 'index.rhtml'
186 186 assert_not_nil assigns(:issues)
187 187 assert_not_nil assigns(:issue_count_by_group)
188 188 end
189 189
190 190 def test_index_sort_by_field_not_included_in_columns
191 191 Setting.issue_list_default_columns = %w(subject author)
192 192 get :index, :sort => 'tracker'
193 193 end
194 194
195 195 def test_index_csv_with_project
196 196 Setting.default_language = 'en'
197 197
198 198 get :index, :format => 'csv'
199 199 assert_response :success
200 200 assert_not_nil assigns(:issues)
201 201 assert_equal 'text/csv', @response.content_type
202 202 assert @response.body.starts_with?("#,")
203 203
204 204 get :index, :project_id => 1, :format => 'csv'
205 205 assert_response :success
206 206 assert_not_nil assigns(:issues)
207 207 assert_equal 'text/csv', @response.content_type
208 208 end
209 209
210 210 def test_index_pdf
211 211 get :index, :format => 'pdf'
212 212 assert_response :success
213 213 assert_not_nil assigns(:issues)
214 214 assert_equal 'application/pdf', @response.content_type
215 215
216 216 get :index, :project_id => 1, :format => 'pdf'
217 217 assert_response :success
218 218 assert_not_nil assigns(:issues)
219 219 assert_equal 'application/pdf', @response.content_type
220 220
221 221 get :index, :project_id => 1, :query_id => 6, :format => 'pdf'
222 222 assert_response :success
223 223 assert_not_nil assigns(:issues)
224 224 assert_equal 'application/pdf', @response.content_type
225 225 end
226 226
227 227 def test_index_pdf_with_query_grouped_by_list_custom_field
228 228 get :index, :project_id => 1, :query_id => 9, :format => 'pdf'
229 229 assert_response :success
230 230 assert_not_nil assigns(:issues)
231 231 assert_not_nil assigns(:issue_count_by_group)
232 232 assert_equal 'application/pdf', @response.content_type
233 233 end
234 234
235 235 def test_index_sort
236 236 get :index, :sort => 'tracker,id:desc'
237 237 assert_response :success
238 238
239 239 sort_params = @request.session['issues_index_sort']
240 240 assert sort_params.is_a?(String)
241 241 assert_equal 'tracker,id:desc', sort_params
242 242
243 243 issues = assigns(:issues)
244 244 assert_not_nil issues
245 245 assert !issues.empty?
246 246 assert_equal issues.sort {|a,b| a.tracker == b.tracker ? b.id <=> a.id : a.tracker <=> b.tracker }.collect(&:id), issues.collect(&:id)
247 247 end
248 248
249 249 def test_index_with_columns
250 250 columns = ['tracker', 'subject', 'assigned_to']
251 251 get :index, :set_filter => 1, :c => columns
252 252 assert_response :success
253 253
254 254 # query should use specified columns
255 255 query = assigns(:query)
256 256 assert_kind_of Query, query
257 257 assert_equal columns, query.column_names.map(&:to_s)
258 258
259 259 # columns should be stored in session
260 260 assert_kind_of Hash, session[:query]
261 261 assert_kind_of Array, session[:query][:column_names]
262 262 assert_equal columns, session[:query][:column_names].map(&:to_s)
263 263 end
264 264
265 265 def test_show_by_anonymous
266 266 get :show, :id => 1
267 267 assert_response :success
268 268 assert_template 'show.rhtml'
269 269 assert_not_nil assigns(:issue)
270 270 assert_equal Issue.find(1), assigns(:issue)
271 271
272 272 # anonymous role is allowed to add a note
273 273 assert_tag :tag => 'form',
274 274 :descendant => { :tag => 'fieldset',
275 275 :child => { :tag => 'legend',
276 276 :content => /Notes/ } }
277 277 end
278 278
279 279 def test_show_by_manager
280 280 @request.session[:user_id] = 2
281 281 get :show, :id => 1
282 282 assert_response :success
283 283
284 284 assert_tag :tag => 'a',
285 285 :content => /Quote/
286 286
287 287 assert_tag :tag => 'form',
288 288 :descendant => { :tag => 'fieldset',
289 289 :child => { :tag => 'legend',
290 290 :content => /Change properties/ } },
291 291 :descendant => { :tag => 'fieldset',
292 292 :child => { :tag => 'legend',
293 293 :content => /Log time/ } },
294 294 :descendant => { :tag => 'fieldset',
295 295 :child => { :tag => 'legend',
296 296 :content => /Notes/ } }
297 297 end
298 298
299 299 def test_show_should_deny_anonymous_access_without_permission
300 300 Role.anonymous.remove_permission!(:view_issues)
301 301 get :show, :id => 1
302 302 assert_response :redirect
303 303 end
304 304
305 305 def test_show_should_deny_non_member_access_without_permission
306 306 Role.non_member.remove_permission!(:view_issues)
307 307 @request.session[:user_id] = 9
308 308 get :show, :id => 1
309 309 assert_response 403
310 310 end
311 311
312 312 def test_show_should_deny_member_access_without_permission
313 313 Role.find(1).remove_permission!(:view_issues)
314 314 @request.session[:user_id] = 2
315 315 get :show, :id => 1
316 316 assert_response 403
317 317 end
318 318
319 319 def test_show_should_not_disclose_relations_to_invisible_issues
320 320 Setting.cross_project_issue_relations = '1'
321 321 IssueRelation.create!(:issue_from => Issue.find(1), :issue_to => Issue.find(2), :relation_type => 'relates')
322 322 # Relation to a private project issue
323 323 IssueRelation.create!(:issue_from => Issue.find(1), :issue_to => Issue.find(4), :relation_type => 'relates')
324 324
325 325 get :show, :id => 1
326 326 assert_response :success
327 327
328 328 assert_tag :div, :attributes => { :id => 'relations' },
329 329 :descendant => { :tag => 'a', :content => /#2$/ }
330 330 assert_no_tag :div, :attributes => { :id => 'relations' },
331 331 :descendant => { :tag => 'a', :content => /#4$/ }
332 332 end
333 333
334 334 def test_show_atom
335 335 get :show, :id => 2, :format => 'atom'
336 336 assert_response :success
337 337 assert_template 'journals/index.rxml'
338 338 # Inline image
339 339 assert_select 'content', :text => Regexp.new(Regexp.quote('http://test.host/attachments/download/10'))
340 340 end
341 341
342 342 def test_show_export_to_pdf
343 343 get :show, :id => 3, :format => 'pdf'
344 344 assert_response :success
345 345 assert_equal 'application/pdf', @response.content_type
346 346 assert @response.body.starts_with?('%PDF')
347 347 assert_not_nil assigns(:issue)
348 348 end
349 349
350 350 def test_get_new
351 351 @request.session[:user_id] = 2
352 352 get :new, :project_id => 1, :tracker_id => 1
353 353 assert_response :success
354 354 assert_template 'new'
355 355
356 356 assert_tag :tag => 'input', :attributes => { :name => 'issue[custom_field_values][2]',
357 357 :value => 'Default string' }
358 358 end
359 359
360 360 def test_get_new_without_tracker_id
361 361 @request.session[:user_id] = 2
362 362 get :new, :project_id => 1
363 363 assert_response :success
364 364 assert_template 'new'
365 365
366 366 issue = assigns(:issue)
367 367 assert_not_nil issue
368 368 assert_equal Project.find(1).trackers.first, issue.tracker
369 369 end
370 370
371 371 def test_get_new_with_no_default_status_should_display_an_error
372 372 @request.session[:user_id] = 2
373 373 IssueStatus.delete_all
374 374
375 375 get :new, :project_id => 1
376 376 assert_response 500
377 377 assert_error_tag :content => /No default issue/
378 378 end
379 379
380 380 def test_get_new_with_no_tracker_should_display_an_error
381 381 @request.session[:user_id] = 2
382 382 Tracker.delete_all
383 383
384 384 get :new, :project_id => 1
385 385 assert_response 500
386 386 assert_error_tag :content => /No tracker/
387 387 end
388 388
389 389 def test_update_new_form
390 390 @request.session[:user_id] = 2
391 391 xhr :post, :new, :project_id => 1,
392 392 :issue => {:tracker_id => 2,
393 393 :subject => 'This is the test_new issue',
394 394 :description => 'This is the description',
395 395 :priority_id => 5}
396 396 assert_response :success
397 397 assert_template 'attributes'
398 398
399 399 issue = assigns(:issue)
400 400 assert_kind_of Issue, issue
401 401 assert_equal 1, issue.project_id
402 402 assert_equal 2, issue.tracker_id
403 403 assert_equal 'This is the test_new issue', issue.subject
404 404 end
405 405
406 406 def test_post_create
407 407 @request.session[:user_id] = 2
408 408 assert_difference 'Issue.count' do
409 409 post :create, :project_id => 1,
410 410 :issue => {:tracker_id => 3,
411 411 :status_id => 2,
412 412 :subject => 'This is the test_new issue',
413 413 :description => 'This is the description',
414 414 :priority_id => 5,
415 415 :start_date => '2010-11-07',
416 416 :estimated_hours => '',
417 417 :custom_field_values => {'2' => 'Value for field 2'}}
418 418 end
419 419 assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id
420 420
421 421 issue = Issue.find_by_subject('This is the test_new issue')
422 422 assert_not_nil issue
423 423 assert_equal 2, issue.author_id
424 424 assert_equal 3, issue.tracker_id
425 425 assert_equal 2, issue.status_id
426 426 assert_equal Date.parse('2010-11-07'), issue.start_date
427 427 assert_nil issue.estimated_hours
428 428 v = issue.custom_values.find(:first, :conditions => {:custom_field_id => 2})
429 429 assert_not_nil v
430 430 assert_equal 'Value for field 2', v.value
431 431 end
432 432
433 433 def test_post_create_without_start_date
434 434 @request.session[:user_id] = 2
435 435 assert_difference 'Issue.count' do
436 436 post :create, :project_id => 1,
437 437 :issue => {:tracker_id => 3,
438 438 :status_id => 2,
439 439 :subject => 'This is the test_new issue',
440 440 :description => 'This is the description',
441 441 :priority_id => 5,
442 442 :start_date => '',
443 443 :estimated_hours => '',
444 444 :custom_field_values => {'2' => 'Value for field 2'}}
445 445 end
446 446 assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id
447 447
448 448 issue = Issue.find_by_subject('This is the test_new issue')
449 449 assert_not_nil issue
450 450 assert_nil issue.start_date
451 451 end
452 452
453 453 def test_post_create_and_continue
454 454 @request.session[:user_id] = 2
455 455 post :create, :project_id => 1,
456 456 :issue => {:tracker_id => 3,
457 457 :subject => 'This is first issue',
458 458 :priority_id => 5},
459 459 :continue => ''
460 460 assert_redirected_to :controller => 'issues', :action => 'new', :project_id => 'ecookbook',
461 461 :issue => {:tracker_id => 3}
462 462 end
463 463
464 464 def test_post_create_without_custom_fields_param
465 465 @request.session[:user_id] = 2
466 466 assert_difference 'Issue.count' do
467 467 post :create, :project_id => 1,
468 468 :issue => {:tracker_id => 1,
469 469 :subject => 'This is the test_new issue',
470 470 :description => 'This is the description',
471 471 :priority_id => 5}
472 472 end
473 473 assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id
474 474 end
475 475
476 476 def test_post_create_with_required_custom_field_and_without_custom_fields_param
477 477 field = IssueCustomField.find_by_name('Database')
478 478 field.update_attribute(:is_required, true)
479 479
480 480 @request.session[:user_id] = 2
481 481 post :create, :project_id => 1,
482 482 :issue => {:tracker_id => 1,
483 483 :subject => 'This is the test_new issue',
484 484 :description => 'This is the description',
485 485 :priority_id => 5}
486 486 assert_response :success
487 487 assert_template 'new'
488 488 issue = assigns(:issue)
489 489 assert_not_nil issue
490 490 assert_equal I18n.translate('activerecord.errors.messages.invalid'), issue.errors.on(:custom_values)
491 491 end
492 492
493 493 def test_post_create_with_watchers
494 494 @request.session[:user_id] = 2
495 495 ActionMailer::Base.deliveries.clear
496 496
497 497 assert_difference 'Watcher.count', 2 do
498 498 post :create, :project_id => 1,
499 499 :issue => {:tracker_id => 1,
500 500 :subject => 'This is a new issue with watchers',
501 501 :description => 'This is the description',
502 502 :priority_id => 5,
503 503 :watcher_user_ids => ['2', '3']}
504 504 end
505 505 issue = Issue.find_by_subject('This is a new issue with watchers')
506 506 assert_not_nil issue
507 507 assert_redirected_to :controller => 'issues', :action => 'show', :id => issue
508 508
509 509 # Watchers added
510 510 assert_equal [2, 3], issue.watcher_user_ids.sort
511 511 assert issue.watched_by?(User.find(3))
512 512 # Watchers notified
513 513 mail = ActionMailer::Base.deliveries.last
514 514 assert_kind_of TMail::Mail, mail
515 515 assert [mail.bcc, mail.cc].flatten.include?(User.find(3).mail)
516 516 end
517 517
518 518 def test_post_create_subissue
519 519 @request.session[:user_id] = 2
520 520
521 521 assert_difference 'Issue.count' do
522 522 post :create, :project_id => 1,
523 523 :issue => {:tracker_id => 1,
524 524 :subject => 'This is a child issue',
525 525 :parent_issue_id => 2}
526 526 end
527 527 issue = Issue.find_by_subject('This is a child issue')
528 528 assert_not_nil issue
529 529 assert_equal Issue.find(2), issue.parent
530 530 end
531 531
532 532 def test_post_create_subissue_with_non_numeric_parent_id
533 533 @request.session[:user_id] = 2
534 534
535 535 assert_difference 'Issue.count' do
536 536 post :create, :project_id => 1,
537 537 :issue => {:tracker_id => 1,
538 538 :subject => 'This is a child issue',
539 539 :parent_issue_id => 'ABC'}
540 540 end
541 541 issue = Issue.find_by_subject('This is a child issue')
542 542 assert_not_nil issue
543 543 assert_nil issue.parent
544 544 end
545 545
546 546 def test_post_create_should_send_a_notification
547 547 ActionMailer::Base.deliveries.clear
548 548 @request.session[:user_id] = 2
549 549 assert_difference 'Issue.count' do
550 550 post :create, :project_id => 1,
551 551 :issue => {:tracker_id => 3,
552 552 :subject => 'This is the test_new issue',
553 553 :description => 'This is the description',
554 554 :priority_id => 5,
555 555 :estimated_hours => '',
556 556 :custom_field_values => {'2' => 'Value for field 2'}}
557 557 end
558 558 assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id
559 559
560 560 assert_equal 1, ActionMailer::Base.deliveries.size
561 561 end
562 562
563 563 def test_post_create_should_preserve_fields_values_on_validation_failure
564 564 @request.session[:user_id] = 2
565 565 post :create, :project_id => 1,
566 566 :issue => {:tracker_id => 1,
567 567 # empty subject
568 568 :subject => '',
569 569 :description => 'This is a description',
570 570 :priority_id => 6,
571 571 :custom_field_values => {'1' => 'Oracle', '2' => 'Value for field 2'}}
572 572 assert_response :success
573 573 assert_template 'new'
574 574
575 575 assert_tag :textarea, :attributes => { :name => 'issue[description]' },
576 576 :content => 'This is a description'
577 577 assert_tag :select, :attributes => { :name => 'issue[priority_id]' },
578 578 :child => { :tag => 'option', :attributes => { :selected => 'selected',
579 579 :value => '6' },
580 580 :content => 'High' }
581 581 # Custom fields
582 582 assert_tag :select, :attributes => { :name => 'issue[custom_field_values][1]' },
583 583 :child => { :tag => 'option', :attributes => { :selected => 'selected',
584 584 :value => 'Oracle' },
585 585 :content => 'Oracle' }
586 586 assert_tag :input, :attributes => { :name => 'issue[custom_field_values][2]',
587 587 :value => 'Value for field 2'}
588 588 end
589 589
590 590 def test_post_create_should_ignore_non_safe_attributes
591 591 @request.session[:user_id] = 2
592 592 assert_nothing_raised do
593 593 post :create, :project_id => 1, :issue => { :tracker => "A param can not be a Tracker" }
594 594 end
595 595 end
596 596
597 597 context "without workflow privilege" do
598 598 setup do
599 599 Workflow.delete_all(["role_id = ?", Role.anonymous.id])
600 600 Role.anonymous.add_permission! :add_issues, :add_issue_notes
601 601 end
602 602
603 603 context "#new" do
604 604 should "propose default status only" do
605 605 get :new, :project_id => 1
606 606 assert_response :success
607 607 assert_template 'new'
608 608 assert_tag :tag => 'select',
609 609 :attributes => {:name => 'issue[status_id]'},
610 610 :children => {:count => 1},
611 611 :child => {:tag => 'option', :attributes => {:value => IssueStatus.default.id.to_s}}
612 612 end
613 613
614 614 should "accept default status" do
615 615 assert_difference 'Issue.count' do
616 616 post :create, :project_id => 1,
617 617 :issue => {:tracker_id => 1,
618 618 :subject => 'This is an issue',
619 619 :status_id => 1}
620 620 end
621 621 issue = Issue.last(:order => 'id')
622 622 assert_equal IssueStatus.default, issue.status
623 623 end
624 624
625 should "accept default status" do
626 assert_difference 'Issue.count' do
627 post :create, :project_id => 1,
628 :issue => {:tracker_id => 1,
629 :subject => 'This is an issue',
630 :status_id => 1}
631 end
632 issue = Issue.last(:order => 'id')
633 assert_equal IssueStatus.default, issue.status
634 end
635
636 625 should "ignore unauthorized status" do
637 626 assert_difference 'Issue.count' do
638 627 post :create, :project_id => 1,
639 628 :issue => {:tracker_id => 1,
640 629 :subject => 'This is an issue',
641 630 :status_id => 3}
642 631 end
643 632 issue = Issue.last(:order => 'id')
644 633 assert_equal IssueStatus.default, issue.status
645 634 end
646 635 end
647 636
648 637 context "#update" do
649 638 should "ignore status change" do
650 639 assert_difference 'Journal.count' do
651 640 put :update, :id => 1, :notes => 'just trying', :issue => {:status_id => 3}
652 641 end
653 642 assert_equal 1, Issue.find(1).status_id
654 643 end
655 644
656 645 should "ignore attributes changes" do
657 646 assert_difference 'Journal.count' do
658 647 put :update, :id => 1, :notes => 'just trying', :issue => {:subject => 'changed', :assigned_to_id => 2}
659 648 end
660 649 issue = Issue.find(1)
661 650 assert_equal "Can't print recipes", issue.subject
662 651 assert_nil issue.assigned_to
663 652 end
664 653 end
665 654 end
666 655
667 656 context "with workflow privilege" do
668 657 setup do
669 658 Workflow.delete_all(["role_id = ?", Role.anonymous.id])
670 659 Workflow.create!(:role => Role.anonymous, :tracker_id => 1, :old_status_id => 1, :new_status_id => 3)
671 660 Workflow.create!(:role => Role.anonymous, :tracker_id => 1, :old_status_id => 1, :new_status_id => 4)
672 661 Role.anonymous.add_permission! :add_issues, :add_issue_notes
673 662 end
674 663
675 664 context "#update" do
676 665 should "accept authorized status" do
677 666 assert_difference 'Journal.count' do
678 667 put :update, :id => 1, :notes => 'just trying', :issue => {:status_id => 3}
679 668 end
680 669 assert_equal 3, Issue.find(1).status_id
681 670 end
682 671
683 672 should "ignore unauthorized status" do
684 673 assert_difference 'Journal.count' do
685 674 put :update, :id => 1, :notes => 'just trying', :issue => {:status_id => 2}
686 675 end
687 676 assert_equal 1, Issue.find(1).status_id
688 677 end
689 678
690 679 should "accept authorized attributes changes" do
691 680 assert_difference 'Journal.count' do
692 681 put :update, :id => 1, :notes => 'just trying', :issue => {:assigned_to_id => 2}
693 682 end
694 683 issue = Issue.find(1)
695 684 assert_equal 2, issue.assigned_to_id
696 685 end
697 686
698 687 should "ignore unauthorized attributes changes" do
699 688 assert_difference 'Journal.count' do
700 689 put :update, :id => 1, :notes => 'just trying', :issue => {:subject => 'changed'}
701 690 end
702 691 issue = Issue.find(1)
703 692 assert_equal "Can't print recipes", issue.subject
704 693 end
705 694 end
706 695
707 696 context "and :edit_issues permission" do
708 697 setup do
709 698 Role.anonymous.add_permission! :add_issues, :edit_issues
710 699 end
711 700
712 701 should "accept authorized status" do
713 702 assert_difference 'Journal.count' do
714 703 put :update, :id => 1, :notes => 'just trying', :issue => {:status_id => 3}
715 704 end
716 705 assert_equal 3, Issue.find(1).status_id
717 706 end
718 707
719 708 should "ignore unauthorized status" do
720 709 assert_difference 'Journal.count' do
721 710 put :update, :id => 1, :notes => 'just trying', :issue => {:status_id => 2}
722 711 end
723 712 assert_equal 1, Issue.find(1).status_id
724 713 end
725 714
726 715 should "accept authorized attributes changes" do
727 716 assert_difference 'Journal.count' do
728 717 put :update, :id => 1, :notes => 'just trying', :issue => {:subject => 'changed', :assigned_to_id => 2}
729 718 end
730 719 issue = Issue.find(1)
731 720 assert_equal "changed", issue.subject
732 721 assert_equal 2, issue.assigned_to_id
733 722 end
734 723 end
735 724 end
736 725
737 726 def test_copy_issue
738 727 @request.session[:user_id] = 2
739 728 get :new, :project_id => 1, :copy_from => 1
740 729 assert_template 'new'
741 730 assert_not_nil assigns(:issue)
742 731 orig = Issue.find(1)
743 732 assert_equal orig.subject, assigns(:issue).subject
744 733 end
745 734
746 735 def test_get_edit
747 736 @request.session[:user_id] = 2
748 737 get :edit, :id => 1
749 738 assert_response :success
750 739 assert_template 'edit'
751 740 assert_not_nil assigns(:issue)
752 741 assert_equal Issue.find(1), assigns(:issue)
753 742 end
754 743
755 744 def test_get_edit_with_params
756 745 @request.session[:user_id] = 2
757 746 get :edit, :id => 1, :issue => { :status_id => 5, :priority_id => 7 },
758 747 :time_entry => { :hours => '2.5', :comments => 'test_get_edit_with_params', :activity_id => TimeEntryActivity.first.id }
759 748 assert_response :success
760 749 assert_template 'edit'
761 750
762 751 issue = assigns(:issue)
763 752 assert_not_nil issue
764 753
765 754 assert_equal 5, issue.status_id
766 755 assert_tag :select, :attributes => { :name => 'issue[status_id]' },
767 756 :child => { :tag => 'option',
768 757 :content => 'Closed',
769 758 :attributes => { :selected => 'selected' } }
770 759
771 760 assert_equal 7, issue.priority_id
772 761 assert_tag :select, :attributes => { :name => 'issue[priority_id]' },
773 762 :child => { :tag => 'option',
774 763 :content => 'Urgent',
775 764 :attributes => { :selected => 'selected' } }
776 765
777 766 assert_tag :input, :attributes => { :name => 'time_entry[hours]', :value => '2.5' }
778 767 assert_tag :select, :attributes => { :name => 'time_entry[activity_id]' },
779 768 :child => { :tag => 'option',
780 769 :attributes => { :selected => 'selected', :value => TimeEntryActivity.first.id } }
781 770 assert_tag :input, :attributes => { :name => 'time_entry[comments]', :value => 'test_get_edit_with_params' }
782 771 end
783 772
784 773 def test_update_edit_form
785 774 @request.session[:user_id] = 2
786 775 xhr :post, :new, :project_id => 1,
787 776 :id => 1,
788 777 :issue => {:tracker_id => 2,
789 778 :subject => 'This is the test_new issue',
790 779 :description => 'This is the description',
791 780 :priority_id => 5}
792 781 assert_response :success
793 782 assert_template 'attributes'
794 783
795 784 issue = assigns(:issue)
796 785 assert_kind_of Issue, issue
797 786 assert_equal 1, issue.id
798 787 assert_equal 1, issue.project_id
799 788 assert_equal 2, issue.tracker_id
800 789 assert_equal 'This is the test_new issue', issue.subject
801 790 end
802 791
803 792 def test_update_using_invalid_http_verbs
804 793 @request.session[:user_id] = 2
805 794 subject = 'Updated by an invalid http verb'
806 795
807 796 get :update, :id => 1, :issue => {:subject => subject}
808 797 assert_not_equal subject, Issue.find(1).subject
809 798
810 799 post :update, :id => 1, :issue => {:subject => subject}
811 800 assert_not_equal subject, Issue.find(1).subject
812 801
813 802 delete :update, :id => 1, :issue => {:subject => subject}
814 803 assert_not_equal subject, Issue.find(1).subject
815 804 end
816 805
817 806 def test_put_update_without_custom_fields_param
818 807 @request.session[:user_id] = 2
819 808 ActionMailer::Base.deliveries.clear
820 809
821 810 issue = Issue.find(1)
822 811 assert_equal '125', issue.custom_value_for(2).value
823 812 old_subject = issue.subject
824 813 new_subject = 'Subject modified by IssuesControllerTest#test_post_edit'
825 814
826 815 assert_difference('Journal.count') do
827 816 assert_difference('JournalDetail.count', 2) do
828 817 put :update, :id => 1, :issue => {:subject => new_subject,
829 818 :priority_id => '6',
830 819 :category_id => '1' # no change
831 820 }
832 821 end
833 822 end
834 823 assert_redirected_to :action => 'show', :id => '1'
835 824 issue.reload
836 825 assert_equal new_subject, issue.subject
837 826 # Make sure custom fields were not cleared
838 827 assert_equal '125', issue.custom_value_for(2).value
839 828
840 829 mail = ActionMailer::Base.deliveries.last
841 830 assert_kind_of TMail::Mail, mail
842 831 assert mail.subject.starts_with?("[#{issue.project.name} - #{issue.tracker.name} ##{issue.id}]")
843 832 assert mail.body.include?("Subject changed from #{old_subject} to #{new_subject}")
844 833 end
845 834
846 835 def test_put_update_with_custom_field_change
847 836 @request.session[:user_id] = 2
848 837 issue = Issue.find(1)
849 838 assert_equal '125', issue.custom_value_for(2).value
850 839
851 840 assert_difference('Journal.count') do
852 841 assert_difference('JournalDetail.count', 3) do
853 842 put :update, :id => 1, :issue => {:subject => 'Custom field change',
854 843 :priority_id => '6',
855 844 :category_id => '1', # no change
856 845 :custom_field_values => { '2' => 'New custom value' }
857 846 }
858 847 end
859 848 end
860 849 assert_redirected_to :action => 'show', :id => '1'
861 850 issue.reload
862 851 assert_equal 'New custom value', issue.custom_value_for(2).value
863 852
864 853 mail = ActionMailer::Base.deliveries.last
865 854 assert_kind_of TMail::Mail, mail
866 855 assert mail.body.include?("Searchable field changed from 125 to New custom value")
867 856 end
868 857
869 858 def test_put_update_with_status_and_assignee_change
870 859 issue = Issue.find(1)
871 860 assert_equal 1, issue.status_id
872 861 @request.session[:user_id] = 2
873 862 assert_difference('TimeEntry.count', 0) do
874 863 put :update,
875 864 :id => 1,
876 865 :issue => { :status_id => 2, :assigned_to_id => 3 },
877 866 :notes => 'Assigned to dlopper',
878 867 :time_entry => { :hours => '', :comments => '', :activity_id => TimeEntryActivity.first }
879 868 end
880 869 assert_redirected_to :action => 'show', :id => '1'
881 870 issue.reload
882 871 assert_equal 2, issue.status_id
883 872 j = Journal.find(:first, :order => 'id DESC')
884 873 assert_equal 'Assigned to dlopper', j.notes
885 874 assert_equal 2, j.details.size
886 875
887 876 mail = ActionMailer::Base.deliveries.last
888 877 assert mail.body.include?("Status changed from New to Assigned")
889 878 # subject should contain the new status
890 879 assert mail.subject.include?("(#{ IssueStatus.find(2).name })")
891 880 end
892 881
893 882 def test_put_update_with_note_only
894 883 notes = 'Note added by IssuesControllerTest#test_update_with_note_only'
895 884 # anonymous user
896 885 put :update,
897 886 :id => 1,
898 887 :notes => notes
899 888 assert_redirected_to :action => 'show', :id => '1'
900 889 j = Journal.find(:first, :order => 'id DESC')
901 890 assert_equal notes, j.notes
902 891 assert_equal 0, j.details.size
903 892 assert_equal User.anonymous, j.user
904 893
905 894 mail = ActionMailer::Base.deliveries.last
906 895 assert mail.body.include?(notes)
907 896 end
908 897
909 898 def test_put_update_with_note_and_spent_time
910 899 @request.session[:user_id] = 2
911 900 spent_hours_before = Issue.find(1).spent_hours
912 901 assert_difference('TimeEntry.count') do
913 902 put :update,
914 903 :id => 1,
915 904 :notes => '2.5 hours added',
916 905 :time_entry => { :hours => '2.5', :comments => 'test_put_update_with_note_and_spent_time', :activity_id => TimeEntryActivity.first.id }
917 906 end
918 907 assert_redirected_to :action => 'show', :id => '1'
919 908
920 909 issue = Issue.find(1)
921 910
922 911 j = Journal.find(:first, :order => 'id DESC')
923 912 assert_equal '2.5 hours added', j.notes
924 913 assert_equal 0, j.details.size
925 914
926 915 t = issue.time_entries.find_by_comments('test_put_update_with_note_and_spent_time')
927 916 assert_not_nil t
928 917 assert_equal 2.5, t.hours
929 918 assert_equal spent_hours_before + 2.5, issue.spent_hours
930 919 end
931 920
932 921 def test_put_update_with_attachment_only
933 922 set_tmp_attachments_directory
934 923
935 924 # Delete all fixtured journals, a race condition can occur causing the wrong
936 925 # journal to get fetched in the next find.
937 926 Journal.delete_all
938 927
939 928 # anonymous user
940 929 put :update,
941 930 :id => 1,
942 931 :notes => '',
943 932 :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain')}}
944 933 assert_redirected_to :action => 'show', :id => '1'
945 934 j = Issue.find(1).journals.find(:first, :order => 'id DESC')
946 935 assert j.notes.blank?
947 936 assert_equal 1, j.details.size
948 937 assert_equal 'testfile.txt', j.details.first.value
949 938 assert_equal User.anonymous, j.user
950 939
951 940 mail = ActionMailer::Base.deliveries.last
952 941 assert mail.body.include?('testfile.txt')
953 942 end
954 943
955 944 def test_put_update_with_attachment_that_fails_to_save
956 945 set_tmp_attachments_directory
957 946
958 947 # Delete all fixtured journals, a race condition can occur causing the wrong
959 948 # journal to get fetched in the next find.
960 949 Journal.delete_all
961 950
962 951 # Mock out the unsaved attachment
963 952 Attachment.any_instance.stubs(:create).returns(Attachment.new)
964 953
965 954 # anonymous user
966 955 put :update,
967 956 :id => 1,
968 957 :notes => '',
969 958 :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain')}}
970 959 assert_redirected_to :action => 'show', :id => '1'
971 960 assert_equal '1 file(s) could not be saved.', flash[:warning]
972 961
973 962 end if Object.const_defined?(:Mocha)
974 963
975 964 def test_put_update_with_no_change
976 965 issue = Issue.find(1)
977 966 issue.journals.clear
978 967 ActionMailer::Base.deliveries.clear
979 968
980 969 put :update,
981 970 :id => 1,
982 971 :notes => ''
983 972 assert_redirected_to :action => 'show', :id => '1'
984 973
985 974 issue.reload
986 975 assert issue.journals.empty?
987 976 # No email should be sent
988 977 assert ActionMailer::Base.deliveries.empty?
989 978 end
990 979
991 980 def test_put_update_should_send_a_notification
992 981 @request.session[:user_id] = 2
993 982 ActionMailer::Base.deliveries.clear
994 983 issue = Issue.find(1)
995 984 old_subject = issue.subject
996 985 new_subject = 'Subject modified by IssuesControllerTest#test_post_edit'
997 986
998 987 put :update, :id => 1, :issue => {:subject => new_subject,
999 988 :priority_id => '6',
1000 989 :category_id => '1' # no change
1001 990 }
1002 991 assert_equal 1, ActionMailer::Base.deliveries.size
1003 992 end
1004 993
1005 994 def test_put_update_with_invalid_spent_time_hours_only
1006 995 @request.session[:user_id] = 2
1007 996 notes = 'Note added by IssuesControllerTest#test_post_edit_with_invalid_spent_time'
1008 997
1009 998 assert_no_difference('Journal.count') do
1010 999 put :update,
1011 1000 :id => 1,
1012 1001 :notes => notes,
1013 1002 :time_entry => {"comments"=>"", "activity_id"=>"", "hours"=>"2z"}
1014 1003 end
1015 1004 assert_response :success
1016 1005 assert_template 'edit'
1017 1006
1018 1007 assert_error_tag :descendant => {:content => /Activity can't be blank/}
1019 1008 assert_tag :textarea, :attributes => { :name => 'notes' }, :content => notes
1020 1009 assert_tag :input, :attributes => { :name => 'time_entry[hours]', :value => "2z" }
1021 1010 end
1022 1011
1023 1012 def test_put_update_with_invalid_spent_time_comments_only
1024 1013 @request.session[:user_id] = 2
1025 1014 notes = 'Note added by IssuesControllerTest#test_post_edit_with_invalid_spent_time'
1026 1015
1027 1016 assert_no_difference('Journal.count') do
1028 1017 put :update,
1029 1018 :id => 1,
1030 1019 :notes => notes,
1031 1020 :time_entry => {"comments"=>"this is my comment", "activity_id"=>"", "hours"=>""}
1032 1021 end
1033 1022 assert_response :success
1034 1023 assert_template 'edit'
1035 1024
1036 1025 assert_error_tag :descendant => {:content => /Activity can't be blank/}
1037 1026 assert_error_tag :descendant => {:content => /Hours can't be blank/}
1038 1027 assert_tag :textarea, :attributes => { :name => 'notes' }, :content => notes
1039 1028 assert_tag :input, :attributes => { :name => 'time_entry[comments]', :value => "this is my comment" }
1040 1029 end
1041 1030
1042 1031 def test_put_update_should_allow_fixed_version_to_be_set_to_a_subproject
1043 1032 issue = Issue.find(2)
1044 1033 @request.session[:user_id] = 2
1045 1034
1046 1035 put :update,
1047 1036 :id => issue.id,
1048 1037 :issue => {
1049 1038 :fixed_version_id => 4
1050 1039 }
1051 1040
1052 1041 assert_response :redirect
1053 1042 issue.reload
1054 1043 assert_equal 4, issue.fixed_version_id
1055 1044 assert_not_equal issue.project_id, issue.fixed_version.project_id
1056 1045 end
1057 1046
1058 1047 def test_put_update_should_redirect_back_using_the_back_url_parameter
1059 1048 issue = Issue.find(2)
1060 1049 @request.session[:user_id] = 2
1061 1050
1062 1051 put :update,
1063 1052 :id => issue.id,
1064 1053 :issue => {
1065 1054 :fixed_version_id => 4
1066 1055 },
1067 1056 :back_url => '/issues'
1068 1057
1069 1058 assert_response :redirect
1070 1059 assert_redirected_to '/issues'
1071 1060 end
1072 1061
1073 1062 def test_put_update_should_not_redirect_back_using_the_back_url_parameter_off_the_host
1074 1063 issue = Issue.find(2)
1075 1064 @request.session[:user_id] = 2
1076 1065
1077 1066 put :update,
1078 1067 :id => issue.id,
1079 1068 :issue => {
1080 1069 :fixed_version_id => 4
1081 1070 },
1082 1071 :back_url => 'http://google.com'
1083 1072
1084 1073 assert_response :redirect
1085 1074 assert_redirected_to :controller => 'issues', :action => 'show', :id => issue.id
1086 1075 end
1087 1076
1088 1077 def test_get_bulk_edit
1089 1078 @request.session[:user_id] = 2
1090 1079 get :bulk_edit, :ids => [1, 2]
1091 1080 assert_response :success
1092 1081 assert_template 'bulk_edit'
1093 1082
1094 1083 assert_tag :input, :attributes => {:name => 'issue[parent_issue_id]'}
1095 1084
1096 1085 # Project specific custom field, date type
1097 1086 field = CustomField.find(9)
1098 1087 assert !field.is_for_all?
1099 1088 assert_equal 'date', field.field_format
1100 1089 assert_tag :input, :attributes => {:name => 'issue[custom_field_values][9]'}
1101 1090
1102 1091 # System wide custom field
1103 1092 assert CustomField.find(1).is_for_all?
1104 1093 assert_tag :select, :attributes => {:name => 'issue[custom_field_values][1]'}
1105 1094 end
1106 1095
1107 1096 def test_get_bulk_edit_on_different_projects
1108 1097 @request.session[:user_id] = 2
1109 1098 get :bulk_edit, :ids => [1, 2, 6]
1110 1099 assert_response :success
1111 1100 assert_template 'bulk_edit'
1112 1101
1113 1102 # Can not set issues from different projects as children of an issue
1114 1103 assert_no_tag :input, :attributes => {:name => 'issue[parent_issue_id]'}
1115 1104
1116 1105 # Project specific custom field, date type
1117 1106 field = CustomField.find(9)
1118 1107 assert !field.is_for_all?
1119 1108 assert !field.project_ids.include?(Issue.find(6).project_id)
1120 1109 assert_no_tag :input, :attributes => {:name => 'issue[custom_field_values][9]'}
1121 1110 end
1122 1111
1123 1112 def test_bulk_update
1124 1113 @request.session[:user_id] = 2
1125 1114 # update issues priority
1126 1115 post :bulk_update, :ids => [1, 2], :notes => 'Bulk editing',
1127 1116 :issue => {:priority_id => 7,
1128 1117 :assigned_to_id => '',
1129 1118 :custom_field_values => {'2' => ''}}
1130 1119
1131 1120 assert_response 302
1132 1121 # check that the issues were updated
1133 1122 assert_equal [7, 7], Issue.find_all_by_id([1, 2]).collect {|i| i.priority.id}
1134 1123
1135 1124 issue = Issue.find(1)
1136 1125 journal = issue.journals.find(:first, :order => 'created_on DESC')
1137 1126 assert_equal '125', issue.custom_value_for(2).value
1138 1127 assert_equal 'Bulk editing', journal.notes
1139 1128 assert_equal 1, journal.details.size
1140 1129 end
1141 1130
1142 1131 def test_bulk_update_on_different_projects
1143 1132 @request.session[:user_id] = 2
1144 1133 # update issues priority
1145 1134 post :bulk_update, :ids => [1, 2, 6], :notes => 'Bulk editing',
1146 1135 :issue => {:priority_id => 7,
1147 1136 :assigned_to_id => '',
1148 1137 :custom_field_values => {'2' => ''}}
1149 1138
1150 1139 assert_response 302
1151 1140 # check that the issues were updated
1152 1141 assert_equal [7, 7, 7], Issue.find([1,2,6]).map(&:priority_id)
1153 1142
1154 1143 issue = Issue.find(1)
1155 1144 journal = issue.journals.find(:first, :order => 'created_on DESC')
1156 1145 assert_equal '125', issue.custom_value_for(2).value
1157 1146 assert_equal 'Bulk editing', journal.notes
1158 1147 assert_equal 1, journal.details.size
1159 1148 end
1160 1149
1161 1150 def test_bulk_update_on_different_projects_without_rights
1162 1151 @request.session[:user_id] = 3
1163 1152 user = User.find(3)
1164 1153 action = { :controller => "issues", :action => "bulk_update" }
1165 1154 assert user.allowed_to?(action, Issue.find(1).project)
1166 1155 assert ! user.allowed_to?(action, Issue.find(6).project)
1167 1156 post :bulk_update, :ids => [1, 6], :notes => 'Bulk should fail',
1168 1157 :issue => {:priority_id => 7,
1169 1158 :assigned_to_id => '',
1170 1159 :custom_field_values => {'2' => ''}}
1171 1160 assert_response 403
1172 1161 assert_not_equal "Bulk should fail", Journal.last.notes
1173 1162 end
1174 1163
1175 1164 def test_bullk_update_should_send_a_notification
1176 1165 @request.session[:user_id] = 2
1177 1166 ActionMailer::Base.deliveries.clear
1178 1167 post(:bulk_update,
1179 1168 {
1180 1169 :ids => [1, 2],
1181 1170 :notes => 'Bulk editing',
1182 1171 :issue => {
1183 1172 :priority_id => 7,
1184 1173 :assigned_to_id => '',
1185 1174 :custom_field_values => {'2' => ''}
1186 1175 }
1187 1176 })
1188 1177
1189 1178 assert_response 302
1190 1179 assert_equal 2, ActionMailer::Base.deliveries.size
1191 1180 end
1192 1181
1193 1182 def test_bulk_update_status
1194 1183 @request.session[:user_id] = 2
1195 1184 # update issues priority
1196 1185 post :bulk_update, :ids => [1, 2], :notes => 'Bulk editing status',
1197 1186 :issue => {:priority_id => '',
1198 1187 :assigned_to_id => '',
1199 1188 :status_id => '5'}
1200 1189
1201 1190 assert_response 302
1202 1191 issue = Issue.find(1)
1203 1192 assert issue.closed?
1204 1193 end
1205 1194
1206 1195 def test_bulk_update_parent_id
1207 1196 @request.session[:user_id] = 2
1208 1197 post :bulk_update, :ids => [1, 3],
1209 1198 :notes => 'Bulk editing parent',
1210 1199 :issue => {:priority_id => '', :assigned_to_id => '', :status_id => '', :parent_issue_id => '2'}
1211 1200
1212 1201 assert_response 302
1213 1202 parent = Issue.find(2)
1214 1203 assert_equal parent.id, Issue.find(1).parent_id
1215 1204 assert_equal parent.id, Issue.find(3).parent_id
1216 1205 assert_equal [1, 3], parent.children.collect(&:id).sort
1217 1206 end
1218 1207
1219 1208 def test_bulk_update_custom_field
1220 1209 @request.session[:user_id] = 2
1221 1210 # update issues priority
1222 1211 post :bulk_update, :ids => [1, 2], :notes => 'Bulk editing custom field',
1223 1212 :issue => {:priority_id => '',
1224 1213 :assigned_to_id => '',
1225 1214 :custom_field_values => {'2' => '777'}}
1226 1215
1227 1216 assert_response 302
1228 1217
1229 1218 issue = Issue.find(1)
1230 1219 journal = issue.journals.find(:first, :order => 'created_on DESC')
1231 1220 assert_equal '777', issue.custom_value_for(2).value
1232 1221 assert_equal 1, journal.details.size
1233 1222 assert_equal '125', journal.details.first.old_value
1234 1223 assert_equal '777', journal.details.first.value
1235 1224 end
1236 1225
1237 1226 def test_bulk_update_unassign
1238 1227 assert_not_nil Issue.find(2).assigned_to
1239 1228 @request.session[:user_id] = 2
1240 1229 # unassign issues
1241 1230 post :bulk_update, :ids => [1, 2], :notes => 'Bulk unassigning', :issue => {:assigned_to_id => 'none'}
1242 1231 assert_response 302
1243 1232 # check that the issues were updated
1244 1233 assert_nil Issue.find(2).assigned_to
1245 1234 end
1246 1235
1247 1236 def test_post_bulk_update_should_allow_fixed_version_to_be_set_to_a_subproject
1248 1237 @request.session[:user_id] = 2
1249 1238
1250 1239 post :bulk_update, :ids => [1,2], :issue => {:fixed_version_id => 4}
1251 1240
1252 1241 assert_response :redirect
1253 1242 issues = Issue.find([1,2])
1254 1243 issues.each do |issue|
1255 1244 assert_equal 4, issue.fixed_version_id
1256 1245 assert_not_equal issue.project_id, issue.fixed_version.project_id
1257 1246 end
1258 1247 end
1259 1248
1260 1249 def test_post_bulk_update_should_redirect_back_using_the_back_url_parameter
1261 1250 @request.session[:user_id] = 2
1262 1251 post :bulk_update, :ids => [1,2], :back_url => '/issues'
1263 1252
1264 1253 assert_response :redirect
1265 1254 assert_redirected_to '/issues'
1266 1255 end
1267 1256
1268 1257 def test_post_bulk_update_should_not_redirect_back_using_the_back_url_parameter_off_the_host
1269 1258 @request.session[:user_id] = 2
1270 1259 post :bulk_update, :ids => [1,2], :back_url => 'http://google.com'
1271 1260
1272 1261 assert_response :redirect
1273 1262 assert_redirected_to :controller => 'issues', :action => 'index', :project_id => Project.find(1).identifier
1274 1263 end
1275 1264
1276 1265 def test_destroy_issue_with_no_time_entries
1277 1266 assert_nil TimeEntry.find_by_issue_id(2)
1278 1267 @request.session[:user_id] = 2
1279 1268 post :destroy, :id => 2
1280 1269 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
1281 1270 assert_nil Issue.find_by_id(2)
1282 1271 end
1283 1272
1284 1273 def test_destroy_issues_with_time_entries
1285 1274 @request.session[:user_id] = 2
1286 1275 post :destroy, :ids => [1, 3]
1287 1276 assert_response :success
1288 1277 assert_template 'destroy'
1289 1278 assert_not_nil assigns(:hours)
1290 1279 assert Issue.find_by_id(1) && Issue.find_by_id(3)
1291 1280 end
1292 1281
1293 1282 def test_destroy_issues_and_destroy_time_entries
1294 1283 @request.session[:user_id] = 2
1295 1284 post :destroy, :ids => [1, 3], :todo => 'destroy'
1296 1285 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
1297 1286 assert !(Issue.find_by_id(1) || Issue.find_by_id(3))
1298 1287 assert_nil TimeEntry.find_by_id([1, 2])
1299 1288 end
1300 1289
1301 1290 def test_destroy_issues_and_assign_time_entries_to_project
1302 1291 @request.session[:user_id] = 2
1303 1292 post :destroy, :ids => [1, 3], :todo => 'nullify'
1304 1293 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
1305 1294 assert !(Issue.find_by_id(1) || Issue.find_by_id(3))
1306 1295 assert_nil TimeEntry.find(1).issue_id
1307 1296 assert_nil TimeEntry.find(2).issue_id
1308 1297 end
1309 1298
1310 1299 def test_destroy_issues_and_reassign_time_entries_to_another_issue
1311 1300 @request.session[:user_id] = 2
1312 1301 post :destroy, :ids => [1, 3], :todo => 'reassign', :reassign_to_id => 2
1313 1302 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
1314 1303 assert !(Issue.find_by_id(1) || Issue.find_by_id(3))
1315 1304 assert_equal 2, TimeEntry.find(1).issue_id
1316 1305 assert_equal 2, TimeEntry.find(2).issue_id
1317 1306 end
1318 1307
1319 1308 def test_destroy_issues_from_different_projects
1320 1309 @request.session[:user_id] = 2
1321 1310 post :destroy, :ids => [1, 2, 6], :todo => 'destroy'
1322 1311 assert_redirected_to :controller => 'issues', :action => 'index'
1323 1312 assert !(Issue.find_by_id(1) || Issue.find_by_id(2) || Issue.find_by_id(6))
1324 1313 end
1325 1314
1326 1315 def test_destroy_parent_and_child_issues
1327 1316 parent = Issue.generate!(:project_id => 1, :tracker_id => 1)
1328 1317 child = Issue.generate!(:project_id => 1, :tracker_id => 1, :parent_issue_id => parent.id)
1329 1318 assert child.is_descendant_of?(parent.reload)
1330 1319
1331 1320 @request.session[:user_id] = 2
1332 1321 assert_difference 'Issue.count', -2 do
1333 1322 post :destroy, :ids => [parent.id, child.id], :todo => 'destroy'
1334 1323 end
1335 1324 assert_response 302
1336 1325 end
1337 1326
1338 1327 def test_default_search_scope
1339 1328 get :index
1340 1329 assert_tag :div, :attributes => {:id => 'quick-search'},
1341 1330 :child => {:tag => 'form',
1342 1331 :child => {:tag => 'input', :attributes => {:name => 'issues', :type => 'hidden', :value => '1'}}}
1343 1332 end
1344 1333 end
General Comments 0
You need to be logged in to leave comments. Login now