OSDN Git Service

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