1 # Redmine - project management software
2 # Copyright (C) 2006-2008 Jean-Philippe Lang
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 require File.dirname(__FILE__) + '/../test_helper'
19 require 'issues_controller'
21 # Re-raise errors caught by the controller.
22 class IssuesController; def rescue_action(e) raise e end; end
24 class IssuesControllerTest < Test::Unit::TestCase
41 :custom_fields_trackers,
47 @controller = IssuesController.new
48 @request = ActionController::TestRequest.new
49 @response = ActionController::TestResponse.new
53 def test_index_routing
55 {:method => :get, :path => '/issues'},
56 :controller => 'issues', :action => 'index'
61 Setting.default_language = 'en'
64 assert_response :success
65 assert_template 'index.rhtml'
66 assert_not_nil assigns(:issues)
67 assert_nil assigns(:project)
68 assert_tag :tag => 'a', :content => /Can't print recipes/
69 assert_tag :tag => 'a', :content => /Subproject issue/
70 # private projects hidden
71 assert_no_tag :tag => 'a', :content => /Issue of a private subproject/
72 assert_no_tag :tag => 'a', :content => /Issue on project 2/
74 assert_tag :tag => 'th', :content => /Project/
77 def test_index_should_not_list_issues_when_module_disabled
78 EnabledModule.delete_all("name = 'issue_tracking' AND project_id = 1")
80 assert_response :success
81 assert_template 'index.rhtml'
82 assert_not_nil assigns(:issues)
83 assert_nil assigns(:project)
84 assert_no_tag :tag => 'a', :content => /Can't print recipes/
85 assert_tag :tag => 'a', :content => /Subproject issue/
88 def test_index_with_project_routing
90 {:method => :get, :path => '/projects/23/issues'},
91 :controller => 'issues', :action => 'index', :project_id => '23'
95 def test_index_should_not_list_issues_when_module_disabled
96 EnabledModule.delete_all("name = 'issue_tracking' AND project_id = 1")
98 assert_response :success
99 assert_template 'index.rhtml'
100 assert_not_nil assigns(:issues)
101 assert_nil assigns(:project)
102 assert_no_tag :tag => 'a', :content => /Can't print recipes/
103 assert_tag :tag => 'a', :content => /Subproject issue/
106 def test_index_with_project_routing
108 {:method => :get, :path => 'projects/23/issues'},
109 :controller => 'issues', :action => 'index', :project_id => '23'
113 def test_index_with_project
114 Setting.display_subprojects_issues = 0
115 get :index, :project_id => 1
116 assert_response :success
117 assert_template 'index.rhtml'
118 assert_not_nil assigns(:issues)
119 assert_tag :tag => 'a', :content => /Can't print recipes/
120 assert_no_tag :tag => 'a', :content => /Subproject issue/
123 def test_index_with_project_and_subprojects
124 Setting.display_subprojects_issues = 1
125 get :index, :project_id => 1
126 assert_response :success
127 assert_template 'index.rhtml'
128 assert_not_nil assigns(:issues)
129 assert_tag :tag => 'a', :content => /Can't print recipes/
130 assert_tag :tag => 'a', :content => /Subproject issue/
131 assert_no_tag :tag => 'a', :content => /Issue of a private subproject/
134 def test_index_with_project_and_subprojects_should_show_private_subprojects
135 @request.session[:user_id] = 2
136 Setting.display_subprojects_issues = 1
137 get :index, :project_id => 1
138 assert_response :success
139 assert_template 'index.rhtml'
140 assert_not_nil assigns(:issues)
141 assert_tag :tag => 'a', :content => /Can't print recipes/
142 assert_tag :tag => 'a', :content => /Subproject issue/
143 assert_tag :tag => 'a', :content => /Issue of a private subproject/
146 def test_index_with_project_routing_formatted
148 {:method => :get, :path => 'projects/23/issues.pdf'},
149 :controller => 'issues', :action => 'index', :project_id => '23', :format => 'pdf'
152 {:method => :get, :path => 'projects/23/issues.atom'},
153 :controller => 'issues', :action => 'index', :project_id => '23', :format => 'atom'
157 def test_index_with_project_and_filter
158 get :index, :project_id => 1, :set_filter => 1
159 assert_response :success
160 assert_template 'index.rhtml'
161 assert_not_nil assigns(:issues)
164 def test_index_csv_with_project
165 get :index, :format => 'csv'
166 assert_response :success
167 assert_not_nil assigns(:issues)
168 assert_equal 'text/csv', @response.content_type
170 get :index, :project_id => 1, :format => 'csv'
171 assert_response :success
172 assert_not_nil assigns(:issues)
173 assert_equal 'text/csv', @response.content_type
176 def test_index_formatted
178 {:method => :get, :path => 'issues.pdf'},
179 :controller => 'issues', :action => 'index', :format => 'pdf'
182 {:method => :get, :path => 'issues.atom'},
183 :controller => 'issues', :action => 'index', :format => 'atom'
188 get :index, :format => 'pdf'
189 assert_response :success
190 assert_not_nil assigns(:issues)
191 assert_equal 'application/pdf', @response.content_type
193 get :index, :project_id => 1, :format => 'pdf'
194 assert_response :success
195 assert_not_nil assigns(:issues)
196 assert_equal 'application/pdf', @response.content_type
200 get :index, :sort => 'tracker,id:desc'
201 assert_response :success
203 sort_params = @request.session['issues_index_sort']
204 assert sort_params.is_a?(String)
205 assert_equal 'tracker,id:desc', sort_params
207 issues = assigns(:issues)
208 assert_not_nil issues
209 assert !issues.empty?
210 assert_equal issues.sort {|a,b| a.tracker == b.tracker ? b.id <=> a.id : a.tracker <=> b.tracker }.collect(&:id), issues.collect(&:id)
214 get :gantt, :project_id => 1
215 assert_response :success
216 assert_template 'gantt.rhtml'
217 assert_not_nil assigns(:gantt)
218 events = assigns(:gantt).events
219 assert_not_nil events
220 # Issue with start and due dates
222 assert_not_nil i.due_date
223 assert events.include?(Issue.find(1))
224 # Issue with without due date but targeted to a version with date
226 assert_nil i.due_date
227 assert events.include?(i)
230 def test_cross_project_gantt
232 assert_response :success
233 assert_template 'gantt.rhtml'
234 assert_not_nil assigns(:gantt)
235 events = assigns(:gantt).events
236 assert_not_nil events
239 def test_gantt_export_to_pdf
240 get :gantt, :project_id => 1, :format => 'pdf'
241 assert_response :success
242 assert_equal 'application/pdf', @response.content_type
243 assert @response.body.starts_with?('%PDF')
244 assert_not_nil assigns(:gantt)
247 def test_cross_project_gantt_export_to_pdf
248 get :gantt, :format => 'pdf'
249 assert_response :success
250 assert_equal 'application/pdf', @response.content_type
251 assert @response.body.starts_with?('%PDF')
252 assert_not_nil assigns(:gantt)
255 if Object.const_defined?(:Magick)
257 get :gantt, :project_id => 1, :format => 'png'
258 assert_response :success
259 assert_equal 'image/png', @response.content_type
262 puts "RMagick not installed. Skipping tests !!!"
266 get :calendar, :project_id => 1
267 assert_response :success
268 assert_template 'calendar'
269 assert_not_nil assigns(:calendar)
272 def test_cross_project_calendar
274 assert_response :success
275 assert_template 'calendar'
276 assert_not_nil assigns(:calendar)
280 get :changes, :project_id => 1
281 assert_response :success
282 assert_not_nil assigns(:journals)
283 assert_equal 'application/atom+xml', @response.content_type
286 def test_show_routing
288 {:method => :get, :path => '/issues/64'},
289 :controller => 'issues', :action => 'show', :id => '64'
293 def test_show_routing_formatted
295 {:method => :get, :path => '/issues/2332.pdf'},
296 :controller => 'issues', :action => 'show', :id => '2332', :format => 'pdf'
299 {:method => :get, :path => '/issues/23123.atom'},
300 :controller => 'issues', :action => 'show', :id => '23123', :format => 'atom'
304 def test_show_by_anonymous
306 assert_response :success
307 assert_template 'show.rhtml'
308 assert_not_nil assigns(:issue)
309 assert_equal Issue.find(1), assigns(:issue)
311 # anonymous role is allowed to add a note
312 assert_tag :tag => 'form',
313 :descendant => { :tag => 'fieldset',
314 :child => { :tag => 'legend',
315 :content => /Notes/ } }
318 def test_show_by_manager
319 @request.session[:user_id] = 2
321 assert_response :success
323 assert_tag :tag => 'form',
324 :descendant => { :tag => 'fieldset',
325 :child => { :tag => 'legend',
326 :content => /Change properties/ } },
327 :descendant => { :tag => 'fieldset',
328 :child => { :tag => 'legend',
329 :content => /Log time/ } },
330 :descendant => { :tag => 'fieldset',
331 :child => { :tag => 'legend',
332 :content => /Notes/ } }
335 def test_show_should_not_disclose_relations_to_invisible_issues
336 Setting.cross_project_issue_relations = '1'
337 IssueRelation.create!(:issue_from => Issue.find(1), :issue_to => Issue.find(2), :relation_type => 'relates')
338 # Relation to a private project issue
339 IssueRelation.create!(:issue_from => Issue.find(1), :issue_to => Issue.find(4), :relation_type => 'relates')
342 assert_response :success
344 assert_tag :div, :attributes => { :id => 'relations' },
345 :descendant => { :tag => 'a', :content => /#2$/ }
346 assert_no_tag :div, :attributes => { :id => 'relations' },
347 :descendant => { :tag => 'a', :content => /#4$/ }
352 {:method => :get, :path => '/projects/1/issues/new'},
353 :controller => 'issues', :action => 'new', :project_id => '1'
356 {:controller => 'issues', :action => 'new', :project_id => '1'},
357 {:method => :post, :path => '/projects/1/issues'}
361 def test_show_export_to_pdf
362 get :show, :id => 3, :format => 'pdf'
363 assert_response :success
364 assert_equal 'application/pdf', @response.content_type
365 assert @response.body.starts_with?('%PDF')
366 assert_not_nil assigns(:issue)
370 @request.session[:user_id] = 2
371 get :new, :project_id => 1, :tracker_id => 1
372 assert_response :success
373 assert_template 'new'
375 assert_tag :tag => 'input', :attributes => { :name => 'issue[custom_field_values][2]',
376 :value => 'Default string' }
379 def test_get_new_without_tracker_id
380 @request.session[:user_id] = 2
381 get :new, :project_id => 1
382 assert_response :success
383 assert_template 'new'
385 issue = assigns(:issue)
387 assert_equal Project.find(1).trackers.first, issue.tracker
390 def test_get_new_with_no_default_status_should_display_an_error
391 @request.session[:user_id] = 2
392 IssueStatus.delete_all
394 get :new, :project_id => 1
396 assert_not_nil flash[:error]
397 assert_tag :tag => 'div', :attributes => { :class => /error/ },
398 :content => /No default issue/
401 def test_get_new_with_no_tracker_should_display_an_error
402 @request.session[:user_id] = 2
405 get :new, :project_id => 1
407 assert_not_nil flash[:error]
408 assert_tag :tag => 'div', :attributes => { :class => /error/ },
409 :content => /No tracker/
412 def test_update_new_form
413 @request.session[:user_id] = 2
414 xhr :post, :new, :project_id => 1,
415 :issue => {:tracker_id => 2,
416 :subject => 'This is the test_new issue',
417 :description => 'This is the description',
419 assert_response :success
420 assert_template 'new'
424 @request.session[:user_id] = 2
425 post :new, :project_id => 1,
426 :issue => {:tracker_id => 3,
427 :subject => 'This is the test_new issue',
428 :description => 'This is the description',
430 :estimated_hours => '',
431 :custom_field_values => {'2' => 'Value for field 2'}}
432 assert_redirected_to :action => 'show'
434 issue = Issue.find_by_subject('This is the test_new issue')
436 assert_equal 2, issue.author_id
437 assert_equal 3, issue.tracker_id
438 assert_nil issue.estimated_hours
439 v = issue.custom_values.find(:first, :conditions => {:custom_field_id => 2})
441 assert_equal 'Value for field 2', v.value
444 def test_post_new_and_continue
445 @request.session[:user_id] = 2
446 post :new, :project_id => 1,
447 :issue => {:tracker_id => 3,
448 :subject => 'This is first issue',
451 assert_redirected_to :controller => 'issues', :action => 'new', :tracker_id => 3
454 def test_post_new_without_custom_fields_param
455 @request.session[:user_id] = 2
456 post :new, :project_id => 1,
457 :issue => {:tracker_id => 1,
458 :subject => 'This is the test_new issue',
459 :description => 'This is the description',
461 assert_redirected_to :action => 'show'
464 def test_post_new_with_required_custom_field_and_without_custom_fields_param
465 field = IssueCustomField.find_by_name('Database')
466 field.update_attribute(:is_required, true)
468 @request.session[:user_id] = 2
469 post :new, :project_id => 1,
470 :issue => {:tracker_id => 1,
471 :subject => 'This is the test_new issue',
472 :description => 'This is the description',
474 assert_response :success
475 assert_template 'new'
476 issue = assigns(:issue)
478 assert_equal I18n.translate('activerecord.errors.messages.invalid'), issue.errors.on(:custom_values)
481 def test_post_new_with_watchers
482 @request.session[:user_id] = 2
483 ActionMailer::Base.deliveries.clear
485 assert_difference 'Watcher.count', 2 do
486 post :new, :project_id => 1,
487 :issue => {:tracker_id => 1,
488 :subject => 'This is a new issue with watchers',
489 :description => 'This is the description',
491 :watcher_user_ids => ['2', '3']}
493 issue = Issue.find_by_subject('This is a new issue with watchers')
495 assert_redirected_to :controller => 'issues', :action => 'show', :id => issue
498 assert_equal [2, 3], issue.watcher_user_ids.sort
499 assert issue.watched_by?(User.find(3))
501 mail = ActionMailer::Base.deliveries.last
502 assert_kind_of TMail::Mail, mail
503 assert [mail.bcc, mail.cc].flatten.include?(User.find(3).mail)
506 def test_post_new_should_send_a_notification
507 ActionMailer::Base.deliveries.clear
508 @request.session[:user_id] = 2
509 post :new, :project_id => 1,
510 :issue => {:tracker_id => 3,
511 :subject => 'This is the test_new issue',
512 :description => 'This is the description',
514 :estimated_hours => '',
515 :custom_field_values => {'2' => 'Value for field 2'}}
516 assert_redirected_to :action => 'show'
518 assert_equal 1, ActionMailer::Base.deliveries.size
521 def test_post_should_preserve_fields_values_on_validation_failure
522 @request.session[:user_id] = 2
523 post :new, :project_id => 1,
524 :issue => {:tracker_id => 1,
527 :description => 'This is a description',
529 :custom_field_values => {'1' => 'Oracle', '2' => 'Value for field 2'}}
530 assert_response :success
531 assert_template 'new'
533 assert_tag :textarea, :attributes => { :name => 'issue[description]' },
534 :content => 'This is a description'
535 assert_tag :select, :attributes => { :name => 'issue[priority_id]' },
536 :child => { :tag => 'option', :attributes => { :selected => 'selected',
540 assert_tag :select, :attributes => { :name => 'issue[custom_field_values][1]' },
541 :child => { :tag => 'option', :attributes => { :selected => 'selected',
542 :value => 'Oracle' },
543 :content => 'Oracle' }
544 assert_tag :input, :attributes => { :name => 'issue[custom_field_values][2]',
545 :value => 'Value for field 2'}
548 def test_copy_routing
550 {:method => :get, :path => '/projects/world_domination/issues/567/copy'},
551 :controller => 'issues', :action => 'new', :project_id => 'world_domination', :copy_from => '567'
556 @request.session[:user_id] = 2
557 get :new, :project_id => 1, :copy_from => 1
558 assert_template 'new'
559 assert_not_nil assigns(:issue)
561 assert_equal orig.subject, assigns(:issue).subject
564 def test_edit_routing
566 {:method => :get, :path => '/issues/1/edit'},
567 :controller => 'issues', :action => 'edit', :id => '1'
569 assert_recognizes( #TODO: use a PUT on the issue URI isntead, need to adjust form
570 {:controller => 'issues', :action => 'edit', :id => '1'},
571 {:method => :post, :path => '/issues/1/edit'}
576 @request.session[:user_id] = 2
578 assert_response :success
579 assert_template 'edit'
580 assert_not_nil assigns(:issue)
581 assert_equal Issue.find(1), assigns(:issue)
584 def test_get_edit_with_params
585 @request.session[:user_id] = 2
586 get :edit, :id => 1, :issue => { :status_id => 5, :priority_id => 7 }
587 assert_response :success
588 assert_template 'edit'
590 issue = assigns(:issue)
593 assert_equal 5, issue.status_id
594 assert_tag :select, :attributes => { :name => 'issue[status_id]' },
595 :child => { :tag => 'option',
596 :content => 'Closed',
597 :attributes => { :selected => 'selected' } }
599 assert_equal 7, issue.priority_id
600 assert_tag :select, :attributes => { :name => 'issue[priority_id]' },
601 :child => { :tag => 'option',
602 :content => 'Urgent',
603 :attributes => { :selected => 'selected' } }
606 def test_reply_routing
608 {:method => :post, :path => '/issues/1/quoted'},
609 :controller => 'issues', :action => 'reply', :id => '1'
613 def test_reply_to_issue
614 @request.session[:user_id] = 2
616 assert_response :success
617 assert_select_rjs :show, "update"
620 def test_reply_to_note
621 @request.session[:user_id] = 2
622 get :reply, :id => 1, :journal_id => 2
623 assert_response :success
624 assert_select_rjs :show, "update"
627 def test_post_edit_without_custom_fields_param
628 @request.session[:user_id] = 2
629 ActionMailer::Base.deliveries.clear
631 issue = Issue.find(1)
632 assert_equal '125', issue.custom_value_for(2).value
633 old_subject = issue.subject
634 new_subject = 'Subject modified by IssuesControllerTest#test_post_edit'
636 assert_difference('Journal.count') do
637 assert_difference('JournalDetail.count', 2) do
638 post :edit, :id => 1, :issue => {:subject => new_subject,
640 :category_id => '1' # no change
644 assert_redirected_to :action => 'show', :id => '1'
646 assert_equal new_subject, issue.subject
647 # Make sure custom fields were not cleared
648 assert_equal '125', issue.custom_value_for(2).value
650 mail = ActionMailer::Base.deliveries.last
651 assert_kind_of TMail::Mail, mail
652 assert mail.subject.starts_with?("[#{issue.project.name} - #{issue.tracker.name} ##{issue.id}]")
653 assert mail.body.include?("Subject changed from #{old_subject} to #{new_subject}")
656 def test_post_edit_with_custom_field_change
657 @request.session[:user_id] = 2
658 issue = Issue.find(1)
659 assert_equal '125', issue.custom_value_for(2).value
661 assert_difference('Journal.count') do
662 assert_difference('JournalDetail.count', 3) do
663 post :edit, :id => 1, :issue => {:subject => 'Custom field change',
665 :category_id => '1', # no change
666 :custom_field_values => { '2' => 'New custom value' }
670 assert_redirected_to :action => 'show', :id => '1'
672 assert_equal 'New custom value', issue.custom_value_for(2).value
674 mail = ActionMailer::Base.deliveries.last
675 assert_kind_of TMail::Mail, mail
676 assert mail.body.include?("Searchable field changed from 125 to New custom value")
679 def test_post_edit_with_status_and_assignee_change
680 issue = Issue.find(1)
681 assert_equal 1, issue.status_id
682 @request.session[:user_id] = 2
683 assert_difference('TimeEntry.count', 0) do
686 :issue => { :status_id => 2, :assigned_to_id => 3 },
687 :notes => 'Assigned to dlopper',
688 :time_entry => { :hours => '', :comments => '', :activity_id => Enumeration.activities.first }
690 assert_redirected_to :action => 'show', :id => '1'
692 assert_equal 2, issue.status_id
693 j = issue.journals.find(:first, :order => 'id DESC')
694 assert_equal 'Assigned to dlopper', j.notes
695 assert_equal 2, j.details.size
697 mail = ActionMailer::Base.deliveries.last
698 assert mail.body.include?("Status changed from New to Assigned")
701 def test_post_edit_with_note_only
702 notes = 'Note added by IssuesControllerTest#test_update_with_note_only'
707 assert_redirected_to :action => 'show', :id => '1'
708 j = Issue.find(1).journals.find(:first, :order => 'id DESC')
709 assert_equal notes, j.notes
710 assert_equal 0, j.details.size
711 assert_equal User.anonymous, j.user
713 mail = ActionMailer::Base.deliveries.last
714 assert mail.body.include?(notes)
717 def test_post_edit_with_note_and_spent_time
718 @request.session[:user_id] = 2
719 spent_hours_before = Issue.find(1).spent_hours
720 assert_difference('TimeEntry.count') do
723 :notes => '2.5 hours added',
724 :time_entry => { :hours => '2.5', :comments => '', :activity_id => Enumeration.activities.first }
726 assert_redirected_to :action => 'show', :id => '1'
728 issue = Issue.find(1)
730 j = issue.journals.find(:first, :order => 'id DESC')
731 assert_equal '2.5 hours added', j.notes
732 assert_equal 0, j.details.size
734 t = issue.time_entries.find(:first, :order => 'id DESC')
736 assert_equal 2.5, t.hours
737 assert_equal spent_hours_before + 2.5, issue.spent_hours
740 def test_post_edit_with_attachment_only
741 set_tmp_attachments_directory
743 # Delete all fixtured journals, a race condition can occur causing the wrong
744 # journal to get fetched in the next find.
751 :attachments => {'1' => {'file' => test_uploaded_file('testfile.txt', 'text/plain')}}
752 assert_redirected_to :action => 'show', :id => '1'
753 j = Issue.find(1).journals.find(:first, :order => 'id DESC')
754 assert j.notes.blank?
755 assert_equal 1, j.details.size
756 assert_equal 'testfile.txt', j.details.first.value
757 assert_equal User.anonymous, j.user
759 mail = ActionMailer::Base.deliveries.last
760 assert mail.body.include?('testfile.txt')
763 def test_post_edit_with_no_change
764 issue = Issue.find(1)
766 ActionMailer::Base.deliveries.clear
771 assert_redirected_to :action => 'show', :id => '1'
774 assert issue.journals.empty?
775 # No email should be sent
776 assert ActionMailer::Base.deliveries.empty?
779 def test_post_edit_should_send_a_notification
780 @request.session[:user_id] = 2
781 ActionMailer::Base.deliveries.clear
782 issue = Issue.find(1)
783 old_subject = issue.subject
784 new_subject = 'Subject modified by IssuesControllerTest#test_post_edit'
786 post :edit, :id => 1, :issue => {:subject => new_subject,
788 :category_id => '1' # no change
790 assert_equal 1, ActionMailer::Base.deliveries.size
793 def test_post_edit_with_invalid_spent_time
794 @request.session[:user_id] = 2
795 notes = 'Note added by IssuesControllerTest#test_post_edit_with_invalid_spent_time'
797 assert_no_difference('Journal.count') do
801 :time_entry => {"comments"=>"", "activity_id"=>"", "hours"=>"2z"}
803 assert_response :success
804 assert_template 'edit'
806 assert_tag :textarea, :attributes => { :name => 'notes' },
808 assert_tag :input, :attributes => { :name => 'time_entry[hours]', :value => "2z" }
812 @request.session[:user_id] = 2
813 # update issues priority
814 post :bulk_edit, :ids => [1, 2], :priority_id => 7,
815 :assigned_to_id => '',
816 :custom_field_values => {'2' => ''},
817 :notes => 'Bulk editing'
819 # check that the issues were updated
820 assert_equal [7, 7], Issue.find_all_by_id([1, 2]).collect {|i| i.priority.id}
822 issue = Issue.find(1)
823 journal = issue.journals.find(:first, :order => 'created_on DESC')
824 assert_equal '125', issue.custom_value_for(2).value
825 assert_equal 'Bulk editing', journal.notes
826 assert_equal 1, journal.details.size
829 def test_bullk_edit_should_send_a_notification
830 @request.session[:user_id] = 2
831 ActionMailer::Base.deliveries.clear
836 :assigned_to_id => '',
837 :custom_field_values => {'2' => ''},
838 :notes => 'Bulk editing'
842 assert_equal 2, ActionMailer::Base.deliveries.size
845 def test_bulk_edit_custom_field
846 @request.session[:user_id] = 2
847 # update issues priority
848 post :bulk_edit, :ids => [1, 2], :priority_id => '',
849 :assigned_to_id => '',
850 :custom_field_values => {'2' => '777'},
851 :notes => 'Bulk editing custom field'
854 issue = Issue.find(1)
855 journal = issue.journals.find(:first, :order => 'created_on DESC')
856 assert_equal '777', issue.custom_value_for(2).value
857 assert_equal 1, journal.details.size
858 assert_equal '125', journal.details.first.old_value
859 assert_equal '777', journal.details.first.value
862 def test_bulk_unassign
863 assert_not_nil Issue.find(2).assigned_to
864 @request.session[:user_id] = 2
866 post :bulk_edit, :ids => [1, 2], :notes => 'Bulk unassigning', :assigned_to_id => 'none'
868 # check that the issues were updated
869 assert_nil Issue.find(2).assigned_to
872 def test_move_routing
874 {:method => :get, :path => '/issues/1/move'},
875 :controller => 'issues', :action => 'move', :id => '1'
878 {:controller => 'issues', :action => 'move', :id => '1'},
879 {:method => :post, :path => '/issues/1/move'}
883 def test_move_one_issue_to_another_project
884 @request.session[:user_id] = 1
885 post :move, :id => 1, :new_project_id => 2
886 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
887 assert_equal 2, Issue.find(1).project_id
890 def test_bulk_move_to_another_project
891 @request.session[:user_id] = 1
892 post :move, :ids => [1, 2], :new_project_id => 2
893 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
894 # Issues moved to project 2
895 assert_equal 2, Issue.find(1).project_id
896 assert_equal 2, Issue.find(2).project_id
898 assert_equal 1, Issue.find(1).tracker_id
899 assert_equal 2, Issue.find(2).tracker_id
902 def test_bulk_move_to_another_tracker
903 @request.session[:user_id] = 1
904 post :move, :ids => [1, 2], :new_tracker_id => 2
905 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
906 assert_equal 2, Issue.find(1).tracker_id
907 assert_equal 2, Issue.find(2).tracker_id
910 def test_bulk_copy_to_another_project
911 @request.session[:user_id] = 1
912 assert_difference 'Issue.count', 2 do
913 assert_no_difference 'Project.find(1).issues.count' do
914 post :move, :ids => [1, 2], :new_project_id => 2, :copy_options => {:copy => '1'}
917 assert_redirected_to 'projects/ecookbook/issues'
920 def test_context_menu_one_issue
921 @request.session[:user_id] = 2
922 get :context_menu, :ids => [1]
923 assert_response :success
924 assert_template 'context_menu'
925 assert_tag :tag => 'a', :content => 'Edit',
926 :attributes => { :href => '/issues/1/edit',
927 :class => 'icon-edit' }
928 assert_tag :tag => 'a', :content => 'Closed',
929 :attributes => { :href => '/issues/1/edit?issue%5Bstatus_id%5D=5',
931 assert_tag :tag => 'a', :content => 'Immediate',
932 :attributes => { :href => '/issues/bulk_edit?ids%5B%5D=1&priority_id=8',
934 assert_tag :tag => 'a', :content => 'Dave Lopper',
935 :attributes => { :href => '/issues/bulk_edit?assigned_to_id=3&ids%5B%5D=1',
937 assert_tag :tag => 'a', :content => 'Copy',
938 :attributes => { :href => '/projects/ecookbook/issues/1/copy',
939 :class => 'icon-copy' }
940 assert_tag :tag => 'a', :content => 'Move',
941 :attributes => { :href => '/issues/move?ids%5B%5D=1',
942 :class => 'icon-move' }
943 assert_tag :tag => 'a', :content => 'Delete',
944 :attributes => { :href => '/issues/destroy?ids%5B%5D=1',
945 :class => 'icon-del' }
948 def test_context_menu_one_issue_by_anonymous
949 get :context_menu, :ids => [1]
950 assert_response :success
951 assert_template 'context_menu'
952 assert_tag :tag => 'a', :content => 'Delete',
953 :attributes => { :href => '#',
954 :class => 'icon-del disabled' }
957 def test_context_menu_multiple_issues_of_same_project
958 @request.session[:user_id] = 2
959 get :context_menu, :ids => [1, 2]
960 assert_response :success
961 assert_template 'context_menu'
962 assert_tag :tag => 'a', :content => 'Edit',
963 :attributes => { :href => '/issues/bulk_edit?ids%5B%5D=1&ids%5B%5D=2',
964 :class => 'icon-edit' }
965 assert_tag :tag => 'a', :content => 'Immediate',
966 :attributes => { :href => '/issues/bulk_edit?ids%5B%5D=1&ids%5B%5D=2&priority_id=8',
968 assert_tag :tag => 'a', :content => 'Dave Lopper',
969 :attributes => { :href => '/issues/bulk_edit?assigned_to_id=3&ids%5B%5D=1&ids%5B%5D=2',
971 assert_tag :tag => 'a', :content => 'Move',
972 :attributes => { :href => '/issues/move?ids%5B%5D=1&ids%5B%5D=2',
973 :class => 'icon-move' }
974 assert_tag :tag => 'a', :content => 'Delete',
975 :attributes => { :href => '/issues/destroy?ids%5B%5D=1&ids%5B%5D=2',
976 :class => 'icon-del' }
979 def test_context_menu_multiple_issues_of_different_project
980 @request.session[:user_id] = 2
981 get :context_menu, :ids => [1, 2, 4]
982 assert_response :success
983 assert_template 'context_menu'
984 assert_tag :tag => 'a', :content => 'Delete',
985 :attributes => { :href => '#',
986 :class => 'icon-del disabled' }
989 def test_destroy_routing
990 assert_recognizes( #TODO: use DELETE on issue URI (need to change forms)
991 {:controller => 'issues', :action => 'destroy', :id => '1'},
992 {:method => :post, :path => '/issues/1/destroy'}
996 def test_destroy_issue_with_no_time_entries
997 assert_nil TimeEntry.find_by_issue_id(2)
998 @request.session[:user_id] = 2
999 post :destroy, :id => 2
1000 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
1001 assert_nil Issue.find_by_id(2)
1004 def test_destroy_issues_with_time_entries
1005 @request.session[:user_id] = 2
1006 post :destroy, :ids => [1, 3]
1007 assert_response :success
1008 assert_template 'destroy'
1009 assert_not_nil assigns(:hours)
1010 assert Issue.find_by_id(1) && Issue.find_by_id(3)
1013 def test_destroy_issues_and_destroy_time_entries
1014 @request.session[:user_id] = 2
1015 post :destroy, :ids => [1, 3], :todo => 'destroy'
1016 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
1017 assert !(Issue.find_by_id(1) || Issue.find_by_id(3))
1018 assert_nil TimeEntry.find_by_id([1, 2])
1021 def test_destroy_issues_and_assign_time_entries_to_project
1022 @request.session[:user_id] = 2
1023 post :destroy, :ids => [1, 3], :todo => 'nullify'
1024 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
1025 assert !(Issue.find_by_id(1) || Issue.find_by_id(3))
1026 assert_nil TimeEntry.find(1).issue_id
1027 assert_nil TimeEntry.find(2).issue_id
1030 def test_destroy_issues_and_reassign_time_entries_to_another_issue
1031 @request.session[:user_id] = 2
1032 post :destroy, :ids => [1, 3], :todo => 'reassign', :reassign_to_id => 2
1033 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
1034 assert !(Issue.find_by_id(1) || Issue.find_by_id(3))
1035 assert_equal 2, TimeEntry.find(1).issue_id
1036 assert_equal 2, TimeEntry.find(2).issue_id