##// END OF EJS Templates
Fixes strange random test failures with Mysql....
Jean-Philippe Lang -
r3610:edeb84a07052
parent child
Show More
@@ -1,1302 +1,1306
1 1 # Redmine - project management software
2 2 # Copyright (C) 2006-2008 Jean-Philippe Lang
3 3 #
4 4 # This program is free software; you can redistribute it and/or
5 5 # modify it under the terms of the GNU General Public License
6 6 # as published by the Free Software Foundation; either version 2
7 7 # of the License, or (at your option) any later version.
8 8 #
9 9 # This program is distributed in the hope that it will be useful,
10 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 12 # GNU General Public License for more details.
13 13 #
14 14 # You should have received a copy of the GNU General Public License
15 15 # along with this program; if not, write to the Free Software
16 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 17
18 18 require File.dirname(__FILE__) + '/../test_helper'
19 19 require 'issues_controller'
20 20
21 21 # Re-raise errors caught by the controller.
22 22 class IssuesController; def rescue_action(e) raise e end; end
23 23
24 24 class IssuesControllerTest < ActionController::TestCase
25 25 fixtures :projects,
26 26 :users,
27 27 :roles,
28 28 :members,
29 29 :member_roles,
30 30 :issues,
31 31 :issue_statuses,
32 32 :versions,
33 33 :trackers,
34 34 :projects_trackers,
35 35 :issue_categories,
36 36 :enabled_modules,
37 37 :enumerations,
38 38 :attachments,
39 39 :workflows,
40 40 :custom_fields,
41 41 :custom_values,
42 42 :custom_fields_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_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 end
134 134
135 135 def test_index_with_query
136 136 get :index, :project_id => 1, :query_id => 5
137 137 assert_response :success
138 138 assert_template 'index.rhtml'
139 139 assert_not_nil assigns(:issues)
140 140 assert_nil assigns(:issue_count_by_group)
141 141 end
142 142
143 143 def test_index_with_query_grouped_by_tracker
144 144 get :index, :project_id => 1, :query_id => 6
145 145 assert_response :success
146 146 assert_template 'index.rhtml'
147 147 assert_not_nil assigns(:issues)
148 148 assert_not_nil assigns(:issue_count_by_group)
149 149 end
150 150
151 151 def test_index_with_query_grouped_by_list_custom_field
152 152 get :index, :project_id => 1, :query_id => 9
153 153 assert_response :success
154 154 assert_template 'index.rhtml'
155 155 assert_not_nil assigns(:issues)
156 156 assert_not_nil assigns(:issue_count_by_group)
157 157 end
158 158
159 159 def test_index_sort_by_field_not_included_in_columns
160 160 Setting.issue_list_default_columns = %w(subject author)
161 161 get :index, :sort => 'tracker'
162 162 end
163 163
164 164 def test_index_csv_with_project
165 165 Setting.default_language = 'en'
166 166
167 167 get :index, :format => 'csv'
168 168 assert_response :success
169 169 assert_not_nil assigns(:issues)
170 170 assert_equal 'text/csv', @response.content_type
171 171 assert @response.body.starts_with?("#,")
172 172
173 173 get :index, :project_id => 1, :format => 'csv'
174 174 assert_response :success
175 175 assert_not_nil assigns(:issues)
176 176 assert_equal 'text/csv', @response.content_type
177 177 end
178 178
179 179 def test_index_pdf
180 180 get :index, :format => 'pdf'
181 181 assert_response :success
182 182 assert_not_nil assigns(:issues)
183 183 assert_equal 'application/pdf', @response.content_type
184 184
185 185 get :index, :project_id => 1, :format => 'pdf'
186 186 assert_response :success
187 187 assert_not_nil assigns(:issues)
188 188 assert_equal 'application/pdf', @response.content_type
189 189
190 190 get :index, :project_id => 1, :query_id => 6, :format => 'pdf'
191 191 assert_response :success
192 192 assert_not_nil assigns(:issues)
193 193 assert_equal 'application/pdf', @response.content_type
194 194 end
195 195
196 196 def test_index_pdf_with_query_grouped_by_list_custom_field
197 197 get :index, :project_id => 1, :query_id => 9, :format => 'pdf'
198 198 assert_response :success
199 199 assert_not_nil assigns(:issues)
200 200 assert_not_nil assigns(:issue_count_by_group)
201 201 assert_equal 'application/pdf', @response.content_type
202 202 end
203 203
204 204 def test_index_sort
205 205 get :index, :sort => 'tracker,id:desc'
206 206 assert_response :success
207 207
208 208 sort_params = @request.session['issues_index_sort']
209 209 assert sort_params.is_a?(String)
210 210 assert_equal 'tracker,id:desc', sort_params
211 211
212 212 issues = assigns(:issues)
213 213 assert_not_nil issues
214 214 assert !issues.empty?
215 215 assert_equal issues.sort {|a,b| a.tracker == b.tracker ? b.id <=> a.id : a.tracker <=> b.tracker }.collect(&:id), issues.collect(&:id)
216 216 end
217 217
218 218 def test_index_with_columns
219 219 columns = ['tracker', 'subject', 'assigned_to']
220 220 get :index, :set_filter => 1, :query => { 'column_names' => columns}
221 221 assert_response :success
222 222
223 223 # query should use specified columns
224 224 query = assigns(:query)
225 225 assert_kind_of Query, query
226 226 assert_equal columns, query.column_names.map(&:to_s)
227 227
228 228 # columns should be stored in session
229 229 assert_kind_of Hash, session[:query]
230 230 assert_kind_of Array, session[:query][:column_names]
231 231 assert_equal columns, session[:query][:column_names].map(&:to_s)
232 232 end
233 233
234 234 def test_calendar
235 235 get :calendar, :project_id => 1
236 236 assert_response :success
237 237 assert_template 'calendar'
238 238 assert_not_nil assigns(:calendar)
239 239 end
240 240
241 241 def test_cross_project_calendar
242 242 get :calendar
243 243 assert_response :success
244 244 assert_template 'calendar'
245 245 assert_not_nil assigns(:calendar)
246 246 end
247 247
248 248 def test_changes
249 249 get :changes, :project_id => 1
250 250 assert_response :success
251 251 assert_not_nil assigns(:journals)
252 252 assert_equal 'application/atom+xml', @response.content_type
253 253 end
254 254
255 255 def test_show_by_anonymous
256 256 get :show, :id => 1
257 257 assert_response :success
258 258 assert_template 'show.rhtml'
259 259 assert_not_nil assigns(:issue)
260 260 assert_equal Issue.find(1), assigns(:issue)
261 261
262 262 # anonymous role is allowed to add a note
263 263 assert_tag :tag => 'form',
264 264 :descendant => { :tag => 'fieldset',
265 265 :child => { :tag => 'legend',
266 266 :content => /Notes/ } }
267 267 end
268 268
269 269 def test_show_by_manager
270 270 @request.session[:user_id] = 2
271 271 get :show, :id => 1
272 272 assert_response :success
273 273
274 274 assert_tag :tag => 'form',
275 275 :descendant => { :tag => 'fieldset',
276 276 :child => { :tag => 'legend',
277 277 :content => /Change properties/ } },
278 278 :descendant => { :tag => 'fieldset',
279 279 :child => { :tag => 'legend',
280 280 :content => /Log time/ } },
281 281 :descendant => { :tag => 'fieldset',
282 282 :child => { :tag => 'legend',
283 283 :content => /Notes/ } }
284 284 end
285 285
286 286 def test_show_should_deny_anonymous_access_without_permission
287 287 Role.anonymous.remove_permission!(:view_issues)
288 288 get :show, :id => 1
289 289 assert_response :redirect
290 290 end
291 291
292 292 def test_show_should_deny_non_member_access_without_permission
293 293 Role.non_member.remove_permission!(:view_issues)
294 294 @request.session[:user_id] = 9
295 295 get :show, :id => 1
296 296 assert_response 403
297 297 end
298 298
299 299 def test_show_should_deny_member_access_without_permission
300 300 Role.find(1).remove_permission!(:view_issues)
301 301 @request.session[:user_id] = 2
302 302 get :show, :id => 1
303 303 assert_response 403
304 304 end
305 305
306 306 def test_show_should_not_disclose_relations_to_invisible_issues
307 307 Setting.cross_project_issue_relations = '1'
308 308 IssueRelation.create!(:issue_from => Issue.find(1), :issue_to => Issue.find(2), :relation_type => 'relates')
309 309 # Relation to a private project issue
310 310 IssueRelation.create!(:issue_from => Issue.find(1), :issue_to => Issue.find(4), :relation_type => 'relates')
311 311
312 312 get :show, :id => 1
313 313 assert_response :success
314 314
315 315 assert_tag :div, :attributes => { :id => 'relations' },
316 316 :descendant => { :tag => 'a', :content => /#2$/ }
317 317 assert_no_tag :div, :attributes => { :id => 'relations' },
318 318 :descendant => { :tag => 'a', :content => /#4$/ }
319 319 end
320 320
321 321 def test_show_atom
322 322 get :show, :id => 2, :format => 'atom'
323 323 assert_response :success
324 324 assert_template 'changes.rxml'
325 325 # Inline image
326 326 assert_select 'content', :text => Regexp.new(Regexp.quote('http://test.host/attachments/download/10'))
327 327 end
328 328
329 329 def test_show_export_to_pdf
330 330 get :show, :id => 3, :format => 'pdf'
331 331 assert_response :success
332 332 assert_equal 'application/pdf', @response.content_type
333 333 assert @response.body.starts_with?('%PDF')
334 334 assert_not_nil assigns(:issue)
335 335 end
336 336
337 337 def test_get_new
338 338 @request.session[:user_id] = 2
339 339 get :new, :project_id => 1, :tracker_id => 1
340 340 assert_response :success
341 341 assert_template 'new'
342 342
343 343 assert_tag :tag => 'input', :attributes => { :name => 'issue[custom_field_values][2]',
344 344 :value => 'Default string' }
345 345 end
346 346
347 347 def test_get_new_without_tracker_id
348 348 @request.session[:user_id] = 2
349 349 get :new, :project_id => 1
350 350 assert_response :success
351 351 assert_template 'new'
352 352
353 353 issue = assigns(:issue)
354 354 assert_not_nil issue
355 355 assert_equal Project.find(1).trackers.first, issue.tracker
356 356 end
357 357
358 358 def test_get_new_with_no_default_status_should_display_an_error
359 359 @request.session[:user_id] = 2
360 360 IssueStatus.delete_all
361 361
362 362 get :new, :project_id => 1
363 363 assert_response 500
364 364 assert_not_nil flash[:error]
365 365 assert_tag :tag => 'div', :attributes => { :class => /error/ },
366 366 :content => /No default issue/
367 367 end
368 368
369 369 def test_get_new_with_no_tracker_should_display_an_error
370 370 @request.session[:user_id] = 2
371 371 Tracker.delete_all
372 372
373 373 get :new, :project_id => 1
374 374 assert_response 500
375 375 assert_not_nil flash[:error]
376 376 assert_tag :tag => 'div', :attributes => { :class => /error/ },
377 377 :content => /No tracker/
378 378 end
379 379
380 380 def test_update_new_form
381 381 @request.session[:user_id] = 2
382 382 xhr :post, :update_form, :project_id => 1,
383 383 :issue => {:tracker_id => 2,
384 384 :subject => 'This is the test_new issue',
385 385 :description => 'This is the description',
386 386 :priority_id => 5}
387 387 assert_response :success
388 388 assert_template 'attributes'
389 389
390 390 issue = assigns(:issue)
391 391 assert_kind_of Issue, issue
392 392 assert_equal 1, issue.project_id
393 393 assert_equal 2, issue.tracker_id
394 394 assert_equal 'This is the test_new issue', issue.subject
395 395 end
396 396
397 397 def test_post_create
398 398 @request.session[:user_id] = 2
399 399 assert_difference 'Issue.count' do
400 400 post :create, :project_id => 1,
401 401 :issue => {:tracker_id => 3,
402 402 :status_id => 2,
403 403 :subject => 'This is the test_new issue',
404 404 :description => 'This is the description',
405 405 :priority_id => 5,
406 406 :estimated_hours => '',
407 407 :custom_field_values => {'2' => 'Value for field 2'}}
408 408 end
409 409 assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id
410 410
411 411 issue = Issue.find_by_subject('This is the test_new issue')
412 412 assert_not_nil issue
413 413 assert_equal 2, issue.author_id
414 414 assert_equal 3, issue.tracker_id
415 415 assert_equal 2, issue.status_id
416 416 assert_nil issue.estimated_hours
417 417 v = issue.custom_values.find(:first, :conditions => {:custom_field_id => 2})
418 418 assert_not_nil v
419 419 assert_equal 'Value for field 2', v.value
420 420 end
421 421
422 422 def test_post_create_and_continue
423 423 @request.session[:user_id] = 2
424 424 post :create, :project_id => 1,
425 425 :issue => {:tracker_id => 3,
426 426 :subject => 'This is first issue',
427 427 :priority_id => 5},
428 428 :continue => ''
429 429 assert_redirected_to :controller => 'issues', :action => 'new', :issue => {:tracker_id => 3}
430 430 end
431 431
432 432 def test_post_create_without_custom_fields_param
433 433 @request.session[:user_id] = 2
434 434 assert_difference 'Issue.count' do
435 435 post :create, :project_id => 1,
436 436 :issue => {:tracker_id => 1,
437 437 :subject => 'This is the test_new issue',
438 438 :description => 'This is the description',
439 439 :priority_id => 5}
440 440 end
441 441 assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id
442 442 end
443 443
444 444 def test_post_create_with_required_custom_field_and_without_custom_fields_param
445 445 field = IssueCustomField.find_by_name('Database')
446 446 field.update_attribute(:is_required, true)
447 447
448 448 @request.session[:user_id] = 2
449 449 post :create, :project_id => 1,
450 450 :issue => {:tracker_id => 1,
451 451 :subject => 'This is the test_new issue',
452 452 :description => 'This is the description',
453 453 :priority_id => 5}
454 454 assert_response :success
455 455 assert_template 'new'
456 456 issue = assigns(:issue)
457 457 assert_not_nil issue
458 458 assert_equal I18n.translate('activerecord.errors.messages.invalid'), issue.errors.on(:custom_values)
459 459 end
460 460
461 461 def test_post_create_with_watchers
462 462 @request.session[:user_id] = 2
463 463 ActionMailer::Base.deliveries.clear
464 464
465 465 assert_difference 'Watcher.count', 2 do
466 466 post :create, :project_id => 1,
467 467 :issue => {:tracker_id => 1,
468 468 :subject => 'This is a new issue with watchers',
469 469 :description => 'This is the description',
470 470 :priority_id => 5,
471 471 :watcher_user_ids => ['2', '3']}
472 472 end
473 473 issue = Issue.find_by_subject('This is a new issue with watchers')
474 474 assert_not_nil issue
475 475 assert_redirected_to :controller => 'issues', :action => 'show', :id => issue
476 476
477 477 # Watchers added
478 478 assert_equal [2, 3], issue.watcher_user_ids.sort
479 479 assert issue.watched_by?(User.find(3))
480 480 # Watchers notified
481 481 mail = ActionMailer::Base.deliveries.last
482 482 assert_kind_of TMail::Mail, mail
483 483 assert [mail.bcc, mail.cc].flatten.include?(User.find(3).mail)
484 484 end
485 485
486 486 def test_post_create_subissue
487 487 @request.session[:user_id] = 2
488 488
489 489 assert_difference 'Issue.count' do
490 490 post :create, :project_id => 1,
491 491 :issue => {:tracker_id => 1,
492 492 :subject => 'This is a child issue',
493 493 :parent_issue_id => 2}
494 494 end
495 495 issue = Issue.find_by_subject('This is a child issue')
496 496 assert_not_nil issue
497 497 assert_equal Issue.find(2), issue.parent
498 498 end
499 499
500 500 def test_post_create_should_send_a_notification
501 501 ActionMailer::Base.deliveries.clear
502 502 @request.session[:user_id] = 2
503 503 assert_difference 'Issue.count' do
504 504 post :create, :project_id => 1,
505 505 :issue => {:tracker_id => 3,
506 506 :subject => 'This is the test_new issue',
507 507 :description => 'This is the description',
508 508 :priority_id => 5,
509 509 :estimated_hours => '',
510 510 :custom_field_values => {'2' => 'Value for field 2'}}
511 511 end
512 512 assert_redirected_to :controller => 'issues', :action => 'show', :id => Issue.last.id
513 513
514 514 assert_equal 1, ActionMailer::Base.deliveries.size
515 515 end
516 516
517 517 def test_post_create_should_preserve_fields_values_on_validation_failure
518 518 @request.session[:user_id] = 2
519 519 post :create, :project_id => 1,
520 520 :issue => {:tracker_id => 1,
521 521 # empty subject
522 522 :subject => '',
523 523 :description => 'This is a description',
524 524 :priority_id => 6,
525 525 :custom_field_values => {'1' => 'Oracle', '2' => 'Value for field 2'}}
526 526 assert_response :success
527 527 assert_template 'new'
528 528
529 529 assert_tag :textarea, :attributes => { :name => 'issue[description]' },
530 530 :content => 'This is a description'
531 531 assert_tag :select, :attributes => { :name => 'issue[priority_id]' },
532 532 :child => { :tag => 'option', :attributes => { :selected => 'selected',
533 533 :value => '6' },
534 534 :content => 'High' }
535 535 # Custom fields
536 536 assert_tag :select, :attributes => { :name => 'issue[custom_field_values][1]' },
537 537 :child => { :tag => 'option', :attributes => { :selected => 'selected',
538 538 :value => 'Oracle' },
539 539 :content => 'Oracle' }
540 540 assert_tag :input, :attributes => { :name => 'issue[custom_field_values][2]',
541 541 :value => 'Value for field 2'}
542 542 end
543 543
544 544 def test_post_create_should_ignore_non_safe_attributes
545 545 @request.session[:user_id] = 2
546 546 assert_nothing_raised do
547 547 post :create, :project_id => 1, :issue => { :tracker => "A param can not be a Tracker" }
548 548 end
549 549 end
550 550
551 551 context "without workflow privilege" do
552 552 setup do
553 553 Workflow.delete_all(["role_id = ?", Role.anonymous.id])
554 554 Role.anonymous.add_permission! :add_issues
555 555 end
556 556
557 557 context "#new" do
558 558 should "propose default status only" do
559 559 get :new, :project_id => 1
560 560 assert_response :success
561 561 assert_template 'new'
562 562 assert_tag :tag => 'select',
563 563 :attributes => {:name => 'issue[status_id]'},
564 564 :children => {:count => 1},
565 565 :child => {:tag => 'option', :attributes => {:value => IssueStatus.default.id.to_s}}
566 566 end
567 567
568 568 should "accept default status" do
569 569 assert_difference 'Issue.count' do
570 570 post :create, :project_id => 1,
571 571 :issue => {:tracker_id => 1,
572 572 :subject => 'This is an issue',
573 573 :status_id => 1}
574 574 end
575 575 issue = Issue.last(:order => 'id')
576 576 assert_equal IssueStatus.default, issue.status
577 577 end
578 578
579 579 should "ignore unauthorized status" do
580 580 assert_difference 'Issue.count' do
581 581 post :create, :project_id => 1,
582 582 :issue => {:tracker_id => 1,
583 583 :subject => 'This is an issue',
584 584 :status_id => 3}
585 585 end
586 586 issue = Issue.last(:order => 'id')
587 587 assert_equal IssueStatus.default, issue.status
588 588 end
589 589 end
590 590 end
591 591
592 592 def test_copy_issue
593 593 @request.session[:user_id] = 2
594 594 get :new, :project_id => 1, :copy_from => 1
595 595 assert_template 'new'
596 596 assert_not_nil assigns(:issue)
597 597 orig = Issue.find(1)
598 598 assert_equal orig.subject, assigns(:issue).subject
599 599 end
600 600
601 601 def test_get_edit
602 602 @request.session[:user_id] = 2
603 603 get :edit, :id => 1
604 604 assert_response :success
605 605 assert_template 'edit'
606 606 assert_not_nil assigns(:issue)
607 607 assert_equal Issue.find(1), assigns(:issue)
608 608 end
609 609
610 610 def test_get_edit_with_params
611 611 @request.session[:user_id] = 2
612 612 get :edit, :id => 1, :issue => { :status_id => 5, :priority_id => 7 }
613 613 assert_response :success
614 614 assert_template 'edit'
615 615
616 616 issue = assigns(:issue)
617 617 assert_not_nil issue
618 618
619 619 assert_equal 5, issue.status_id
620 620 assert_tag :select, :attributes => { :name => 'issue[status_id]' },
621 621 :child => { :tag => 'option',
622 622 :content => 'Closed',
623 623 :attributes => { :selected => 'selected' } }
624 624
625 625 assert_equal 7, issue.priority_id
626 626 assert_tag :select, :attributes => { :name => 'issue[priority_id]' },
627 627 :child => { :tag => 'option',
628 628 :content => 'Urgent',
629 629 :attributes => { :selected => 'selected' } }
630 630 end
631 631
632 632 def test_update_edit_form
633 633 @request.session[:user_id] = 2
634 634 xhr :post, :update_form, :project_id => 1,
635 635 :id => 1,
636 636 :issue => {:tracker_id => 2,
637 637 :subject => 'This is the test_new issue',
638 638 :description => 'This is the description',
639 639 :priority_id => 5}
640 640 assert_response :success
641 641 assert_template 'attributes'
642 642
643 643 issue = assigns(:issue)
644 644 assert_kind_of Issue, issue
645 645 assert_equal 1, issue.id
646 646 assert_equal 1, issue.project_id
647 647 assert_equal 2, issue.tracker_id
648 648 assert_equal 'This is the test_new issue', issue.subject
649 649 end
650 650
651 651 def test_reply_to_issue
652 652 @request.session[:user_id] = 2
653 653 get :reply, :id => 1
654 654 assert_response :success
655 655 assert_select_rjs :show, "update"
656 656 end
657 657
658 658 def test_reply_to_note
659 659 @request.session[:user_id] = 2
660 660 get :reply, :id => 1, :journal_id => 2
661 661 assert_response :success
662 662 assert_select_rjs :show, "update"
663 663 end
664 664
665 665 def test_update_using_invalid_http_verbs
666 666 @request.session[:user_id] = 2
667 667 subject = 'Updated by an invalid http verb'
668 668
669 669 get :update, :id => 1, :issue => {:subject => subject}
670 670 assert_not_equal subject, Issue.find(1).subject
671 671
672 672 post :update, :id => 1, :issue => {:subject => subject}
673 673 assert_not_equal subject, Issue.find(1).subject
674 674
675 675 delete :update, :id => 1, :issue => {:subject => subject}
676 676 assert_not_equal subject, Issue.find(1).subject
677 677 end
678 678
679 679 def test_put_update_without_custom_fields_param
680 680 @request.session[:user_id] = 2
681 681 ActionMailer::Base.deliveries.clear
682 682
683 683 issue = Issue.find(1)
684 684 assert_equal '125', issue.custom_value_for(2).value
685 685 old_subject = issue.subject
686 686 new_subject = 'Subject modified by IssuesControllerTest#test_post_edit'
687 687
688 688 assert_difference('Journal.count') do
689 689 assert_difference('JournalDetail.count', 2) do
690 690 put :update, :id => 1, :issue => {:subject => new_subject,
691 691 :priority_id => '6',
692 692 :category_id => '1' # no change
693 693 }
694 694 end
695 695 end
696 696 assert_redirected_to :action => 'show', :id => '1'
697 697 issue.reload
698 698 assert_equal new_subject, issue.subject
699 699 # Make sure custom fields were not cleared
700 700 assert_equal '125', issue.custom_value_for(2).value
701 701
702 702 mail = ActionMailer::Base.deliveries.last
703 703 assert_kind_of TMail::Mail, mail
704 704 assert mail.subject.starts_with?("[#{issue.project.name} - #{issue.tracker.name} ##{issue.id}]")
705 705 assert mail.body.include?("Subject changed from #{old_subject} to #{new_subject}")
706 706 end
707 707
708 708 def test_put_update_with_custom_field_change
709 709 @request.session[:user_id] = 2
710 710 issue = Issue.find(1)
711 711 assert_equal '125', issue.custom_value_for(2).value
712 712
713 713 assert_difference('Journal.count') do
714 714 assert_difference('JournalDetail.count', 3) do
715 715 put :update, :id => 1, :issue => {:subject => 'Custom field change',
716 716 :priority_id => '6',
717 717 :category_id => '1', # no change
718 718 :custom_field_values => { '2' => 'New custom value' }
719 719 }
720 720 end
721 721 end
722 722 assert_redirected_to :action => 'show', :id => '1'
723 723 issue.reload
724 724 assert_equal 'New custom value', issue.custom_value_for(2).value
725 725
726 726 mail = ActionMailer::Base.deliveries.last
727 727 assert_kind_of TMail::Mail, mail
728 728 assert mail.body.include?("Searchable field changed from 125 to New custom value")
729 729 end
730 730
731 731 def test_put_update_with_status_and_assignee_change
732 732 issue = Issue.find(1)
733 733 assert_equal 1, issue.status_id
734 734 @request.session[:user_id] = 2
735 735 assert_difference('TimeEntry.count', 0) do
736 736 put :update,
737 737 :id => 1,
738 738 :issue => { :status_id => 2, :assigned_to_id => 3 },
739 739 :notes => 'Assigned to dlopper',
740 740 :time_entry => { :hours => '', :comments => '', :activity_id => TimeEntryActivity.first }
741 741 end
742 742 assert_redirected_to :action => 'show', :id => '1'
743 743 issue.reload
744 744 assert_equal 2, issue.status_id
745 745 j = Journal.find(:first, :order => 'id DESC')
746 746 assert_equal 'Assigned to dlopper', j.notes
747 747 assert_equal 2, j.details.size
748 748
749 749 mail = ActionMailer::Base.deliveries.last
750 750 assert mail.body.include?("Status changed from New to Assigned")
751 751 # subject should contain the new status
752 752 assert mail.subject.include?("(#{ IssueStatus.find(2).name })")
753 753 end
754 754
755 755 def test_put_update_with_note_only
756 756 notes = 'Note added by IssuesControllerTest#test_update_with_note_only'
757 757 # anonymous user
758 758 put :update,
759 759 :id => 1,
760 760 :notes => notes
761 761 assert_redirected_to :action => 'show', :id => '1'
762 762 j = Journal.find(:first, :order => 'id DESC')
763 763 assert_equal notes, j.notes
764 764 assert_equal 0, j.details.size
765 765 assert_equal User.anonymous, j.user
766 766
767 767 mail = ActionMailer::Base.deliveries.last
768 768 assert mail.body.include?(notes)
769 769 end
770 770
771 771 def test_put_update_with_note_and_spent_time
772 772 @request.session[:user_id] = 2
773 773 spent_hours_before = Issue.find(1).spent_hours
774 774 assert_difference('TimeEntry.count') do
775 775 put :update,
776 776 :id => 1,
777 777 :notes => '2.5 hours added',
778 778 :time_entry => { :hours => '2.5', :comments => 'test_put_update_with_note_and_spent_time', :activity_id => TimeEntryActivity.first.id }
779 779 end
780 780 assert_redirected_to :action => 'show', :id => '1'
781 781
782 782 issue = Issue.find(1)
783 783
784 784 j = Journal.find(:first, :order => 'id DESC')
785 785 assert_equal '2.5 hours added', j.notes
786 786 assert_equal 0, j.details.size
787 787
788 788 t = issue.time_entries.find_by_comments('test_put_update_with_note_and_spent_time')
789 789 assert_not_nil t
790 790 assert_equal 2.5, t.hours
791 791 assert_equal spent_hours_before + 2.5, issue.spent_hours
792 792 end
793 793
794 794 def test_put_update_with_attachment_only
795 795 set_tmp_attachments_directory
796 796
797 797 # Delete all fixtured journals, a race condition can occur causing the wrong
798 798 # journal to get fetched in the next find.
799 799 Journal.delete_all
800 800
801 801 # anonymous user
802 802 put :update,
803 803 :id => 1,
804 804 :notes => '',
805 805 :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain')}}
806 806 assert_redirected_to :action => 'show', :id => '1'
807 807 j = Issue.find(1).journals.find(:first, :order => 'id DESC')
808 808 assert j.notes.blank?
809 809 assert_equal 1, j.details.size
810 810 assert_equal 'testfile.txt', j.details.first.value
811 811 assert_equal User.anonymous, j.user
812 812
813 813 mail = ActionMailer::Base.deliveries.last
814 814 assert mail.body.include?('testfile.txt')
815 815 end
816 816
817 817 def test_put_update_with_attachment_that_fails_to_save
818 818 set_tmp_attachments_directory
819 819
820 820 # Delete all fixtured journals, a race condition can occur causing the wrong
821 821 # journal to get fetched in the next find.
822 822 Journal.delete_all
823 823
824 824 # Mock out the unsaved attachment
825 825 Attachment.any_instance.stubs(:create).returns(Attachment.new)
826 826
827 827 # anonymous user
828 828 put :update,
829 829 :id => 1,
830 830 :notes => '',
831 831 :attachments => {'1' => {'file' => uploaded_test_file('testfile.txt', 'text/plain')}}
832 832 assert_redirected_to :action => 'show', :id => '1'
833 833 assert_equal '1 file(s) could not be saved.', flash[:warning]
834 834
835 835 end if Object.const_defined?(:Mocha)
836 836
837 837 def test_put_update_with_no_change
838 838 issue = Issue.find(1)
839 839 issue.journals.clear
840 840 ActionMailer::Base.deliveries.clear
841 841
842 842 put :update,
843 843 :id => 1,
844 844 :notes => ''
845 845 assert_redirected_to :action => 'show', :id => '1'
846 846
847 847 issue.reload
848 848 assert issue.journals.empty?
849 849 # No email should be sent
850 850 assert ActionMailer::Base.deliveries.empty?
851 851 end
852 852
853 853 def test_put_update_should_send_a_notification
854 854 @request.session[:user_id] = 2
855 855 ActionMailer::Base.deliveries.clear
856 856 issue = Issue.find(1)
857 857 old_subject = issue.subject
858 858 new_subject = 'Subject modified by IssuesControllerTest#test_post_edit'
859 859
860 860 put :update, :id => 1, :issue => {:subject => new_subject,
861 861 :priority_id => '6',
862 862 :category_id => '1' # no change
863 863 }
864 864 assert_equal 1, ActionMailer::Base.deliveries.size
865 865 end
866 866
867 867 def test_put_update_with_invalid_spent_time
868 868 @request.session[:user_id] = 2
869 869 notes = 'Note added by IssuesControllerTest#test_post_edit_with_invalid_spent_time'
870 870
871 871 assert_no_difference('Journal.count') do
872 872 put :update,
873 873 :id => 1,
874 874 :notes => notes,
875 875 :time_entry => {"comments"=>"", "activity_id"=>"", "hours"=>"2z"}
876 876 end
877 877 assert_response :success
878 878 assert_template 'edit'
879 879
880 880 assert_tag :textarea, :attributes => { :name => 'notes' },
881 881 :content => notes
882 882 assert_tag :input, :attributes => { :name => 'time_entry[hours]', :value => "2z" }
883 883 end
884 884
885 885 def test_put_update_should_allow_fixed_version_to_be_set_to_a_subproject
886 886 issue = Issue.find(2)
887 887 @request.session[:user_id] = 2
888 888
889 889 put :update,
890 890 :id => issue.id,
891 891 :issue => {
892 892 :fixed_version_id => 4
893 893 }
894 894
895 895 assert_response :redirect
896 896 issue.reload
897 897 assert_equal 4, issue.fixed_version_id
898 898 assert_not_equal issue.project_id, issue.fixed_version.project_id
899 899 end
900 900
901 901 def test_put_update_should_redirect_back_using_the_back_url_parameter
902 902 issue = Issue.find(2)
903 903 @request.session[:user_id] = 2
904 904
905 905 put :update,
906 906 :id => issue.id,
907 907 :issue => {
908 908 :fixed_version_id => 4
909 909 },
910 910 :back_url => '/issues'
911 911
912 912 assert_response :redirect
913 913 assert_redirected_to '/issues'
914 914 end
915 915
916 916 def test_put_update_should_not_redirect_back_using_the_back_url_parameter_off_the_host
917 917 issue = Issue.find(2)
918 918 @request.session[:user_id] = 2
919 919
920 920 put :update,
921 921 :id => issue.id,
922 922 :issue => {
923 923 :fixed_version_id => 4
924 924 },
925 925 :back_url => 'http://google.com'
926 926
927 927 assert_response :redirect
928 928 assert_redirected_to :controller => 'issues', :action => 'show', :id => issue.id
929 929 end
930 930
931 931 def test_get_bulk_edit
932 932 @request.session[:user_id] = 2
933 933 get :bulk_edit, :ids => [1, 2]
934 934 assert_response :success
935 935 assert_template 'bulk_edit'
936 936
937 937 # Project specific custom field, date type
938 938 field = CustomField.find(9)
939 939 assert !field.is_for_all?
940 940 assert_equal 'date', field.field_format
941 941 assert_tag :input, :attributes => {:name => 'issue[custom_field_values][9]'}
942 942
943 943 # System wide custom field
944 944 assert CustomField.find(1).is_for_all?
945 945 assert_tag :select, :attributes => {:name => 'issue[custom_field_values][1]'}
946 946 end
947 947
948 948 def test_bulk_edit
949 949 @request.session[:user_id] = 2
950 950 # update issues priority
951 951 post :bulk_edit, :ids => [1, 2], :notes => 'Bulk editing',
952 952 :issue => {:priority_id => 7,
953 953 :assigned_to_id => '',
954 954 :custom_field_values => {'2' => ''}}
955 955
956 956 assert_response 302
957 957 # check that the issues were updated
958 958 assert_equal [7, 7], Issue.find_all_by_id([1, 2]).collect {|i| i.priority.id}
959 959
960 960 issue = Issue.find(1)
961 961 journal = issue.journals.find(:first, :order => 'created_on DESC')
962 962 assert_equal '125', issue.custom_value_for(2).value
963 963 assert_equal 'Bulk editing', journal.notes
964 964 assert_equal 1, journal.details.size
965 965 end
966 966
967 967 def test_bullk_edit_should_send_a_notification
968 968 @request.session[:user_id] = 2
969 969 ActionMailer::Base.deliveries.clear
970 970 post(:bulk_edit,
971 971 {
972 972 :ids => [1, 2],
973 973 :notes => 'Bulk editing',
974 974 :issue => {
975 975 :priority_id => 7,
976 976 :assigned_to_id => '',
977 977 :custom_field_values => {'2' => ''}
978 978 }
979 979 })
980 980
981 981 assert_response 302
982 982 assert_equal 2, ActionMailer::Base.deliveries.size
983 983 end
984 984
985 985 def test_bulk_edit_status
986 986 @request.session[:user_id] = 2
987 987 # update issues priority
988 988 post :bulk_edit, :ids => [1, 2], :notes => 'Bulk editing status',
989 989 :issue => {:priority_id => '',
990 990 :assigned_to_id => '',
991 991 :status_id => '5'}
992 992
993 993 assert_response 302
994 994 issue = Issue.find(1)
995 995 assert issue.closed?
996 996 end
997 997
998 998 def test_bulk_edit_custom_field
999 999 @request.session[:user_id] = 2
1000 1000 # update issues priority
1001 1001 post :bulk_edit, :ids => [1, 2], :notes => 'Bulk editing custom field',
1002 1002 :issue => {:priority_id => '',
1003 1003 :assigned_to_id => '',
1004 1004 :custom_field_values => {'2' => '777'}}
1005 1005
1006 1006 assert_response 302
1007 1007
1008 1008 issue = Issue.find(1)
1009 1009 journal = issue.journals.find(:first, :order => 'created_on DESC')
1010 1010 assert_equal '777', issue.custom_value_for(2).value
1011 1011 assert_equal 1, journal.details.size
1012 1012 assert_equal '125', journal.details.first.old_value
1013 1013 assert_equal '777', journal.details.first.value
1014 1014 end
1015 1015
1016 1016 def test_bulk_unassign
1017 1017 assert_not_nil Issue.find(2).assigned_to
1018 1018 @request.session[:user_id] = 2
1019 1019 # unassign issues
1020 1020 post :bulk_edit, :ids => [1, 2], :notes => 'Bulk unassigning', :issue => {:assigned_to_id => 'none'}
1021 1021 assert_response 302
1022 1022 # check that the issues were updated
1023 1023 assert_nil Issue.find(2).assigned_to
1024 1024 end
1025 1025
1026 1026 def test_post_bulk_edit_should_allow_fixed_version_to_be_set_to_a_subproject
1027 1027 @request.session[:user_id] = 2
1028 1028
1029 1029 post :bulk_edit, :ids => [1,2], :issue => {:fixed_version_id => 4}
1030 1030
1031 1031 assert_response :redirect
1032 1032 issues = Issue.find([1,2])
1033 1033 issues.each do |issue|
1034 1034 assert_equal 4, issue.fixed_version_id
1035 1035 assert_not_equal issue.project_id, issue.fixed_version.project_id
1036 1036 end
1037 1037 end
1038 1038
1039 1039 def test_post_bulk_edit_should_redirect_back_using_the_back_url_parameter
1040 1040 @request.session[:user_id] = 2
1041 1041 post :bulk_edit, :ids => [1,2], :back_url => '/issues'
1042 1042
1043 1043 assert_response :redirect
1044 1044 assert_redirected_to '/issues'
1045 1045 end
1046 1046
1047 1047 def test_post_bulk_edit_should_not_redirect_back_using_the_back_url_parameter_off_the_host
1048 1048 @request.session[:user_id] = 2
1049 1049 post :bulk_edit, :ids => [1,2], :back_url => 'http://google.com'
1050 1050
1051 1051 assert_response :redirect
1052 1052 assert_redirected_to :controller => 'issues', :action => 'index', :project_id => Project.find(1).identifier
1053 1053 end
1054 1054
1055 1055 def test_move_one_issue_to_another_project
1056 1056 @request.session[:user_id] = 2
1057 1057 post :move, :id => 1, :new_project_id => 2, :tracker_id => '', :assigned_to_id => '', :status_id => '', :start_date => '', :due_date => ''
1058 1058 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
1059 1059 assert_equal 2, Issue.find(1).project_id
1060 1060 end
1061 1061
1062 1062 def test_move_one_issue_to_another_project_should_follow_when_needed
1063 1063 @request.session[:user_id] = 2
1064 1064 post :move, :id => 1, :new_project_id => 2, :follow => '1'
1065 1065 assert_redirected_to '/issues/1'
1066 1066 end
1067 1067
1068 1068 def test_bulk_move_to_another_project
1069 1069 @request.session[:user_id] = 2
1070 1070 post :move, :ids => [1, 2], :new_project_id => 2
1071 1071 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
1072 1072 # Issues moved to project 2
1073 1073 assert_equal 2, Issue.find(1).project_id
1074 1074 assert_equal 2, Issue.find(2).project_id
1075 1075 # No tracker change
1076 1076 assert_equal 1, Issue.find(1).tracker_id
1077 1077 assert_equal 2, Issue.find(2).tracker_id
1078 1078 end
1079 1079
1080 1080 def test_bulk_move_to_another_tracker
1081 1081 @request.session[:user_id] = 2
1082 1082 post :move, :ids => [1, 2], :new_tracker_id => 2
1083 1083 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
1084 1084 assert_equal 2, Issue.find(1).tracker_id
1085 1085 assert_equal 2, Issue.find(2).tracker_id
1086 1086 end
1087 1087
1088 1088 def test_bulk_copy_to_another_project
1089 1089 @request.session[:user_id] = 2
1090 1090 assert_difference 'Issue.count', 2 do
1091 1091 assert_no_difference 'Project.find(1).issues.count' do
1092 1092 post :move, :ids => [1, 2], :new_project_id => 2, :copy_options => {:copy => '1'}
1093 1093 end
1094 1094 end
1095 1095 assert_redirected_to 'projects/ecookbook/issues'
1096 1096 end
1097 1097
1098 1098 context "#move via bulk copy" do
1099 1099 should "allow not changing the issue's attributes" do
1100 1100 @request.session[:user_id] = 2
1101 1101 issue_before_move = Issue.find(1)
1102 1102 assert_difference 'Issue.count', 1 do
1103 1103 assert_no_difference 'Project.find(1).issues.count' do
1104 1104 post :move, :ids => [1], :new_project_id => 2, :copy_options => {:copy => '1'}, :new_tracker_id => '', :assigned_to_id => '', :status_id => '', :start_date => '', :due_date => ''
1105 1105 end
1106 1106 end
1107 1107 issue_after_move = Issue.first(:order => 'id desc', :conditions => {:project_id => 2})
1108 1108 assert_equal issue_before_move.tracker_id, issue_after_move.tracker_id
1109 1109 assert_equal issue_before_move.status_id, issue_after_move.status_id
1110 1110 assert_equal issue_before_move.assigned_to_id, issue_after_move.assigned_to_id
1111 1111 end
1112 1112
1113 1113 should "allow changing the issue's attributes" do
1114 # Fixes random test failure with Mysql
1115 # where Issue.all(:limit => 2, :order => 'id desc', :conditions => {:project_id => 2}) doesn't return the expected results
1116 Issue.delete_all("project_id=2")
1117
1114 1118 @request.session[:user_id] = 2
1115 1119 assert_difference 'Issue.count', 2 do
1116 1120 assert_no_difference 'Project.find(1).issues.count' do
1117 1121 post :move, :ids => [1, 2], :new_project_id => 2, :copy_options => {:copy => '1'}, :new_tracker_id => '', :assigned_to_id => 4, :status_id => 3, :start_date => '2009-12-01', :due_date => '2009-12-31'
1118 1122 end
1119 1123 end
1120 1124
1121 1125 copied_issues = Issue.all(:limit => 2, :order => 'id desc', :conditions => {:project_id => 2})
1122 1126 assert_equal 2, copied_issues.size
1123 1127 copied_issues.each do |issue|
1124 1128 assert_equal 2, issue.project_id, "Project is incorrect"
1125 1129 assert_equal 4, issue.assigned_to_id, "Assigned to is incorrect"
1126 1130 assert_equal 3, issue.status_id, "Status is incorrect"
1127 1131 assert_equal '2009-12-01', issue.start_date.to_s, "Start date is incorrect"
1128 1132 assert_equal '2009-12-31', issue.due_date.to_s, "Due date is incorrect"
1129 1133 end
1130 1134 end
1131 1135 end
1132 1136
1133 1137 def test_copy_to_another_project_should_follow_when_needed
1134 1138 @request.session[:user_id] = 2
1135 1139 post :move, :ids => [1], :new_project_id => 2, :copy_options => {:copy => '1'}, :follow => '1'
1136 1140 issue = Issue.first(:order => 'id DESC')
1137 1141 assert_redirected_to :controller => 'issues', :action => 'show', :id => issue
1138 1142 end
1139 1143
1140 1144 def test_context_menu_one_issue
1141 1145 @request.session[:user_id] = 2
1142 1146 get :context_menu, :ids => [1]
1143 1147 assert_response :success
1144 1148 assert_template 'context_menu'
1145 1149 assert_tag :tag => 'a', :content => 'Edit',
1146 1150 :attributes => { :href => '/issues/1/edit',
1147 1151 :class => 'icon-edit' }
1148 1152 assert_tag :tag => 'a', :content => 'Closed',
1149 1153 :attributes => { :href => '/issues/1/edit?issue%5Bstatus_id%5D=5',
1150 1154 :class => '' }
1151 1155 assert_tag :tag => 'a', :content => 'Immediate',
1152 1156 :attributes => { :href => '/issues/bulk_edit?ids%5B%5D=1&amp;issue%5Bpriority_id%5D=8',
1153 1157 :class => '' }
1154 1158 # Versions
1155 1159 assert_tag :tag => 'a', :content => '2.0',
1156 1160 :attributes => { :href => '/issues/bulk_edit?ids%5B%5D=1&amp;issue%5Bfixed_version_id%5D=3',
1157 1161 :class => '' }
1158 1162 assert_tag :tag => 'a', :content => 'eCookbook Subproject 1 - 2.0',
1159 1163 :attributes => { :href => '/issues/bulk_edit?ids%5B%5D=1&amp;issue%5Bfixed_version_id%5D=4',
1160 1164 :class => '' }
1161 1165
1162 1166 assert_tag :tag => 'a', :content => 'Dave Lopper',
1163 1167 :attributes => { :href => '/issues/bulk_edit?ids%5B%5D=1&amp;issue%5Bassigned_to_id%5D=3',
1164 1168 :class => '' }
1165 1169 assert_tag :tag => 'a', :content => 'Duplicate',
1166 1170 :attributes => { :href => '/projects/ecookbook/issues/1/copy',
1167 1171 :class => 'icon-duplicate' }
1168 1172 assert_tag :tag => 'a', :content => 'Copy',
1169 1173 :attributes => { :href => '/issues/move?copy_options%5Bcopy%5D=t&amp;ids%5B%5D=1',
1170 1174 :class => 'icon-copy' }
1171 1175 assert_tag :tag => 'a', :content => 'Move',
1172 1176 :attributes => { :href => '/issues/move?ids%5B%5D=1',
1173 1177 :class => 'icon-move' }
1174 1178 assert_tag :tag => 'a', :content => 'Delete',
1175 1179 :attributes => { :href => '/issues/destroy?ids%5B%5D=1',
1176 1180 :class => 'icon-del' }
1177 1181 end
1178 1182
1179 1183 def test_context_menu_one_issue_by_anonymous
1180 1184 get :context_menu, :ids => [1]
1181 1185 assert_response :success
1182 1186 assert_template 'context_menu'
1183 1187 assert_tag :tag => 'a', :content => 'Delete',
1184 1188 :attributes => { :href => '#',
1185 1189 :class => 'icon-del disabled' }
1186 1190 end
1187 1191
1188 1192 def test_context_menu_multiple_issues_of_same_project
1189 1193 @request.session[:user_id] = 2
1190 1194 get :context_menu, :ids => [1, 2]
1191 1195 assert_response :success
1192 1196 assert_template 'context_menu'
1193 1197 assert_tag :tag => 'a', :content => 'Edit',
1194 1198 :attributes => { :href => '/issues/bulk_edit?ids%5B%5D=1&amp;ids%5B%5D=2',
1195 1199 :class => 'icon-edit' }
1196 1200 assert_tag :tag => 'a', :content => 'Immediate',
1197 1201 :attributes => { :href => '/issues/bulk_edit?ids%5B%5D=1&amp;ids%5B%5D=2&amp;issue%5Bpriority_id%5D=8',
1198 1202 :class => '' }
1199 1203 assert_tag :tag => 'a', :content => 'Dave Lopper',
1200 1204 :attributes => { :href => '/issues/bulk_edit?ids%5B%5D=1&amp;ids%5B%5D=2&amp;issue%5Bassigned_to_id%5D=3',
1201 1205 :class => '' }
1202 1206 assert_tag :tag => 'a', :content => 'Copy',
1203 1207 :attributes => { :href => '/issues/move?copy_options%5Bcopy%5D=t&amp;ids%5B%5D=1&amp;ids%5B%5D=2',
1204 1208 :class => 'icon-copy' }
1205 1209 assert_tag :tag => 'a', :content => 'Move',
1206 1210 :attributes => { :href => '/issues/move?ids%5B%5D=1&amp;ids%5B%5D=2',
1207 1211 :class => 'icon-move' }
1208 1212 assert_tag :tag => 'a', :content => 'Delete',
1209 1213 :attributes => { :href => '/issues/destroy?ids%5B%5D=1&amp;ids%5B%5D=2',
1210 1214 :class => 'icon-del' }
1211 1215 end
1212 1216
1213 1217 def test_context_menu_multiple_issues_of_different_project
1214 1218 @request.session[:user_id] = 2
1215 1219 get :context_menu, :ids => [1, 2, 4]
1216 1220 assert_response :success
1217 1221 assert_template 'context_menu'
1218 1222 assert_tag :tag => 'a', :content => 'Delete',
1219 1223 :attributes => { :href => '#',
1220 1224 :class => 'icon-del disabled' }
1221 1225 end
1222 1226
1223 1227 def test_preview_new_issue
1224 1228 @request.session[:user_id] = 2
1225 1229 post :preview, :project_id => '1', :issue => {:description => 'Foo'}
1226 1230 assert_response :success
1227 1231 assert_template 'preview'
1228 1232 assert_not_nil assigns(:description)
1229 1233 end
1230 1234
1231 1235 def test_preview_notes
1232 1236 @request.session[:user_id] = 2
1233 1237 post :preview, :project_id => '1', :id => 1, :issue => {:description => Issue.find(1).description}, :notes => 'Foo'
1234 1238 assert_response :success
1235 1239 assert_template 'preview'
1236 1240 assert_not_nil assigns(:notes)
1237 1241 end
1238 1242
1239 1243 def test_auto_complete_should_not_be_case_sensitive
1240 1244 get :auto_complete, :project_id => 'ecookbook', :q => 'ReCiPe'
1241 1245 assert_response :success
1242 1246 assert_not_nil assigns(:issues)
1243 1247 assert assigns(:issues).detect {|issue| issue.subject.match /recipe/}
1244 1248 end
1245 1249
1246 1250 def test_auto_complete_should_return_issue_with_given_id
1247 1251 get :auto_complete, :project_id => 'subproject1', :q => '13'
1248 1252 assert_response :success
1249 1253 assert_not_nil assigns(:issues)
1250 1254 assert assigns(:issues).include?(Issue.find(13))
1251 1255 end
1252 1256
1253 1257 def test_destroy_issue_with_no_time_entries
1254 1258 assert_nil TimeEntry.find_by_issue_id(2)
1255 1259 @request.session[:user_id] = 2
1256 1260 post :destroy, :id => 2
1257 1261 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
1258 1262 assert_nil Issue.find_by_id(2)
1259 1263 end
1260 1264
1261 1265 def test_destroy_issues_with_time_entries
1262 1266 @request.session[:user_id] = 2
1263 1267 post :destroy, :ids => [1, 3]
1264 1268 assert_response :success
1265 1269 assert_template 'destroy'
1266 1270 assert_not_nil assigns(:hours)
1267 1271 assert Issue.find_by_id(1) && Issue.find_by_id(3)
1268 1272 end
1269 1273
1270 1274 def test_destroy_issues_and_destroy_time_entries
1271 1275 @request.session[:user_id] = 2
1272 1276 post :destroy, :ids => [1, 3], :todo => 'destroy'
1273 1277 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
1274 1278 assert !(Issue.find_by_id(1) || Issue.find_by_id(3))
1275 1279 assert_nil TimeEntry.find_by_id([1, 2])
1276 1280 end
1277 1281
1278 1282 def test_destroy_issues_and_assign_time_entries_to_project
1279 1283 @request.session[:user_id] = 2
1280 1284 post :destroy, :ids => [1, 3], :todo => 'nullify'
1281 1285 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
1282 1286 assert !(Issue.find_by_id(1) || Issue.find_by_id(3))
1283 1287 assert_nil TimeEntry.find(1).issue_id
1284 1288 assert_nil TimeEntry.find(2).issue_id
1285 1289 end
1286 1290
1287 1291 def test_destroy_issues_and_reassign_time_entries_to_another_issue
1288 1292 @request.session[:user_id] = 2
1289 1293 post :destroy, :ids => [1, 3], :todo => 'reassign', :reassign_to_id => 2
1290 1294 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
1291 1295 assert !(Issue.find_by_id(1) || Issue.find_by_id(3))
1292 1296 assert_equal 2, TimeEntry.find(1).issue_id
1293 1297 assert_equal 2, TimeEntry.find(2).issue_id
1294 1298 end
1295 1299
1296 1300 def test_default_search_scope
1297 1301 get :index
1298 1302 assert_tag :div, :attributes => {:id => 'quick-search'},
1299 1303 :child => {:tag => 'form',
1300 1304 :child => {:tag => 'input', :attributes => {:name => 'issues', :type => 'hidden', :value => '1'}}}
1301 1305 end
1302 1306 end
General Comments 0
You need to be logged in to leave comments. Login now