##// END OF EJS Templates
Fixes functional test broken by r2246....
Jean-Philippe Lang -
r2246:a64928fa6be2
parent child
Show More
@@ -1,759 +1,759
1 # Redmine - project management software
1 # Redmine - project management software
2 # Copyright (C) 2006-2008 Jean-Philippe Lang
2 # Copyright (C) 2006-2008 Jean-Philippe Lang
3 #
3 #
4 # This program is free software; you can redistribute it and/or
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
7 # of the License, or (at your option) any later version.
8 #
8 #
9 # This program is distributed in the hope that it will be useful,
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
12 # GNU General Public License for more details.
13 #
13 #
14 # You should have received a copy of the GNU General Public License
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
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.
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
17
18 require File.dirname(__FILE__) + '/../test_helper'
18 require File.dirname(__FILE__) + '/../test_helper'
19 require 'issues_controller'
19 require 'issues_controller'
20
20
21 # Re-raise errors caught by the controller.
21 # Re-raise errors caught by the controller.
22 class IssuesController; def rescue_action(e) raise e end; end
22 class IssuesController; def rescue_action(e) raise e end; end
23
23
24 class IssuesControllerTest < Test::Unit::TestCase
24 class IssuesControllerTest < Test::Unit::TestCase
25 fixtures :projects,
25 fixtures :projects,
26 :users,
26 :users,
27 :roles,
27 :roles,
28 :members,
28 :members,
29 :issues,
29 :issues,
30 :issue_statuses,
30 :issue_statuses,
31 :versions,
31 :versions,
32 :trackers,
32 :trackers,
33 :projects_trackers,
33 :projects_trackers,
34 :issue_categories,
34 :issue_categories,
35 :enabled_modules,
35 :enabled_modules,
36 :enumerations,
36 :enumerations,
37 :attachments,
37 :attachments,
38 :workflows,
38 :workflows,
39 :custom_fields,
39 :custom_fields,
40 :custom_values,
40 :custom_values,
41 :custom_fields_trackers,
41 :custom_fields_trackers,
42 :time_entries,
42 :time_entries,
43 :journals,
43 :journals,
44 :journal_details
44 :journal_details
45
45
46 def setup
46 def setup
47 @controller = IssuesController.new
47 @controller = IssuesController.new
48 @request = ActionController::TestRequest.new
48 @request = ActionController::TestRequest.new
49 @response = ActionController::TestResponse.new
49 @response = ActionController::TestResponse.new
50 User.current = nil
50 User.current = nil
51 end
51 end
52
52
53 def test_index
53 def test_index
54 get :index
54 get :index
55 assert_response :success
55 assert_response :success
56 assert_template 'index.rhtml'
56 assert_template 'index.rhtml'
57 assert_not_nil assigns(:issues)
57 assert_not_nil assigns(:issues)
58 assert_nil assigns(:project)
58 assert_nil assigns(:project)
59 assert_tag :tag => 'a', :content => /Can't print recipes/
59 assert_tag :tag => 'a', :content => /Can't print recipes/
60 assert_tag :tag => 'a', :content => /Subproject issue/
60 assert_tag :tag => 'a', :content => /Subproject issue/
61 # private projects hidden
61 # private projects hidden
62 assert_no_tag :tag => 'a', :content => /Issue of a private subproject/
62 assert_no_tag :tag => 'a', :content => /Issue of a private subproject/
63 assert_no_tag :tag => 'a', :content => /Issue on project 2/
63 assert_no_tag :tag => 'a', :content => /Issue on project 2/
64 end
64 end
65
65
66 def test_index_should_not_list_issues_when_module_disabled
66 def test_index_should_not_list_issues_when_module_disabled
67 EnabledModule.delete_all("name = 'issue_tracking' AND project_id = 1")
67 EnabledModule.delete_all("name = 'issue_tracking' AND project_id = 1")
68 get :index
68 get :index
69 assert_response :success
69 assert_response :success
70 assert_template 'index.rhtml'
70 assert_template 'index.rhtml'
71 assert_not_nil assigns(:issues)
71 assert_not_nil assigns(:issues)
72 assert_nil assigns(:project)
72 assert_nil assigns(:project)
73 assert_no_tag :tag => 'a', :content => /Can't print recipes/
73 assert_no_tag :tag => 'a', :content => /Can't print recipes/
74 assert_tag :tag => 'a', :content => /Subproject issue/
74 assert_tag :tag => 'a', :content => /Subproject issue/
75 end
75 end
76
76
77 def test_index_with_project
77 def test_index_with_project
78 Setting.display_subprojects_issues = 0
78 Setting.display_subprojects_issues = 0
79 get :index, :project_id => 1
79 get :index, :project_id => 1
80 assert_response :success
80 assert_response :success
81 assert_template 'index.rhtml'
81 assert_template 'index.rhtml'
82 assert_not_nil assigns(:issues)
82 assert_not_nil assigns(:issues)
83 assert_tag :tag => 'a', :content => /Can't print recipes/
83 assert_tag :tag => 'a', :content => /Can't print recipes/
84 assert_no_tag :tag => 'a', :content => /Subproject issue/
84 assert_no_tag :tag => 'a', :content => /Subproject issue/
85 end
85 end
86
86
87 def test_index_with_project_and_subprojects
87 def test_index_with_project_and_subprojects
88 Setting.display_subprojects_issues = 1
88 Setting.display_subprojects_issues = 1
89 get :index, :project_id => 1
89 get :index, :project_id => 1
90 assert_response :success
90 assert_response :success
91 assert_template 'index.rhtml'
91 assert_template 'index.rhtml'
92 assert_not_nil assigns(:issues)
92 assert_not_nil assigns(:issues)
93 assert_tag :tag => 'a', :content => /Can't print recipes/
93 assert_tag :tag => 'a', :content => /Can't print recipes/
94 assert_tag :tag => 'a', :content => /Subproject issue/
94 assert_tag :tag => 'a', :content => /Subproject issue/
95 assert_no_tag :tag => 'a', :content => /Issue of a private subproject/
95 assert_no_tag :tag => 'a', :content => /Issue of a private subproject/
96 end
96 end
97
97
98 def test_index_with_project_and_subprojects_should_show_private_subprojects
98 def test_index_with_project_and_subprojects_should_show_private_subprojects
99 @request.session[:user_id] = 2
99 @request.session[:user_id] = 2
100 Setting.display_subprojects_issues = 1
100 Setting.display_subprojects_issues = 1
101 get :index, :project_id => 1
101 get :index, :project_id => 1
102 assert_response :success
102 assert_response :success
103 assert_template 'index.rhtml'
103 assert_template 'index.rhtml'
104 assert_not_nil assigns(:issues)
104 assert_not_nil assigns(:issues)
105 assert_tag :tag => 'a', :content => /Can't print recipes/
105 assert_tag :tag => 'a', :content => /Can't print recipes/
106 assert_tag :tag => 'a', :content => /Subproject issue/
106 assert_tag :tag => 'a', :content => /Subproject issue/
107 assert_tag :tag => 'a', :content => /Issue of a private subproject/
107 assert_tag :tag => 'a', :content => /Issue of a private subproject/
108 end
108 end
109
109
110 def test_index_with_project_and_filter
110 def test_index_with_project_and_filter
111 get :index, :project_id => 1, :set_filter => 1
111 get :index, :project_id => 1, :set_filter => 1
112 assert_response :success
112 assert_response :success
113 assert_template 'index.rhtml'
113 assert_template 'index.rhtml'
114 assert_not_nil assigns(:issues)
114 assert_not_nil assigns(:issues)
115 end
115 end
116
116
117 def test_index_csv_with_project
117 def test_index_csv_with_project
118 get :index, :format => 'csv'
118 get :index, :format => 'csv'
119 assert_response :success
119 assert_response :success
120 assert_not_nil assigns(:issues)
120 assert_not_nil assigns(:issues)
121 assert_equal 'text/csv', @response.content_type
121 assert_equal 'text/csv', @response.content_type
122
122
123 get :index, :project_id => 1, :format => 'csv'
123 get :index, :project_id => 1, :format => 'csv'
124 assert_response :success
124 assert_response :success
125 assert_not_nil assigns(:issues)
125 assert_not_nil assigns(:issues)
126 assert_equal 'text/csv', @response.content_type
126 assert_equal 'text/csv', @response.content_type
127 end
127 end
128
128
129 def test_index_pdf
129 def test_index_pdf
130 get :index, :format => 'pdf'
130 get :index, :format => 'pdf'
131 assert_response :success
131 assert_response :success
132 assert_not_nil assigns(:issues)
132 assert_not_nil assigns(:issues)
133 assert_equal 'application/pdf', @response.content_type
133 assert_equal 'application/pdf', @response.content_type
134
134
135 get :index, :project_id => 1, :format => 'pdf'
135 get :index, :project_id => 1, :format => 'pdf'
136 assert_response :success
136 assert_response :success
137 assert_not_nil assigns(:issues)
137 assert_not_nil assigns(:issues)
138 assert_equal 'application/pdf', @response.content_type
138 assert_equal 'application/pdf', @response.content_type
139 end
139 end
140
140
141 def test_index_sort
141 def test_index_sort
142 get :index, :sort_key => 'tracker'
142 get :index, :sort_key => 'tracker'
143 assert_response :success
143 assert_response :success
144
144
145 sort_params = @request.session['issuesindex_sort']
145 sort_params = @request.session['issuesindex_sort']
146 assert sort_params.is_a?(Hash)
146 assert sort_params.is_a?(Hash)
147 assert_equal 'tracker', sort_params[:key]
147 assert_equal 'tracker', sort_params[:key]
148 assert_equal 'ASC', sort_params[:order]
148 assert_equal 'ASC', sort_params[:order]
149 end
149 end
150
150
151 def test_gantt
151 def test_gantt
152 get :gantt, :project_id => 1
152 get :gantt, :project_id => 1
153 assert_response :success
153 assert_response :success
154 assert_template 'gantt.rhtml'
154 assert_template 'gantt.rhtml'
155 assert_not_nil assigns(:gantt)
155 assert_not_nil assigns(:gantt)
156 events = assigns(:gantt).events
156 events = assigns(:gantt).events
157 assert_not_nil events
157 assert_not_nil events
158 # Issue with start and due dates
158 # Issue with start and due dates
159 i = Issue.find(1)
159 i = Issue.find(1)
160 assert_not_nil i.due_date
160 assert_not_nil i.due_date
161 assert events.include?(Issue.find(1))
161 assert events.include?(Issue.find(1))
162 # Issue with without due date but targeted to a version with date
162 # Issue with without due date but targeted to a version with date
163 i = Issue.find(2)
163 i = Issue.find(2)
164 assert_nil i.due_date
164 assert_nil i.due_date
165 assert events.include?(i)
165 assert events.include?(i)
166 end
166 end
167
167
168 def test_cross_project_gantt
168 def test_cross_project_gantt
169 get :gantt
169 get :gantt
170 assert_response :success
170 assert_response :success
171 assert_template 'gantt.rhtml'
171 assert_template 'gantt.rhtml'
172 assert_not_nil assigns(:gantt)
172 assert_not_nil assigns(:gantt)
173 events = assigns(:gantt).events
173 events = assigns(:gantt).events
174 assert_not_nil events
174 assert_not_nil events
175 end
175 end
176
176
177 def test_gantt_export_to_pdf
177 def test_gantt_export_to_pdf
178 get :gantt, :project_id => 1, :format => 'pdf'
178 get :gantt, :project_id => 1, :format => 'pdf'
179 assert_response :success
179 assert_response :success
180 assert_equal 'application/pdf', @response.content_type
180 assert_equal 'application/pdf', @response.content_type
181 assert @response.body.starts_with?('%PDF')
181 assert @response.body.starts_with?('%PDF')
182 assert_not_nil assigns(:gantt)
182 assert_not_nil assigns(:gantt)
183 end
183 end
184
184
185 def test_cross_project_gantt_export_to_pdf
185 def test_cross_project_gantt_export_to_pdf
186 get :gantt, :format => 'pdf'
186 get :gantt, :format => 'pdf'
187 assert_response :success
187 assert_response :success
188 assert_equal 'application/pdf', @response.content_type
188 assert_equal 'application/pdf', @response.content_type
189 assert @response.body.starts_with?('%PDF')
189 assert @response.body.starts_with?('%PDF')
190 assert_not_nil assigns(:gantt)
190 assert_not_nil assigns(:gantt)
191 end
191 end
192
192
193 if Object.const_defined?(:Magick)
193 if Object.const_defined?(:Magick)
194 def test_gantt_image
194 def test_gantt_image
195 get :gantt, :project_id => 1, :format => 'png'
195 get :gantt, :project_id => 1, :format => 'png'
196 assert_response :success
196 assert_response :success
197 assert_equal 'image/png', @response.content_type
197 assert_equal 'image/png', @response.content_type
198 end
198 end
199 else
199 else
200 puts "RMagick not installed. Skipping tests !!!"
200 puts "RMagick not installed. Skipping tests !!!"
201 end
201 end
202
202
203 def test_calendar
203 def test_calendar
204 get :calendar, :project_id => 1
204 get :calendar, :project_id => 1
205 assert_response :success
205 assert_response :success
206 assert_template 'calendar'
206 assert_template 'calendar'
207 assert_not_nil assigns(:calendar)
207 assert_not_nil assigns(:calendar)
208 end
208 end
209
209
210 def test_cross_project_calendar
210 def test_cross_project_calendar
211 get :calendar
211 get :calendar
212 assert_response :success
212 assert_response :success
213 assert_template 'calendar'
213 assert_template 'calendar'
214 assert_not_nil assigns(:calendar)
214 assert_not_nil assigns(:calendar)
215 end
215 end
216
216
217 def test_changes
217 def test_changes
218 get :changes, :project_id => 1
218 get :changes, :project_id => 1
219 assert_response :success
219 assert_response :success
220 assert_not_nil assigns(:journals)
220 assert_not_nil assigns(:journals)
221 assert_equal 'application/atom+xml', @response.content_type
221 assert_equal 'application/atom+xml', @response.content_type
222 end
222 end
223
223
224 def test_show_by_anonymous
224 def test_show_by_anonymous
225 get :show, :id => 1
225 get :show, :id => 1
226 assert_response :success
226 assert_response :success
227 assert_template 'show.rhtml'
227 assert_template 'show.rhtml'
228 assert_not_nil assigns(:issue)
228 assert_not_nil assigns(:issue)
229 assert_equal Issue.find(1), assigns(:issue)
229 assert_equal Issue.find(1), assigns(:issue)
230
230
231 # anonymous role is allowed to add a note
231 # anonymous role is allowed to add a note
232 assert_tag :tag => 'form',
232 assert_tag :tag => 'form',
233 :descendant => { :tag => 'fieldset',
233 :descendant => { :tag => 'fieldset',
234 :child => { :tag => 'legend',
234 :child => { :tag => 'legend',
235 :content => /Notes/ } }
235 :content => /Notes/ } }
236 end
236 end
237
237
238 def test_show_by_manager
238 def test_show_by_manager
239 @request.session[:user_id] = 2
239 @request.session[:user_id] = 2
240 get :show, :id => 1
240 get :show, :id => 1
241 assert_response :success
241 assert_response :success
242
242
243 assert_tag :tag => 'form',
243 assert_tag :tag => 'form',
244 :descendant => { :tag => 'fieldset',
244 :descendant => { :tag => 'fieldset',
245 :child => { :tag => 'legend',
245 :child => { :tag => 'legend',
246 :content => /Change properties/ } },
246 :content => /Change properties/ } },
247 :descendant => { :tag => 'fieldset',
247 :descendant => { :tag => 'fieldset',
248 :child => { :tag => 'legend',
248 :child => { :tag => 'legend',
249 :content => /Log time/ } },
249 :content => /Log time/ } },
250 :descendant => { :tag => 'fieldset',
250 :descendant => { :tag => 'fieldset',
251 :child => { :tag => 'legend',
251 :child => { :tag => 'legend',
252 :content => /Notes/ } }
252 :content => /Notes/ } }
253 end
253 end
254
254
255 def test_show_export_to_pdf
255 def test_show_export_to_pdf
256 get :show, :id => 1, :format => 'pdf'
256 get :show, :id => 1, :format => 'pdf'
257 assert_response :success
257 assert_response :success
258 assert_equal 'application/pdf', @response.content_type
258 assert_equal 'application/pdf', @response.content_type
259 assert @response.body.starts_with?('%PDF')
259 assert @response.body.starts_with?('%PDF')
260 assert_not_nil assigns(:issue)
260 assert_not_nil assigns(:issue)
261 end
261 end
262
262
263 def test_get_new
263 def test_get_new
264 @request.session[:user_id] = 2
264 @request.session[:user_id] = 2
265 get :new, :project_id => 1, :tracker_id => 1
265 get :new, :project_id => 1, :tracker_id => 1
266 assert_response :success
266 assert_response :success
267 assert_template 'new'
267 assert_template 'new'
268
268
269 assert_tag :tag => 'input', :attributes => { :name => 'issue[custom_field_values][2]',
269 assert_tag :tag => 'input', :attributes => { :name => 'issue[custom_field_values][2]',
270 :value => 'Default string' }
270 :value => 'Default string' }
271 end
271 end
272
272
273 def test_get_new_without_tracker_id
273 def test_get_new_without_tracker_id
274 @request.session[:user_id] = 2
274 @request.session[:user_id] = 2
275 get :new, :project_id => 1
275 get :new, :project_id => 1
276 assert_response :success
276 assert_response :success
277 assert_template 'new'
277 assert_template 'new'
278
278
279 issue = assigns(:issue)
279 issue = assigns(:issue)
280 assert_not_nil issue
280 assert_not_nil issue
281 assert_equal Project.find(1).trackers.first, issue.tracker
281 assert_equal Project.find(1).trackers.first, issue.tracker
282 end
282 end
283
283
284 def test_update_new_form
284 def test_update_new_form
285 @request.session[:user_id] = 2
285 @request.session[:user_id] = 2
286 xhr :post, :new, :project_id => 1,
286 xhr :post, :new, :project_id => 1,
287 :issue => {:tracker_id => 2,
287 :issue => {:tracker_id => 2,
288 :subject => 'This is the test_new issue',
288 :subject => 'This is the test_new issue',
289 :description => 'This is the description',
289 :description => 'This is the description',
290 :priority_id => 5}
290 :priority_id => 5}
291 assert_response :success
291 assert_response :success
292 assert_template 'new'
292 assert_template 'new'
293 end
293 end
294
294
295 def test_post_new
295 def test_post_new
296 @request.session[:user_id] = 2
296 @request.session[:user_id] = 2
297 post :new, :project_id => 1,
297 post :new, :project_id => 1,
298 :issue => {:tracker_id => 3,
298 :issue => {:tracker_id => 3,
299 :subject => 'This is the test_new issue',
299 :subject => 'This is the test_new issue',
300 :description => 'This is the description',
300 :description => 'This is the description',
301 :priority_id => 5,
301 :priority_id => 5,
302 :estimated_hours => '',
302 :estimated_hours => '',
303 :custom_field_values => {'2' => 'Value for field 2'}}
303 :custom_field_values => {'2' => 'Value for field 2'}}
304 assert_redirected_to :controller => 'issues', :action => 'show'
304 assert_redirected_to :controller => 'issues', :action => 'show'
305
305
306 issue = Issue.find_by_subject('This is the test_new issue')
306 issue = Issue.find_by_subject('This is the test_new issue')
307 assert_not_nil issue
307 assert_not_nil issue
308 assert_equal 2, issue.author_id
308 assert_equal 2, issue.author_id
309 assert_equal 3, issue.tracker_id
309 assert_equal 3, issue.tracker_id
310 assert_nil issue.estimated_hours
310 assert_nil issue.estimated_hours
311 v = issue.custom_values.find(:first, :conditions => {:custom_field_id => 2})
311 v = issue.custom_values.find(:first, :conditions => {:custom_field_id => 2})
312 assert_not_nil v
312 assert_not_nil v
313 assert_equal 'Value for field 2', v.value
313 assert_equal 'Value for field 2', v.value
314 end
314 end
315
315
316 def test_post_new_without_custom_fields_param
316 def test_post_new_without_custom_fields_param
317 @request.session[:user_id] = 2
317 @request.session[:user_id] = 2
318 post :new, :project_id => 1,
318 post :new, :project_id => 1,
319 :issue => {:tracker_id => 1,
319 :issue => {:tracker_id => 1,
320 :subject => 'This is the test_new issue',
320 :subject => 'This is the test_new issue',
321 :description => 'This is the description',
321 :description => 'This is the description',
322 :priority_id => 5}
322 :priority_id => 5}
323 assert_redirected_to :controller => 'issues', :action => 'show'
323 assert_redirected_to :controller => 'issues', :action => 'show'
324 end
324 end
325
325
326 def test_post_new_with_required_custom_field_and_without_custom_fields_param
326 def test_post_new_with_required_custom_field_and_without_custom_fields_param
327 field = IssueCustomField.find_by_name('Database')
327 field = IssueCustomField.find_by_name('Database')
328 field.update_attribute(:is_required, true)
328 field.update_attribute(:is_required, true)
329
329
330 @request.session[:user_id] = 2
330 @request.session[:user_id] = 2
331 post :new, :project_id => 1,
331 post :new, :project_id => 1,
332 :issue => {:tracker_id => 1,
332 :issue => {:tracker_id => 1,
333 :subject => 'This is the test_new issue',
333 :subject => 'This is the test_new issue',
334 :description => 'This is the description',
334 :description => 'This is the description',
335 :priority_id => 5}
335 :priority_id => 5}
336 assert_response :success
336 assert_response :success
337 assert_template 'new'
337 assert_template 'new'
338 issue = assigns(:issue)
338 issue = assigns(:issue)
339 assert_not_nil issue
339 assert_not_nil issue
340 assert_equal 'activerecord_error_invalid', issue.errors.on(:custom_values)
340 assert_equal 'activerecord_error_invalid', issue.errors.on(:custom_values)
341 end
341 end
342
342
343 def test_post_new_with_watchers
343 def test_post_new_with_watchers
344 @request.session[:user_id] = 2
344 @request.session[:user_id] = 2
345 ActionMailer::Base.deliveries.clear
345 ActionMailer::Base.deliveries.clear
346
346
347 assert_difference 'Watcher.count', 2 do
347 assert_difference 'Watcher.count', 2 do
348 post :new, :project_id => 1,
348 post :new, :project_id => 1,
349 :issue => {:tracker_id => 1,
349 :issue => {:tracker_id => 1,
350 :subject => 'This is a new issue with watchers',
350 :subject => 'This is a new issue with watchers',
351 :description => 'This is the description',
351 :description => 'This is the description',
352 :priority_id => 5,
352 :priority_id => 5,
353 :watcher_user_ids => ['2', '3']}
353 :watcher_user_ids => ['2', '3']}
354 end
354 end
355 issue = Issue.find_by_subject('This is a new issue with watchers')
355 issue = Issue.find_by_subject('This is a new issue with watchers')
356 assert_not_nil issue
356 assert_not_nil issue
357 assert_redirected_to :controller => 'issues', :action => 'show', :id => issue
357 assert_redirected_to :controller => 'issues', :action => 'show', :id => issue
358
358
359 # Watchers added
359 # Watchers added
360 assert_equal [2, 3], issue.watcher_user_ids.sort
360 assert_equal [2, 3], issue.watcher_user_ids.sort
361 assert issue.watched_by?(User.find(3))
361 assert issue.watched_by?(User.find(3))
362 # Watchers notified
362 # Watchers notified
363 mail = ActionMailer::Base.deliveries.last
363 mail = ActionMailer::Base.deliveries.last
364 assert_kind_of TMail::Mail, mail
364 assert_kind_of TMail::Mail, mail
365 assert [mail.bcc, mail.cc].flatten.include?(User.find(3).mail)
365 assert [mail.bcc, mail.cc].flatten.include?(User.find(3).mail)
366 end
366 end
367
367
368 def test_post_should_preserve_fields_values_on_validation_failure
368 def test_post_should_preserve_fields_values_on_validation_failure
369 @request.session[:user_id] = 2
369 @request.session[:user_id] = 2
370 post :new, :project_id => 1,
370 post :new, :project_id => 1,
371 :issue => {:tracker_id => 1,
371 :issue => {:tracker_id => 1,
372 :subject => 'This is the test_new issue',
372 # empty subject
373 # empty description
373 :subject => '',
374 :description => '',
374 :description => 'This is a description',
375 :priority_id => 6,
375 :priority_id => 6,
376 :custom_field_values => {'1' => 'Oracle', '2' => 'Value for field 2'}}
376 :custom_field_values => {'1' => 'Oracle', '2' => 'Value for field 2'}}
377 assert_response :success
377 assert_response :success
378 assert_template 'new'
378 assert_template 'new'
379
379
380 assert_tag :input, :attributes => { :name => 'issue[subject]',
380 assert_tag :textarea, :attributes => { :name => 'issue[description]' },
381 :value => 'This is the test_new issue' }
381 :content => 'This is a description'
382 assert_tag :select, :attributes => { :name => 'issue[priority_id]' },
382 assert_tag :select, :attributes => { :name => 'issue[priority_id]' },
383 :child => { :tag => 'option', :attributes => { :selected => 'selected',
383 :child => { :tag => 'option', :attributes => { :selected => 'selected',
384 :value => '6' },
384 :value => '6' },
385 :content => 'High' }
385 :content => 'High' }
386 # Custom fields
386 # Custom fields
387 assert_tag :select, :attributes => { :name => 'issue[custom_field_values][1]' },
387 assert_tag :select, :attributes => { :name => 'issue[custom_field_values][1]' },
388 :child => { :tag => 'option', :attributes => { :selected => 'selected',
388 :child => { :tag => 'option', :attributes => { :selected => 'selected',
389 :value => 'Oracle' },
389 :value => 'Oracle' },
390 :content => 'Oracle' }
390 :content => 'Oracle' }
391 assert_tag :input, :attributes => { :name => 'issue[custom_field_values][2]',
391 assert_tag :input, :attributes => { :name => 'issue[custom_field_values][2]',
392 :value => 'Value for field 2'}
392 :value => 'Value for field 2'}
393 end
393 end
394
394
395 def test_copy_issue
395 def test_copy_issue
396 @request.session[:user_id] = 2
396 @request.session[:user_id] = 2
397 get :new, :project_id => 1, :copy_from => 1
397 get :new, :project_id => 1, :copy_from => 1
398 assert_template 'new'
398 assert_template 'new'
399 assert_not_nil assigns(:issue)
399 assert_not_nil assigns(:issue)
400 orig = Issue.find(1)
400 orig = Issue.find(1)
401 assert_equal orig.subject, assigns(:issue).subject
401 assert_equal orig.subject, assigns(:issue).subject
402 end
402 end
403
403
404 def test_get_edit
404 def test_get_edit
405 @request.session[:user_id] = 2
405 @request.session[:user_id] = 2
406 get :edit, :id => 1
406 get :edit, :id => 1
407 assert_response :success
407 assert_response :success
408 assert_template 'edit'
408 assert_template 'edit'
409 assert_not_nil assigns(:issue)
409 assert_not_nil assigns(:issue)
410 assert_equal Issue.find(1), assigns(:issue)
410 assert_equal Issue.find(1), assigns(:issue)
411 end
411 end
412
412
413 def test_get_edit_with_params
413 def test_get_edit_with_params
414 @request.session[:user_id] = 2
414 @request.session[:user_id] = 2
415 get :edit, :id => 1, :issue => { :status_id => 5, :priority_id => 7 }
415 get :edit, :id => 1, :issue => { :status_id => 5, :priority_id => 7 }
416 assert_response :success
416 assert_response :success
417 assert_template 'edit'
417 assert_template 'edit'
418
418
419 issue = assigns(:issue)
419 issue = assigns(:issue)
420 assert_not_nil issue
420 assert_not_nil issue
421
421
422 assert_equal 5, issue.status_id
422 assert_equal 5, issue.status_id
423 assert_tag :select, :attributes => { :name => 'issue[status_id]' },
423 assert_tag :select, :attributes => { :name => 'issue[status_id]' },
424 :child => { :tag => 'option',
424 :child => { :tag => 'option',
425 :content => 'Closed',
425 :content => 'Closed',
426 :attributes => { :selected => 'selected' } }
426 :attributes => { :selected => 'selected' } }
427
427
428 assert_equal 7, issue.priority_id
428 assert_equal 7, issue.priority_id
429 assert_tag :select, :attributes => { :name => 'issue[priority_id]' },
429 assert_tag :select, :attributes => { :name => 'issue[priority_id]' },
430 :child => { :tag => 'option',
430 :child => { :tag => 'option',
431 :content => 'Urgent',
431 :content => 'Urgent',
432 :attributes => { :selected => 'selected' } }
432 :attributes => { :selected => 'selected' } }
433 end
433 end
434
434
435 def test_reply_to_issue
435 def test_reply_to_issue
436 @request.session[:user_id] = 2
436 @request.session[:user_id] = 2
437 get :reply, :id => 1
437 get :reply, :id => 1
438 assert_response :success
438 assert_response :success
439 assert_select_rjs :show, "update"
439 assert_select_rjs :show, "update"
440 end
440 end
441
441
442 def test_reply_to_note
442 def test_reply_to_note
443 @request.session[:user_id] = 2
443 @request.session[:user_id] = 2
444 get :reply, :id => 1, :journal_id => 2
444 get :reply, :id => 1, :journal_id => 2
445 assert_response :success
445 assert_response :success
446 assert_select_rjs :show, "update"
446 assert_select_rjs :show, "update"
447 end
447 end
448
448
449 def test_post_edit_without_custom_fields_param
449 def test_post_edit_without_custom_fields_param
450 @request.session[:user_id] = 2
450 @request.session[:user_id] = 2
451 ActionMailer::Base.deliveries.clear
451 ActionMailer::Base.deliveries.clear
452
452
453 issue = Issue.find(1)
453 issue = Issue.find(1)
454 assert_equal '125', issue.custom_value_for(2).value
454 assert_equal '125', issue.custom_value_for(2).value
455 old_subject = issue.subject
455 old_subject = issue.subject
456 new_subject = 'Subject modified by IssuesControllerTest#test_post_edit'
456 new_subject = 'Subject modified by IssuesControllerTest#test_post_edit'
457
457
458 assert_difference('Journal.count') do
458 assert_difference('Journal.count') do
459 assert_difference('JournalDetail.count', 2) do
459 assert_difference('JournalDetail.count', 2) do
460 post :edit, :id => 1, :issue => {:subject => new_subject,
460 post :edit, :id => 1, :issue => {:subject => new_subject,
461 :priority_id => '6',
461 :priority_id => '6',
462 :category_id => '1' # no change
462 :category_id => '1' # no change
463 }
463 }
464 end
464 end
465 end
465 end
466 assert_redirected_to 'issues/show/1'
466 assert_redirected_to 'issues/show/1'
467 issue.reload
467 issue.reload
468 assert_equal new_subject, issue.subject
468 assert_equal new_subject, issue.subject
469 # Make sure custom fields were not cleared
469 # Make sure custom fields were not cleared
470 assert_equal '125', issue.custom_value_for(2).value
470 assert_equal '125', issue.custom_value_for(2).value
471
471
472 mail = ActionMailer::Base.deliveries.last
472 mail = ActionMailer::Base.deliveries.last
473 assert_kind_of TMail::Mail, mail
473 assert_kind_of TMail::Mail, mail
474 assert mail.subject.starts_with?("[#{issue.project.name} - #{issue.tracker.name} ##{issue.id}]")
474 assert mail.subject.starts_with?("[#{issue.project.name} - #{issue.tracker.name} ##{issue.id}]")
475 assert mail.body.include?("Subject changed from #{old_subject} to #{new_subject}")
475 assert mail.body.include?("Subject changed from #{old_subject} to #{new_subject}")
476 end
476 end
477
477
478 def test_post_edit_with_custom_field_change
478 def test_post_edit_with_custom_field_change
479 @request.session[:user_id] = 2
479 @request.session[:user_id] = 2
480 issue = Issue.find(1)
480 issue = Issue.find(1)
481 assert_equal '125', issue.custom_value_for(2).value
481 assert_equal '125', issue.custom_value_for(2).value
482
482
483 assert_difference('Journal.count') do
483 assert_difference('Journal.count') do
484 assert_difference('JournalDetail.count', 3) do
484 assert_difference('JournalDetail.count', 3) do
485 post :edit, :id => 1, :issue => {:subject => 'Custom field change',
485 post :edit, :id => 1, :issue => {:subject => 'Custom field change',
486 :priority_id => '6',
486 :priority_id => '6',
487 :category_id => '1', # no change
487 :category_id => '1', # no change
488 :custom_field_values => { '2' => 'New custom value' }
488 :custom_field_values => { '2' => 'New custom value' }
489 }
489 }
490 end
490 end
491 end
491 end
492 assert_redirected_to 'issues/show/1'
492 assert_redirected_to 'issues/show/1'
493 issue.reload
493 issue.reload
494 assert_equal 'New custom value', issue.custom_value_for(2).value
494 assert_equal 'New custom value', issue.custom_value_for(2).value
495
495
496 mail = ActionMailer::Base.deliveries.last
496 mail = ActionMailer::Base.deliveries.last
497 assert_kind_of TMail::Mail, mail
497 assert_kind_of TMail::Mail, mail
498 assert mail.body.include?("Searchable field changed from 125 to New custom value")
498 assert mail.body.include?("Searchable field changed from 125 to New custom value")
499 end
499 end
500
500
501 def test_post_edit_with_status_and_assignee_change
501 def test_post_edit_with_status_and_assignee_change
502 issue = Issue.find(1)
502 issue = Issue.find(1)
503 assert_equal 1, issue.status_id
503 assert_equal 1, issue.status_id
504 @request.session[:user_id] = 2
504 @request.session[:user_id] = 2
505 assert_difference('TimeEntry.count', 0) do
505 assert_difference('TimeEntry.count', 0) do
506 post :edit,
506 post :edit,
507 :id => 1,
507 :id => 1,
508 :issue => { :status_id => 2, :assigned_to_id => 3 },
508 :issue => { :status_id => 2, :assigned_to_id => 3 },
509 :notes => 'Assigned to dlopper',
509 :notes => 'Assigned to dlopper',
510 :time_entry => { :hours => '', :comments => '', :activity_id => Enumeration.get_values('ACTI').first }
510 :time_entry => { :hours => '', :comments => '', :activity_id => Enumeration.get_values('ACTI').first }
511 end
511 end
512 assert_redirected_to 'issues/show/1'
512 assert_redirected_to 'issues/show/1'
513 issue.reload
513 issue.reload
514 assert_equal 2, issue.status_id
514 assert_equal 2, issue.status_id
515 j = issue.journals.find(:first, :order => 'id DESC')
515 j = issue.journals.find(:first, :order => 'id DESC')
516 assert_equal 'Assigned to dlopper', j.notes
516 assert_equal 'Assigned to dlopper', j.notes
517 assert_equal 2, j.details.size
517 assert_equal 2, j.details.size
518
518
519 mail = ActionMailer::Base.deliveries.last
519 mail = ActionMailer::Base.deliveries.last
520 assert mail.body.include?("Status changed from New to Assigned")
520 assert mail.body.include?("Status changed from New to Assigned")
521 end
521 end
522
522
523 def test_post_edit_with_note_only
523 def test_post_edit_with_note_only
524 notes = 'Note added by IssuesControllerTest#test_update_with_note_only'
524 notes = 'Note added by IssuesControllerTest#test_update_with_note_only'
525 # anonymous user
525 # anonymous user
526 post :edit,
526 post :edit,
527 :id => 1,
527 :id => 1,
528 :notes => notes
528 :notes => notes
529 assert_redirected_to 'issues/show/1'
529 assert_redirected_to 'issues/show/1'
530 j = Issue.find(1).journals.find(:first, :order => 'id DESC')
530 j = Issue.find(1).journals.find(:first, :order => 'id DESC')
531 assert_equal notes, j.notes
531 assert_equal notes, j.notes
532 assert_equal 0, j.details.size
532 assert_equal 0, j.details.size
533 assert_equal User.anonymous, j.user
533 assert_equal User.anonymous, j.user
534
534
535 mail = ActionMailer::Base.deliveries.last
535 mail = ActionMailer::Base.deliveries.last
536 assert mail.body.include?(notes)
536 assert mail.body.include?(notes)
537 end
537 end
538
538
539 def test_post_edit_with_note_and_spent_time
539 def test_post_edit_with_note_and_spent_time
540 @request.session[:user_id] = 2
540 @request.session[:user_id] = 2
541 spent_hours_before = Issue.find(1).spent_hours
541 spent_hours_before = Issue.find(1).spent_hours
542 assert_difference('TimeEntry.count') do
542 assert_difference('TimeEntry.count') do
543 post :edit,
543 post :edit,
544 :id => 1,
544 :id => 1,
545 :notes => '2.5 hours added',
545 :notes => '2.5 hours added',
546 :time_entry => { :hours => '2.5', :comments => '', :activity_id => Enumeration.get_values('ACTI').first }
546 :time_entry => { :hours => '2.5', :comments => '', :activity_id => Enumeration.get_values('ACTI').first }
547 end
547 end
548 assert_redirected_to 'issues/show/1'
548 assert_redirected_to 'issues/show/1'
549
549
550 issue = Issue.find(1)
550 issue = Issue.find(1)
551
551
552 j = issue.journals.find(:first, :order => 'id DESC')
552 j = issue.journals.find(:first, :order => 'id DESC')
553 assert_equal '2.5 hours added', j.notes
553 assert_equal '2.5 hours added', j.notes
554 assert_equal 0, j.details.size
554 assert_equal 0, j.details.size
555
555
556 t = issue.time_entries.find(:first, :order => 'id DESC')
556 t = issue.time_entries.find(:first, :order => 'id DESC')
557 assert_not_nil t
557 assert_not_nil t
558 assert_equal 2.5, t.hours
558 assert_equal 2.5, t.hours
559 assert_equal spent_hours_before + 2.5, issue.spent_hours
559 assert_equal spent_hours_before + 2.5, issue.spent_hours
560 end
560 end
561
561
562 def test_post_edit_with_attachment_only
562 def test_post_edit_with_attachment_only
563 set_tmp_attachments_directory
563 set_tmp_attachments_directory
564
564
565 # Delete all fixtured journals, a race condition can occur causing the wrong
565 # Delete all fixtured journals, a race condition can occur causing the wrong
566 # journal to get fetched in the next find.
566 # journal to get fetched in the next find.
567 Journal.delete_all
567 Journal.delete_all
568
568
569 # anonymous user
569 # anonymous user
570 post :edit,
570 post :edit,
571 :id => 1,
571 :id => 1,
572 :notes => '',
572 :notes => '',
573 :attachments => {'1' => {'file' => test_uploaded_file('testfile.txt', 'text/plain')}}
573 :attachments => {'1' => {'file' => test_uploaded_file('testfile.txt', 'text/plain')}}
574 assert_redirected_to 'issues/show/1'
574 assert_redirected_to 'issues/show/1'
575 j = Issue.find(1).journals.find(:first, :order => 'id DESC')
575 j = Issue.find(1).journals.find(:first, :order => 'id DESC')
576 assert j.notes.blank?
576 assert j.notes.blank?
577 assert_equal 1, j.details.size
577 assert_equal 1, j.details.size
578 assert_equal 'testfile.txt', j.details.first.value
578 assert_equal 'testfile.txt', j.details.first.value
579 assert_equal User.anonymous, j.user
579 assert_equal User.anonymous, j.user
580
580
581 mail = ActionMailer::Base.deliveries.last
581 mail = ActionMailer::Base.deliveries.last
582 assert mail.body.include?('testfile.txt')
582 assert mail.body.include?('testfile.txt')
583 end
583 end
584
584
585 def test_post_edit_with_no_change
585 def test_post_edit_with_no_change
586 issue = Issue.find(1)
586 issue = Issue.find(1)
587 issue.journals.clear
587 issue.journals.clear
588 ActionMailer::Base.deliveries.clear
588 ActionMailer::Base.deliveries.clear
589
589
590 post :edit,
590 post :edit,
591 :id => 1,
591 :id => 1,
592 :notes => ''
592 :notes => ''
593 assert_redirected_to 'issues/show/1'
593 assert_redirected_to 'issues/show/1'
594
594
595 issue.reload
595 issue.reload
596 assert issue.journals.empty?
596 assert issue.journals.empty?
597 # No email should be sent
597 # No email should be sent
598 assert ActionMailer::Base.deliveries.empty?
598 assert ActionMailer::Base.deliveries.empty?
599 end
599 end
600
600
601 def test_bulk_edit
601 def test_bulk_edit
602 @request.session[:user_id] = 2
602 @request.session[:user_id] = 2
603 # update issues priority
603 # update issues priority
604 post :bulk_edit, :ids => [1, 2], :priority_id => 7, :notes => 'Bulk editing', :assigned_to_id => ''
604 post :bulk_edit, :ids => [1, 2], :priority_id => 7, :notes => 'Bulk editing', :assigned_to_id => ''
605 assert_response 302
605 assert_response 302
606 # check that the issues were updated
606 # check that the issues were updated
607 assert_equal [7, 7], Issue.find_all_by_id([1, 2]).collect {|i| i.priority.id}
607 assert_equal [7, 7], Issue.find_all_by_id([1, 2]).collect {|i| i.priority.id}
608 assert_equal 'Bulk editing', Issue.find(1).journals.find(:first, :order => 'created_on DESC').notes
608 assert_equal 'Bulk editing', Issue.find(1).journals.find(:first, :order => 'created_on DESC').notes
609 end
609 end
610
610
611 def test_bulk_unassign
611 def test_bulk_unassign
612 assert_not_nil Issue.find(2).assigned_to
612 assert_not_nil Issue.find(2).assigned_to
613 @request.session[:user_id] = 2
613 @request.session[:user_id] = 2
614 # unassign issues
614 # unassign issues
615 post :bulk_edit, :ids => [1, 2], :notes => 'Bulk unassigning', :assigned_to_id => 'none'
615 post :bulk_edit, :ids => [1, 2], :notes => 'Bulk unassigning', :assigned_to_id => 'none'
616 assert_response 302
616 assert_response 302
617 # check that the issues were updated
617 # check that the issues were updated
618 assert_nil Issue.find(2).assigned_to
618 assert_nil Issue.find(2).assigned_to
619 end
619 end
620
620
621 def test_move_one_issue_to_another_project
621 def test_move_one_issue_to_another_project
622 @request.session[:user_id] = 1
622 @request.session[:user_id] = 1
623 post :move, :id => 1, :new_project_id => 2
623 post :move, :id => 1, :new_project_id => 2
624 assert_redirected_to 'projects/ecookbook/issues'
624 assert_redirected_to 'projects/ecookbook/issues'
625 assert_equal 2, Issue.find(1).project_id
625 assert_equal 2, Issue.find(1).project_id
626 end
626 end
627
627
628 def test_bulk_move_to_another_project
628 def test_bulk_move_to_another_project
629 @request.session[:user_id] = 1
629 @request.session[:user_id] = 1
630 post :move, :ids => [1, 2], :new_project_id => 2
630 post :move, :ids => [1, 2], :new_project_id => 2
631 assert_redirected_to 'projects/ecookbook/issues'
631 assert_redirected_to 'projects/ecookbook/issues'
632 # Issues moved to project 2
632 # Issues moved to project 2
633 assert_equal 2, Issue.find(1).project_id
633 assert_equal 2, Issue.find(1).project_id
634 assert_equal 2, Issue.find(2).project_id
634 assert_equal 2, Issue.find(2).project_id
635 # No tracker change
635 # No tracker change
636 assert_equal 1, Issue.find(1).tracker_id
636 assert_equal 1, Issue.find(1).tracker_id
637 assert_equal 2, Issue.find(2).tracker_id
637 assert_equal 2, Issue.find(2).tracker_id
638 end
638 end
639
639
640 def test_bulk_move_to_another_tracker
640 def test_bulk_move_to_another_tracker
641 @request.session[:user_id] = 1
641 @request.session[:user_id] = 1
642 post :move, :ids => [1, 2], :new_tracker_id => 2
642 post :move, :ids => [1, 2], :new_tracker_id => 2
643 assert_redirected_to 'projects/ecookbook/issues'
643 assert_redirected_to 'projects/ecookbook/issues'
644 assert_equal 2, Issue.find(1).tracker_id
644 assert_equal 2, Issue.find(1).tracker_id
645 assert_equal 2, Issue.find(2).tracker_id
645 assert_equal 2, Issue.find(2).tracker_id
646 end
646 end
647
647
648 def test_context_menu_one_issue
648 def test_context_menu_one_issue
649 @request.session[:user_id] = 2
649 @request.session[:user_id] = 2
650 get :context_menu, :ids => [1]
650 get :context_menu, :ids => [1]
651 assert_response :success
651 assert_response :success
652 assert_template 'context_menu'
652 assert_template 'context_menu'
653 assert_tag :tag => 'a', :content => 'Edit',
653 assert_tag :tag => 'a', :content => 'Edit',
654 :attributes => { :href => '/issues/edit/1',
654 :attributes => { :href => '/issues/edit/1',
655 :class => 'icon-edit' }
655 :class => 'icon-edit' }
656 assert_tag :tag => 'a', :content => 'Closed',
656 assert_tag :tag => 'a', :content => 'Closed',
657 :attributes => { :href => '/issues/edit/1?issue%5Bstatus_id%5D=5',
657 :attributes => { :href => '/issues/edit/1?issue%5Bstatus_id%5D=5',
658 :class => '' }
658 :class => '' }
659 assert_tag :tag => 'a', :content => 'Immediate',
659 assert_tag :tag => 'a', :content => 'Immediate',
660 :attributes => { :href => '/issues/bulk_edit?ids%5B%5D=1&amp;priority_id=8',
660 :attributes => { :href => '/issues/bulk_edit?ids%5B%5D=1&amp;priority_id=8',
661 :class => '' }
661 :class => '' }
662 assert_tag :tag => 'a', :content => 'Dave Lopper',
662 assert_tag :tag => 'a', :content => 'Dave Lopper',
663 :attributes => { :href => '/issues/bulk_edit?assigned_to_id=3&amp;ids%5B%5D=1',
663 :attributes => { :href => '/issues/bulk_edit?assigned_to_id=3&amp;ids%5B%5D=1',
664 :class => '' }
664 :class => '' }
665 assert_tag :tag => 'a', :content => 'Copy',
665 assert_tag :tag => 'a', :content => 'Copy',
666 :attributes => { :href => '/projects/ecookbook/issues/new?copy_from=1',
666 :attributes => { :href => '/projects/ecookbook/issues/new?copy_from=1',
667 :class => 'icon-copy' }
667 :class => 'icon-copy' }
668 assert_tag :tag => 'a', :content => 'Move',
668 assert_tag :tag => 'a', :content => 'Move',
669 :attributes => { :href => '/issues/move?ids%5B%5D=1',
669 :attributes => { :href => '/issues/move?ids%5B%5D=1',
670 :class => 'icon-move' }
670 :class => 'icon-move' }
671 assert_tag :tag => 'a', :content => 'Delete',
671 assert_tag :tag => 'a', :content => 'Delete',
672 :attributes => { :href => '/issues/destroy?ids%5B%5D=1',
672 :attributes => { :href => '/issues/destroy?ids%5B%5D=1',
673 :class => 'icon-del' }
673 :class => 'icon-del' }
674 end
674 end
675
675
676 def test_context_menu_one_issue_by_anonymous
676 def test_context_menu_one_issue_by_anonymous
677 get :context_menu, :ids => [1]
677 get :context_menu, :ids => [1]
678 assert_response :success
678 assert_response :success
679 assert_template 'context_menu'
679 assert_template 'context_menu'
680 assert_tag :tag => 'a', :content => 'Delete',
680 assert_tag :tag => 'a', :content => 'Delete',
681 :attributes => { :href => '#',
681 :attributes => { :href => '#',
682 :class => 'icon-del disabled' }
682 :class => 'icon-del disabled' }
683 end
683 end
684
684
685 def test_context_menu_multiple_issues_of_same_project
685 def test_context_menu_multiple_issues_of_same_project
686 @request.session[:user_id] = 2
686 @request.session[:user_id] = 2
687 get :context_menu, :ids => [1, 2]
687 get :context_menu, :ids => [1, 2]
688 assert_response :success
688 assert_response :success
689 assert_template 'context_menu'
689 assert_template 'context_menu'
690 assert_tag :tag => 'a', :content => 'Edit',
690 assert_tag :tag => 'a', :content => 'Edit',
691 :attributes => { :href => '/issues/bulk_edit?ids%5B%5D=1&amp;ids%5B%5D=2',
691 :attributes => { :href => '/issues/bulk_edit?ids%5B%5D=1&amp;ids%5B%5D=2',
692 :class => 'icon-edit' }
692 :class => 'icon-edit' }
693 assert_tag :tag => 'a', :content => 'Immediate',
693 assert_tag :tag => 'a', :content => 'Immediate',
694 :attributes => { :href => '/issues/bulk_edit?ids%5B%5D=1&amp;ids%5B%5D=2&amp;priority_id=8',
694 :attributes => { :href => '/issues/bulk_edit?ids%5B%5D=1&amp;ids%5B%5D=2&amp;priority_id=8',
695 :class => '' }
695 :class => '' }
696 assert_tag :tag => 'a', :content => 'Dave Lopper',
696 assert_tag :tag => 'a', :content => 'Dave Lopper',
697 :attributes => { :href => '/issues/bulk_edit?assigned_to_id=3&amp;ids%5B%5D=1&amp;ids%5B%5D=2',
697 :attributes => { :href => '/issues/bulk_edit?assigned_to_id=3&amp;ids%5B%5D=1&amp;ids%5B%5D=2',
698 :class => '' }
698 :class => '' }
699 assert_tag :tag => 'a', :content => 'Move',
699 assert_tag :tag => 'a', :content => 'Move',
700 :attributes => { :href => '/issues/move?ids%5B%5D=1&amp;ids%5B%5D=2',
700 :attributes => { :href => '/issues/move?ids%5B%5D=1&amp;ids%5B%5D=2',
701 :class => 'icon-move' }
701 :class => 'icon-move' }
702 assert_tag :tag => 'a', :content => 'Delete',
702 assert_tag :tag => 'a', :content => 'Delete',
703 :attributes => { :href => '/issues/destroy?ids%5B%5D=1&amp;ids%5B%5D=2',
703 :attributes => { :href => '/issues/destroy?ids%5B%5D=1&amp;ids%5B%5D=2',
704 :class => 'icon-del' }
704 :class => 'icon-del' }
705 end
705 end
706
706
707 def test_context_menu_multiple_issues_of_different_project
707 def test_context_menu_multiple_issues_of_different_project
708 @request.session[:user_id] = 2
708 @request.session[:user_id] = 2
709 get :context_menu, :ids => [1, 2, 4]
709 get :context_menu, :ids => [1, 2, 4]
710 assert_response :success
710 assert_response :success
711 assert_template 'context_menu'
711 assert_template 'context_menu'
712 assert_tag :tag => 'a', :content => 'Delete',
712 assert_tag :tag => 'a', :content => 'Delete',
713 :attributes => { :href => '#',
713 :attributes => { :href => '#',
714 :class => 'icon-del disabled' }
714 :class => 'icon-del disabled' }
715 end
715 end
716
716
717 def test_destroy_issue_with_no_time_entries
717 def test_destroy_issue_with_no_time_entries
718 assert_nil TimeEntry.find_by_issue_id(2)
718 assert_nil TimeEntry.find_by_issue_id(2)
719 @request.session[:user_id] = 2
719 @request.session[:user_id] = 2
720 post :destroy, :id => 2
720 post :destroy, :id => 2
721 assert_redirected_to 'projects/ecookbook/issues'
721 assert_redirected_to 'projects/ecookbook/issues'
722 assert_nil Issue.find_by_id(2)
722 assert_nil Issue.find_by_id(2)
723 end
723 end
724
724
725 def test_destroy_issues_with_time_entries
725 def test_destroy_issues_with_time_entries
726 @request.session[:user_id] = 2
726 @request.session[:user_id] = 2
727 post :destroy, :ids => [1, 3]
727 post :destroy, :ids => [1, 3]
728 assert_response :success
728 assert_response :success
729 assert_template 'destroy'
729 assert_template 'destroy'
730 assert_not_nil assigns(:hours)
730 assert_not_nil assigns(:hours)
731 assert Issue.find_by_id(1) && Issue.find_by_id(3)
731 assert Issue.find_by_id(1) && Issue.find_by_id(3)
732 end
732 end
733
733
734 def test_destroy_issues_and_destroy_time_entries
734 def test_destroy_issues_and_destroy_time_entries
735 @request.session[:user_id] = 2
735 @request.session[:user_id] = 2
736 post :destroy, :ids => [1, 3], :todo => 'destroy'
736 post :destroy, :ids => [1, 3], :todo => 'destroy'
737 assert_redirected_to 'projects/ecookbook/issues'
737 assert_redirected_to 'projects/ecookbook/issues'
738 assert !(Issue.find_by_id(1) || Issue.find_by_id(3))
738 assert !(Issue.find_by_id(1) || Issue.find_by_id(3))
739 assert_nil TimeEntry.find_by_id([1, 2])
739 assert_nil TimeEntry.find_by_id([1, 2])
740 end
740 end
741
741
742 def test_destroy_issues_and_assign_time_entries_to_project
742 def test_destroy_issues_and_assign_time_entries_to_project
743 @request.session[:user_id] = 2
743 @request.session[:user_id] = 2
744 post :destroy, :ids => [1, 3], :todo => 'nullify'
744 post :destroy, :ids => [1, 3], :todo => 'nullify'
745 assert_redirected_to 'projects/ecookbook/issues'
745 assert_redirected_to 'projects/ecookbook/issues'
746 assert !(Issue.find_by_id(1) || Issue.find_by_id(3))
746 assert !(Issue.find_by_id(1) || Issue.find_by_id(3))
747 assert_nil TimeEntry.find(1).issue_id
747 assert_nil TimeEntry.find(1).issue_id
748 assert_nil TimeEntry.find(2).issue_id
748 assert_nil TimeEntry.find(2).issue_id
749 end
749 end
750
750
751 def test_destroy_issues_and_reassign_time_entries_to_another_issue
751 def test_destroy_issues_and_reassign_time_entries_to_another_issue
752 @request.session[:user_id] = 2
752 @request.session[:user_id] = 2
753 post :destroy, :ids => [1, 3], :todo => 'reassign', :reassign_to_id => 2
753 post :destroy, :ids => [1, 3], :todo => 'reassign', :reassign_to_id => 2
754 assert_redirected_to 'projects/ecookbook/issues'
754 assert_redirected_to 'projects/ecookbook/issues'
755 assert !(Issue.find_by_id(1) || Issue.find_by_id(3))
755 assert !(Issue.find_by_id(1) || Issue.find_by_id(3))
756 assert_equal 2, TimeEntry.find(1).issue_id
756 assert_equal 2, TimeEntry.find(1).issue_id
757 assert_equal 2, TimeEntry.find(2).issue_id
757 assert_equal 2, TimeEntry.find(2).issue_id
758 end
758 end
759 end
759 end
General Comments 0
You need to be logged in to leave comments. Login now