##// END OF EJS Templates
Fixes functional tests broken by r1501....
Jean-Philippe Lang -
r1490:383da1e6d610
parent child
Show More
@@ -1,561 +1,561
1 # redMine - project management software
1 # redMine - project management software
2 # Copyright (C) 2006-2007 Jean-Philippe Lang
2 # Copyright (C) 2006-2007 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 :trackers,
31 :trackers,
32 :projects_trackers,
32 :projects_trackers,
33 :issue_categories,
33 :issue_categories,
34 :enabled_modules,
34 :enabled_modules,
35 :enumerations,
35 :enumerations,
36 :attachments,
36 :attachments,
37 :workflows,
37 :workflows,
38 :custom_fields,
38 :custom_fields,
39 :custom_values,
39 :custom_values,
40 :custom_fields_trackers,
40 :custom_fields_trackers,
41 :time_entries
41 :time_entries,
42 :journals,
43 :journal_details
42
44
43 def setup
45 def setup
44 @controller = IssuesController.new
46 @controller = IssuesController.new
45 @request = ActionController::TestRequest.new
47 @request = ActionController::TestRequest.new
46 @response = ActionController::TestResponse.new
48 @response = ActionController::TestResponse.new
47 User.current = nil
49 User.current = nil
48 end
50 end
49
51
50 def test_index
52 def test_index
51 get :index
53 get :index
52 assert_response :success
54 assert_response :success
53 assert_template 'index.rhtml'
55 assert_template 'index.rhtml'
54 assert_not_nil assigns(:issues)
56 assert_not_nil assigns(:issues)
55 assert_nil assigns(:project)
57 assert_nil assigns(:project)
56 assert_tag :tag => 'a', :content => /Can't print recipes/
58 assert_tag :tag => 'a', :content => /Can't print recipes/
57 assert_tag :tag => 'a', :content => /Subproject issue/
59 assert_tag :tag => 'a', :content => /Subproject issue/
58 # private projects hidden
60 # private projects hidden
59 assert_no_tag :tag => 'a', :content => /Issue of a private subproject/
61 assert_no_tag :tag => 'a', :content => /Issue of a private subproject/
60 assert_no_tag :tag => 'a', :content => /Issue on project 2/
62 assert_no_tag :tag => 'a', :content => /Issue on project 2/
61 end
63 end
62
64
63 def test_index_with_project
65 def test_index_with_project
64 Setting.display_subprojects_issues = 0
66 Setting.display_subprojects_issues = 0
65 get :index, :project_id => 1
67 get :index, :project_id => 1
66 assert_response :success
68 assert_response :success
67 assert_template 'index.rhtml'
69 assert_template 'index.rhtml'
68 assert_not_nil assigns(:issues)
70 assert_not_nil assigns(:issues)
69 assert_tag :tag => 'a', :content => /Can't print recipes/
71 assert_tag :tag => 'a', :content => /Can't print recipes/
70 assert_no_tag :tag => 'a', :content => /Subproject issue/
72 assert_no_tag :tag => 'a', :content => /Subproject issue/
71 end
73 end
72
74
73 def test_index_with_project_and_subprojects
75 def test_index_with_project_and_subprojects
74 Setting.display_subprojects_issues = 1
76 Setting.display_subprojects_issues = 1
75 get :index, :project_id => 1
77 get :index, :project_id => 1
76 assert_response :success
78 assert_response :success
77 assert_template 'index.rhtml'
79 assert_template 'index.rhtml'
78 assert_not_nil assigns(:issues)
80 assert_not_nil assigns(:issues)
79 assert_tag :tag => 'a', :content => /Can't print recipes/
81 assert_tag :tag => 'a', :content => /Can't print recipes/
80 assert_tag :tag => 'a', :content => /Subproject issue/
82 assert_tag :tag => 'a', :content => /Subproject issue/
81 assert_no_tag :tag => 'a', :content => /Issue of a private subproject/
83 assert_no_tag :tag => 'a', :content => /Issue of a private subproject/
82 end
84 end
83
85
84 def test_index_with_project_and_subprojects_should_show_private_subprojects
86 def test_index_with_project_and_subprojects_should_show_private_subprojects
85 @request.session[:user_id] = 2
87 @request.session[:user_id] = 2
86 Setting.display_subprojects_issues = 1
88 Setting.display_subprojects_issues = 1
87 get :index, :project_id => 1
89 get :index, :project_id => 1
88 assert_response :success
90 assert_response :success
89 assert_template 'index.rhtml'
91 assert_template 'index.rhtml'
90 assert_not_nil assigns(:issues)
92 assert_not_nil assigns(:issues)
91 assert_tag :tag => 'a', :content => /Can't print recipes/
93 assert_tag :tag => 'a', :content => /Can't print recipes/
92 assert_tag :tag => 'a', :content => /Subproject issue/
94 assert_tag :tag => 'a', :content => /Subproject issue/
93 assert_tag :tag => 'a', :content => /Issue of a private subproject/
95 assert_tag :tag => 'a', :content => /Issue of a private subproject/
94 end
96 end
95
97
96 def test_index_with_project_and_filter
98 def test_index_with_project_and_filter
97 get :index, :project_id => 1, :set_filter => 1
99 get :index, :project_id => 1, :set_filter => 1
98 assert_response :success
100 assert_response :success
99 assert_template 'index.rhtml'
101 assert_template 'index.rhtml'
100 assert_not_nil assigns(:issues)
102 assert_not_nil assigns(:issues)
101 end
103 end
102
104
103 def test_index_csv_with_project
105 def test_index_csv_with_project
104 get :index, :format => 'csv'
106 get :index, :format => 'csv'
105 assert_response :success
107 assert_response :success
106 assert_not_nil assigns(:issues)
108 assert_not_nil assigns(:issues)
107 assert_equal 'text/csv', @response.content_type
109 assert_equal 'text/csv', @response.content_type
108
110
109 get :index, :project_id => 1, :format => 'csv'
111 get :index, :project_id => 1, :format => 'csv'
110 assert_response :success
112 assert_response :success
111 assert_not_nil assigns(:issues)
113 assert_not_nil assigns(:issues)
112 assert_equal 'text/csv', @response.content_type
114 assert_equal 'text/csv', @response.content_type
113 end
115 end
114
116
115 def test_index_pdf
117 def test_index_pdf
116 get :index, :format => 'pdf'
118 get :index, :format => 'pdf'
117 assert_response :success
119 assert_response :success
118 assert_not_nil assigns(:issues)
120 assert_not_nil assigns(:issues)
119 assert_equal 'application/pdf', @response.content_type
121 assert_equal 'application/pdf', @response.content_type
120
122
121 get :index, :project_id => 1, :format => 'pdf'
123 get :index, :project_id => 1, :format => 'pdf'
122 assert_response :success
124 assert_response :success
123 assert_not_nil assigns(:issues)
125 assert_not_nil assigns(:issues)
124 assert_equal 'application/pdf', @response.content_type
126 assert_equal 'application/pdf', @response.content_type
125 end
127 end
126
128
127 def test_changes
129 def test_changes
128 get :changes, :project_id => 1
130 get :changes, :project_id => 1
129 assert_response :success
131 assert_response :success
130 assert_not_nil assigns(:journals)
132 assert_not_nil assigns(:journals)
131 assert_equal 'application/atom+xml', @response.content_type
133 assert_equal 'application/atom+xml', @response.content_type
132 end
134 end
133
135
134 def test_show_by_anonymous
136 def test_show_by_anonymous
135 get :show, :id => 1
137 get :show, :id => 1
136 assert_response :success
138 assert_response :success
137 assert_template 'show.rhtml'
139 assert_template 'show.rhtml'
138 assert_not_nil assigns(:issue)
140 assert_not_nil assigns(:issue)
139 assert_equal Issue.find(1), assigns(:issue)
141 assert_equal Issue.find(1), assigns(:issue)
140
142
141 # anonymous role is allowed to add a note
143 # anonymous role is allowed to add a note
142 assert_tag :tag => 'form',
144 assert_tag :tag => 'form',
143 :descendant => { :tag => 'fieldset',
145 :descendant => { :tag => 'fieldset',
144 :child => { :tag => 'legend',
146 :child => { :tag => 'legend',
145 :content => /Notes/ } }
147 :content => /Notes/ } }
146 end
148 end
147
149
148 def test_show_by_manager
150 def test_show_by_manager
149 @request.session[:user_id] = 2
151 @request.session[:user_id] = 2
150 get :show, :id => 1
152 get :show, :id => 1
151 assert_response :success
153 assert_response :success
152
154
153 assert_tag :tag => 'form',
155 assert_tag :tag => 'form',
154 :descendant => { :tag => 'fieldset',
156 :descendant => { :tag => 'fieldset',
155 :child => { :tag => 'legend',
157 :child => { :tag => 'legend',
156 :content => /Change properties/ } },
158 :content => /Change properties/ } },
157 :descendant => { :tag => 'fieldset',
159 :descendant => { :tag => 'fieldset',
158 :child => { :tag => 'legend',
160 :child => { :tag => 'legend',
159 :content => /Log time/ } },
161 :content => /Log time/ } },
160 :descendant => { :tag => 'fieldset',
162 :descendant => { :tag => 'fieldset',
161 :child => { :tag => 'legend',
163 :child => { :tag => 'legend',
162 :content => /Notes/ } }
164 :content => /Notes/ } }
163 end
165 end
164
166
165 def test_get_new
167 def test_get_new
166 @request.session[:user_id] = 2
168 @request.session[:user_id] = 2
167 get :new, :project_id => 1, :tracker_id => 1
169 get :new, :project_id => 1, :tracker_id => 1
168 assert_response :success
170 assert_response :success
169 assert_template 'new'
171 assert_template 'new'
170
172
171 assert_tag :tag => 'input', :attributes => { :name => 'custom_fields[2]',
173 assert_tag :tag => 'input', :attributes => { :name => 'custom_fields[2]',
172 :value => 'Default string' }
174 :value => 'Default string' }
173 end
175 end
174
176
175 def test_get_new_without_tracker_id
177 def test_get_new_without_tracker_id
176 @request.session[:user_id] = 2
178 @request.session[:user_id] = 2
177 get :new, :project_id => 1
179 get :new, :project_id => 1
178 assert_response :success
180 assert_response :success
179 assert_template 'new'
181 assert_template 'new'
180
182
181 issue = assigns(:issue)
183 issue = assigns(:issue)
182 assert_not_nil issue
184 assert_not_nil issue
183 assert_equal Project.find(1).trackers.first, issue.tracker
185 assert_equal Project.find(1).trackers.first, issue.tracker
184 end
186 end
185
187
186 def test_update_new_form
188 def test_update_new_form
187 @request.session[:user_id] = 2
189 @request.session[:user_id] = 2
188 xhr :post, :new, :project_id => 1,
190 xhr :post, :new, :project_id => 1,
189 :issue => {:tracker_id => 2,
191 :issue => {:tracker_id => 2,
190 :subject => 'This is the test_new issue',
192 :subject => 'This is the test_new issue',
191 :description => 'This is the description',
193 :description => 'This is the description',
192 :priority_id => 5}
194 :priority_id => 5}
193 assert_response :success
195 assert_response :success
194 assert_template 'new'
196 assert_template 'new'
195 end
197 end
196
198
197 def test_post_new
199 def test_post_new
198 @request.session[:user_id] = 2
200 @request.session[:user_id] = 2
199 post :new, :project_id => 1,
201 post :new, :project_id => 1,
200 :issue => {:tracker_id => 1,
202 :issue => {:tracker_id => 1,
201 :subject => 'This is the test_new issue',
203 :subject => 'This is the test_new issue',
202 :description => 'This is the description',
204 :description => 'This is the description',
203 :priority_id => 5,
205 :priority_id => 5,
204 :estimated_hours => ''},
206 :estimated_hours => ''},
205 :custom_fields => {'2' => 'Value for field 2'}
207 :custom_fields => {'2' => 'Value for field 2'}
206 assert_redirected_to 'issues/show'
208 assert_redirected_to 'issues/show'
207
209
208 issue = Issue.find_by_subject('This is the test_new issue')
210 issue = Issue.find_by_subject('This is the test_new issue')
209 assert_not_nil issue
211 assert_not_nil issue
210 assert_equal 2, issue.author_id
212 assert_equal 2, issue.author_id
211 assert_nil issue.estimated_hours
213 assert_nil issue.estimated_hours
212 v = issue.custom_values.find_by_custom_field_id(2)
214 v = issue.custom_values.find_by_custom_field_id(2)
213 assert_not_nil v
215 assert_not_nil v
214 assert_equal 'Value for field 2', v.value
216 assert_equal 'Value for field 2', v.value
215 end
217 end
216
218
217 def test_post_new_without_custom_fields_param
219 def test_post_new_without_custom_fields_param
218 @request.session[:user_id] = 2
220 @request.session[:user_id] = 2
219 post :new, :project_id => 1,
221 post :new, :project_id => 1,
220 :issue => {:tracker_id => 1,
222 :issue => {:tracker_id => 1,
221 :subject => 'This is the test_new issue',
223 :subject => 'This is the test_new issue',
222 :description => 'This is the description',
224 :description => 'This is the description',
223 :priority_id => 5}
225 :priority_id => 5}
224 assert_redirected_to 'issues/show'
226 assert_redirected_to 'issues/show'
225 end
227 end
226
228
227 def test_copy_issue
229 def test_copy_issue
228 @request.session[:user_id] = 2
230 @request.session[:user_id] = 2
229 get :new, :project_id => 1, :copy_from => 1
231 get :new, :project_id => 1, :copy_from => 1
230 assert_template 'new'
232 assert_template 'new'
231 assert_not_nil assigns(:issue)
233 assert_not_nil assigns(:issue)
232 orig = Issue.find(1)
234 orig = Issue.find(1)
233 assert_equal orig.subject, assigns(:issue).subject
235 assert_equal orig.subject, assigns(:issue).subject
234 end
236 end
235
237
236 def test_get_edit
238 def test_get_edit
237 @request.session[:user_id] = 2
239 @request.session[:user_id] = 2
238 get :edit, :id => 1
240 get :edit, :id => 1
239 assert_response :success
241 assert_response :success
240 assert_template 'edit'
242 assert_template 'edit'
241 assert_not_nil assigns(:issue)
243 assert_not_nil assigns(:issue)
242 assert_equal Issue.find(1), assigns(:issue)
244 assert_equal Issue.find(1), assigns(:issue)
243 end
245 end
244
246
245 def test_get_edit_with_params
247 def test_get_edit_with_params
246 @request.session[:user_id] = 2
248 @request.session[:user_id] = 2
247 get :edit, :id => 1, :issue => { :status_id => 5, :priority_id => 7 }
249 get :edit, :id => 1, :issue => { :status_id => 5, :priority_id => 7 }
248 assert_response :success
250 assert_response :success
249 assert_template 'edit'
251 assert_template 'edit'
250
252
251 issue = assigns(:issue)
253 issue = assigns(:issue)
252 assert_not_nil issue
254 assert_not_nil issue
253
255
254 assert_equal 5, issue.status_id
256 assert_equal 5, issue.status_id
255 assert_tag :select, :attributes => { :name => 'issue[status_id]' },
257 assert_tag :select, :attributes => { :name => 'issue[status_id]' },
256 :child => { :tag => 'option',
258 :child => { :tag => 'option',
257 :content => 'Closed',
259 :content => 'Closed',
258 :attributes => { :selected => 'selected' } }
260 :attributes => { :selected => 'selected' } }
259
261
260 assert_equal 7, issue.priority_id
262 assert_equal 7, issue.priority_id
261 assert_tag :select, :attributes => { :name => 'issue[priority_id]' },
263 assert_tag :select, :attributes => { :name => 'issue[priority_id]' },
262 :child => { :tag => 'option',
264 :child => { :tag => 'option',
263 :content => 'Urgent',
265 :content => 'Urgent',
264 :attributes => { :selected => 'selected' } }
266 :attributes => { :selected => 'selected' } }
265 end
267 end
266
268
267 def test_reply_to_issue
269 def test_reply_to_issue
268 @request.session[:user_id] = 2
270 @request.session[:user_id] = 2
269 get :reply, :id => 1
271 get :reply, :id => 1
270 assert_response :success
272 assert_response :success
271 assert_select_rjs :show, "update"
273 assert_select_rjs :show, "update"
272 assert_select_rjs :replace_html, "notes"
273 end
274 end
274
275
275 def test_reply_to_note
276 def test_reply_to_note
276 @request.session[:user_id] = 2
277 @request.session[:user_id] = 2
277 get :reply, :id => 1, :journal_id => 2
278 get :reply, :id => 1, :journal_id => 2
278 assert_response :success
279 assert_response :success
279 assert_select_rjs :show, "update"
280 assert_select_rjs :show, "update"
280 assert_select_rjs :replace_html, "notes"
281 end
281 end
282
282
283 def test_post_edit
283 def test_post_edit
284 @request.session[:user_id] = 2
284 @request.session[:user_id] = 2
285 ActionMailer::Base.deliveries.clear
285 ActionMailer::Base.deliveries.clear
286
286
287 issue = Issue.find(1)
287 issue = Issue.find(1)
288 old_subject = issue.subject
288 old_subject = issue.subject
289 new_subject = 'Subject modified by IssuesControllerTest#test_post_edit'
289 new_subject = 'Subject modified by IssuesControllerTest#test_post_edit'
290
290
291 post :edit, :id => 1, :issue => {:subject => new_subject}
291 post :edit, :id => 1, :issue => {:subject => new_subject}
292 assert_redirected_to 'issues/show/1'
292 assert_redirected_to 'issues/show/1'
293 issue.reload
293 issue.reload
294 assert_equal new_subject, issue.subject
294 assert_equal new_subject, issue.subject
295
295
296 mail = ActionMailer::Base.deliveries.last
296 mail = ActionMailer::Base.deliveries.last
297 assert_kind_of TMail::Mail, mail
297 assert_kind_of TMail::Mail, mail
298 assert mail.subject.starts_with?("[#{issue.project.name} - #{issue.tracker.name} ##{issue.id}]")
298 assert mail.subject.starts_with?("[#{issue.project.name} - #{issue.tracker.name} ##{issue.id}]")
299 assert mail.body.include?("Subject changed from #{old_subject} to #{new_subject}")
299 assert mail.body.include?("Subject changed from #{old_subject} to #{new_subject}")
300 end
300 end
301
301
302 def test_post_edit_with_status_and_assignee_change
302 def test_post_edit_with_status_and_assignee_change
303 issue = Issue.find(1)
303 issue = Issue.find(1)
304 assert_equal 1, issue.status_id
304 assert_equal 1, issue.status_id
305 @request.session[:user_id] = 2
305 @request.session[:user_id] = 2
306 assert_difference('TimeEntry.count', 0) do
306 assert_difference('TimeEntry.count', 0) do
307 post :edit,
307 post :edit,
308 :id => 1,
308 :id => 1,
309 :issue => { :status_id => 2, :assigned_to_id => 3 },
309 :issue => { :status_id => 2, :assigned_to_id => 3 },
310 :notes => 'Assigned to dlopper',
310 :notes => 'Assigned to dlopper',
311 :time_entry => { :hours => '', :comments => '', :activity_id => Enumeration.get_values('ACTI').first }
311 :time_entry => { :hours => '', :comments => '', :activity_id => Enumeration.get_values('ACTI').first }
312 end
312 end
313 assert_redirected_to 'issues/show/1'
313 assert_redirected_to 'issues/show/1'
314 issue.reload
314 issue.reload
315 assert_equal 2, issue.status_id
315 assert_equal 2, issue.status_id
316 j = issue.journals.find(:first, :order => 'id DESC')
316 j = issue.journals.find(:first, :order => 'id DESC')
317 assert_equal 'Assigned to dlopper', j.notes
317 assert_equal 'Assigned to dlopper', j.notes
318 assert_equal 2, j.details.size
318 assert_equal 2, j.details.size
319
319
320 mail = ActionMailer::Base.deliveries.last
320 mail = ActionMailer::Base.deliveries.last
321 assert mail.body.include?("Status changed from New to Assigned")
321 assert mail.body.include?("Status changed from New to Assigned")
322 end
322 end
323
323
324 def test_post_edit_with_note_only
324 def test_post_edit_with_note_only
325 notes = 'Note added by IssuesControllerTest#test_update_with_note_only'
325 notes = 'Note added by IssuesControllerTest#test_update_with_note_only'
326 # anonymous user
326 # anonymous user
327 post :edit,
327 post :edit,
328 :id => 1,
328 :id => 1,
329 :notes => notes
329 :notes => notes
330 assert_redirected_to 'issues/show/1'
330 assert_redirected_to 'issues/show/1'
331 j = Issue.find(1).journals.find(:first, :order => 'id DESC')
331 j = Issue.find(1).journals.find(:first, :order => 'id DESC')
332 assert_equal notes, j.notes
332 assert_equal notes, j.notes
333 assert_equal 0, j.details.size
333 assert_equal 0, j.details.size
334 assert_equal User.anonymous, j.user
334 assert_equal User.anonymous, j.user
335
335
336 mail = ActionMailer::Base.deliveries.last
336 mail = ActionMailer::Base.deliveries.last
337 assert mail.body.include?(notes)
337 assert mail.body.include?(notes)
338 end
338 end
339
339
340 def test_post_edit_with_note_and_spent_time
340 def test_post_edit_with_note_and_spent_time
341 @request.session[:user_id] = 2
341 @request.session[:user_id] = 2
342 spent_hours_before = Issue.find(1).spent_hours
342 spent_hours_before = Issue.find(1).spent_hours
343 assert_difference('TimeEntry.count') do
343 assert_difference('TimeEntry.count') do
344 post :edit,
344 post :edit,
345 :id => 1,
345 :id => 1,
346 :notes => '2.5 hours added',
346 :notes => '2.5 hours added',
347 :time_entry => { :hours => '2.5', :comments => '', :activity_id => Enumeration.get_values('ACTI').first }
347 :time_entry => { :hours => '2.5', :comments => '', :activity_id => Enumeration.get_values('ACTI').first }
348 end
348 end
349 assert_redirected_to 'issues/show/1'
349 assert_redirected_to 'issues/show/1'
350
350
351 issue = Issue.find(1)
351 issue = Issue.find(1)
352
352
353 j = issue.journals.find(:first, :order => 'id DESC')
353 j = issue.journals.find(:first, :order => 'id DESC')
354 assert_equal '2.5 hours added', j.notes
354 assert_equal '2.5 hours added', j.notes
355 assert_equal 0, j.details.size
355 assert_equal 0, j.details.size
356
356
357 t = issue.time_entries.find(:first, :order => 'id DESC')
357 t = issue.time_entries.find(:first, :order => 'id DESC')
358 assert_not_nil t
358 assert_not_nil t
359 assert_equal 2.5, t.hours
359 assert_equal 2.5, t.hours
360 assert_equal spent_hours_before + 2.5, issue.spent_hours
360 assert_equal spent_hours_before + 2.5, issue.spent_hours
361 end
361 end
362
362
363 def test_post_edit_with_attachment_only
363 def test_post_edit_with_attachment_only
364 # anonymous user
364 # anonymous user
365 post :edit,
365 post :edit,
366 :id => 1,
366 :id => 1,
367 :notes => '',
367 :notes => '',
368 :attachments => {'1' => {'file' => test_uploaded_file('testfile.txt', 'text/plain')}}
368 :attachments => {'1' => {'file' => test_uploaded_file('testfile.txt', 'text/plain')}}
369 assert_redirected_to 'issues/show/1'
369 assert_redirected_to 'issues/show/1'
370 j = Issue.find(1).journals.find(:first, :order => 'id DESC')
370 j = Issue.find(1).journals.find(:first, :order => 'id DESC')
371 assert j.notes.blank?
371 assert j.notes.blank?
372 assert_equal 1, j.details.size
372 assert_equal 1, j.details.size
373 assert_equal 'testfile.txt', j.details.first.value
373 assert_equal 'testfile.txt', j.details.first.value
374 assert_equal User.anonymous, j.user
374 assert_equal User.anonymous, j.user
375
375
376 mail = ActionMailer::Base.deliveries.last
376 mail = ActionMailer::Base.deliveries.last
377 assert mail.body.include?('testfile.txt')
377 assert mail.body.include?('testfile.txt')
378 end
378 end
379
379
380 def test_post_edit_with_no_change
380 def test_post_edit_with_no_change
381 issue = Issue.find(1)
381 issue = Issue.find(1)
382 issue.journals.clear
382 issue.journals.clear
383 ActionMailer::Base.deliveries.clear
383 ActionMailer::Base.deliveries.clear
384
384
385 post :edit,
385 post :edit,
386 :id => 1,
386 :id => 1,
387 :notes => ''
387 :notes => ''
388 assert_redirected_to 'issues/show/1'
388 assert_redirected_to 'issues/show/1'
389
389
390 issue.reload
390 issue.reload
391 assert issue.journals.empty?
391 assert issue.journals.empty?
392 # No email should be sent
392 # No email should be sent
393 assert ActionMailer::Base.deliveries.empty?
393 assert ActionMailer::Base.deliveries.empty?
394 end
394 end
395
395
396 def test_bulk_edit
396 def test_bulk_edit
397 @request.session[:user_id] = 2
397 @request.session[:user_id] = 2
398 # update issues priority
398 # update issues priority
399 post :bulk_edit, :ids => [1, 2], :priority_id => 7, :notes => 'Bulk editing', :assigned_to_id => ''
399 post :bulk_edit, :ids => [1, 2], :priority_id => 7, :notes => 'Bulk editing', :assigned_to_id => ''
400 assert_response 302
400 assert_response 302
401 # check that the issues were updated
401 # check that the issues were updated
402 assert_equal [7, 7], Issue.find_all_by_id([1, 2]).collect {|i| i.priority.id}
402 assert_equal [7, 7], Issue.find_all_by_id([1, 2]).collect {|i| i.priority.id}
403 assert_equal 'Bulk editing', Issue.find(1).journals.find(:first, :order => 'created_on DESC').notes
403 assert_equal 'Bulk editing', Issue.find(1).journals.find(:first, :order => 'created_on DESC').notes
404 end
404 end
405
405
406 def test_bulk_unassign
406 def test_bulk_unassign
407 assert_not_nil Issue.find(2).assigned_to
407 assert_not_nil Issue.find(2).assigned_to
408 @request.session[:user_id] = 2
408 @request.session[:user_id] = 2
409 # unassign issues
409 # unassign issues
410 post :bulk_edit, :ids => [1, 2], :notes => 'Bulk unassigning', :assigned_to_id => 'none'
410 post :bulk_edit, :ids => [1, 2], :notes => 'Bulk unassigning', :assigned_to_id => 'none'
411 assert_response 302
411 assert_response 302
412 # check that the issues were updated
412 # check that the issues were updated
413 assert_nil Issue.find(2).assigned_to
413 assert_nil Issue.find(2).assigned_to
414 end
414 end
415
415
416 def test_move_one_issue_to_another_project
416 def test_move_one_issue_to_another_project
417 @request.session[:user_id] = 1
417 @request.session[:user_id] = 1
418 post :move, :id => 1, :new_project_id => 2
418 post :move, :id => 1, :new_project_id => 2
419 assert_redirected_to 'projects/ecookbook/issues'
419 assert_redirected_to 'projects/ecookbook/issues'
420 assert_equal 2, Issue.find(1).project_id
420 assert_equal 2, Issue.find(1).project_id
421 end
421 end
422
422
423 def test_bulk_move_to_another_project
423 def test_bulk_move_to_another_project
424 @request.session[:user_id] = 1
424 @request.session[:user_id] = 1
425 post :move, :ids => [1, 2], :new_project_id => 2
425 post :move, :ids => [1, 2], :new_project_id => 2
426 assert_redirected_to 'projects/ecookbook/issues'
426 assert_redirected_to 'projects/ecookbook/issues'
427 # Issues moved to project 2
427 # Issues moved to project 2
428 assert_equal 2, Issue.find(1).project_id
428 assert_equal 2, Issue.find(1).project_id
429 assert_equal 2, Issue.find(2).project_id
429 assert_equal 2, Issue.find(2).project_id
430 # No tracker change
430 # No tracker change
431 assert_equal 1, Issue.find(1).tracker_id
431 assert_equal 1, Issue.find(1).tracker_id
432 assert_equal 2, Issue.find(2).tracker_id
432 assert_equal 2, Issue.find(2).tracker_id
433 end
433 end
434
434
435 def test_bulk_move_to_another_tracker
435 def test_bulk_move_to_another_tracker
436 @request.session[:user_id] = 1
436 @request.session[:user_id] = 1
437 post :move, :ids => [1, 2], :new_tracker_id => 2
437 post :move, :ids => [1, 2], :new_tracker_id => 2
438 assert_redirected_to 'projects/ecookbook/issues'
438 assert_redirected_to 'projects/ecookbook/issues'
439 assert_equal 2, Issue.find(1).tracker_id
439 assert_equal 2, Issue.find(1).tracker_id
440 assert_equal 2, Issue.find(2).tracker_id
440 assert_equal 2, Issue.find(2).tracker_id
441 end
441 end
442
442
443 def test_context_menu_one_issue
443 def test_context_menu_one_issue
444 @request.session[:user_id] = 2
444 @request.session[:user_id] = 2
445 get :context_menu, :ids => [1]
445 get :context_menu, :ids => [1]
446 assert_response :success
446 assert_response :success
447 assert_template 'context_menu'
447 assert_template 'context_menu'
448 assert_tag :tag => 'a', :content => 'Edit',
448 assert_tag :tag => 'a', :content => 'Edit',
449 :attributes => { :href => '/issues/edit/1',
449 :attributes => { :href => '/issues/edit/1',
450 :class => 'icon-edit' }
450 :class => 'icon-edit' }
451 assert_tag :tag => 'a', :content => 'Closed',
451 assert_tag :tag => 'a', :content => 'Closed',
452 :attributes => { :href => '/issues/edit/1?issue%5Bstatus_id%5D=5',
452 :attributes => { :href => '/issues/edit/1?issue%5Bstatus_id%5D=5',
453 :class => '' }
453 :class => '' }
454 assert_tag :tag => 'a', :content => 'Immediate',
454 assert_tag :tag => 'a', :content => 'Immediate',
455 :attributes => { :href => '/issues/edit/1?issue%5Bpriority_id%5D=8',
455 :attributes => { :href => '/issues/edit/1?issue%5Bpriority_id%5D=8',
456 :class => '' }
456 :class => '' }
457 assert_tag :tag => 'a', :content => 'Dave Lopper',
457 assert_tag :tag => 'a', :content => 'Dave Lopper',
458 :attributes => { :href => '/issues/edit/1?issue%5Bassigned_to_id%5D=3',
458 :attributes => { :href => '/issues/edit/1?issue%5Bassigned_to_id%5D=3',
459 :class => '' }
459 :class => '' }
460 assert_tag :tag => 'a', :content => 'Copy',
460 assert_tag :tag => 'a', :content => 'Copy',
461 :attributes => { :href => '/projects/ecookbook/issues/new?copy_from=1',
461 :attributes => { :href => '/projects/ecookbook/issues/new?copy_from=1',
462 :class => 'icon-copy' }
462 :class => 'icon-copy' }
463 assert_tag :tag => 'a', :content => 'Move',
463 assert_tag :tag => 'a', :content => 'Move',
464 :attributes => { :href => '/issues/move?ids%5B%5D=1',
464 :attributes => { :href => '/issues/move?ids%5B%5D=1',
465 :class => 'icon-move' }
465 :class => 'icon-move' }
466 assert_tag :tag => 'a', :content => 'Delete',
466 assert_tag :tag => 'a', :content => 'Delete',
467 :attributes => { :href => '/issues/destroy?ids%5B%5D=1',
467 :attributes => { :href => '/issues/destroy?ids%5B%5D=1',
468 :class => 'icon-del' }
468 :class => 'icon-del' }
469 end
469 end
470
470
471 def test_context_menu_one_issue_by_anonymous
471 def test_context_menu_one_issue_by_anonymous
472 get :context_menu, :ids => [1]
472 get :context_menu, :ids => [1]
473 assert_response :success
473 assert_response :success
474 assert_template 'context_menu'
474 assert_template 'context_menu'
475 assert_tag :tag => 'a', :content => 'Delete',
475 assert_tag :tag => 'a', :content => 'Delete',
476 :attributes => { :href => '#',
476 :attributes => { :href => '#',
477 :class => 'icon-del disabled' }
477 :class => 'icon-del disabled' }
478 end
478 end
479
479
480 def test_context_menu_multiple_issues_of_same_project
480 def test_context_menu_multiple_issues_of_same_project
481 @request.session[:user_id] = 2
481 @request.session[:user_id] = 2
482 get :context_menu, :ids => [1, 2]
482 get :context_menu, :ids => [1, 2]
483 assert_response :success
483 assert_response :success
484 assert_template 'context_menu'
484 assert_template 'context_menu'
485 assert_tag :tag => 'a', :content => 'Edit',
485 assert_tag :tag => 'a', :content => 'Edit',
486 :attributes => { :href => '/issues/bulk_edit?ids%5B%5D=1&amp;ids%5B%5D=2',
486 :attributes => { :href => '/issues/bulk_edit?ids%5B%5D=1&amp;ids%5B%5D=2',
487 :class => 'icon-edit' }
487 :class => 'icon-edit' }
488 assert_tag :tag => 'a', :content => 'Move',
488 assert_tag :tag => 'a', :content => 'Move',
489 :attributes => { :href => '/issues/move?ids%5B%5D=1&amp;ids%5B%5D=2',
489 :attributes => { :href => '/issues/move?ids%5B%5D=1&amp;ids%5B%5D=2',
490 :class => 'icon-move' }
490 :class => 'icon-move' }
491 assert_tag :tag => 'a', :content => 'Delete',
491 assert_tag :tag => 'a', :content => 'Delete',
492 :attributes => { :href => '/issues/destroy?ids%5B%5D=1&amp;ids%5B%5D=2',
492 :attributes => { :href => '/issues/destroy?ids%5B%5D=1&amp;ids%5B%5D=2',
493 :class => 'icon-del' }
493 :class => 'icon-del' }
494 end
494 end
495
495
496 def test_context_menu_multiple_issues_of_different_project
496 def test_context_menu_multiple_issues_of_different_project
497 @request.session[:user_id] = 2
497 @request.session[:user_id] = 2
498 get :context_menu, :ids => [1, 2, 4]
498 get :context_menu, :ids => [1, 2, 4]
499 assert_response :success
499 assert_response :success
500 assert_template 'context_menu'
500 assert_template 'context_menu'
501 assert_tag :tag => 'a', :content => 'Delete',
501 assert_tag :tag => 'a', :content => 'Delete',
502 :attributes => { :href => '#',
502 :attributes => { :href => '#',
503 :class => 'icon-del disabled' }
503 :class => 'icon-del disabled' }
504 end
504 end
505
505
506 def test_destroy_issue_with_no_time_entries
506 def test_destroy_issue_with_no_time_entries
507 assert_nil TimeEntry.find_by_issue_id(2)
507 assert_nil TimeEntry.find_by_issue_id(2)
508 @request.session[:user_id] = 2
508 @request.session[:user_id] = 2
509 post :destroy, :id => 2
509 post :destroy, :id => 2
510 assert_redirected_to 'projects/ecookbook/issues'
510 assert_redirected_to 'projects/ecookbook/issues'
511 assert_nil Issue.find_by_id(2)
511 assert_nil Issue.find_by_id(2)
512 end
512 end
513
513
514 def test_destroy_issues_with_time_entries
514 def test_destroy_issues_with_time_entries
515 @request.session[:user_id] = 2
515 @request.session[:user_id] = 2
516 post :destroy, :ids => [1, 3]
516 post :destroy, :ids => [1, 3]
517 assert_response :success
517 assert_response :success
518 assert_template 'destroy'
518 assert_template 'destroy'
519 assert_not_nil assigns(:hours)
519 assert_not_nil assigns(:hours)
520 assert Issue.find_by_id(1) && Issue.find_by_id(3)
520 assert Issue.find_by_id(1) && Issue.find_by_id(3)
521 end
521 end
522
522
523 def test_destroy_issues_and_destroy_time_entries
523 def test_destroy_issues_and_destroy_time_entries
524 @request.session[:user_id] = 2
524 @request.session[:user_id] = 2
525 post :destroy, :ids => [1, 3], :todo => 'destroy'
525 post :destroy, :ids => [1, 3], :todo => 'destroy'
526 assert_redirected_to 'projects/ecookbook/issues'
526 assert_redirected_to 'projects/ecookbook/issues'
527 assert !(Issue.find_by_id(1) || Issue.find_by_id(3))
527 assert !(Issue.find_by_id(1) || Issue.find_by_id(3))
528 assert_nil TimeEntry.find_by_id([1, 2])
528 assert_nil TimeEntry.find_by_id([1, 2])
529 end
529 end
530
530
531 def test_destroy_issues_and_assign_time_entries_to_project
531 def test_destroy_issues_and_assign_time_entries_to_project
532 @request.session[:user_id] = 2
532 @request.session[:user_id] = 2
533 post :destroy, :ids => [1, 3], :todo => 'nullify'
533 post :destroy, :ids => [1, 3], :todo => 'nullify'
534 assert_redirected_to 'projects/ecookbook/issues'
534 assert_redirected_to 'projects/ecookbook/issues'
535 assert !(Issue.find_by_id(1) || Issue.find_by_id(3))
535 assert !(Issue.find_by_id(1) || Issue.find_by_id(3))
536 assert_nil TimeEntry.find(1).issue_id
536 assert_nil TimeEntry.find(1).issue_id
537 assert_nil TimeEntry.find(2).issue_id
537 assert_nil TimeEntry.find(2).issue_id
538 end
538 end
539
539
540 def test_destroy_issues_and_reassign_time_entries_to_another_issue
540 def test_destroy_issues_and_reassign_time_entries_to_another_issue
541 @request.session[:user_id] = 2
541 @request.session[:user_id] = 2
542 post :destroy, :ids => [1, 3], :todo => 'reassign', :reassign_to_id => 2
542 post :destroy, :ids => [1, 3], :todo => 'reassign', :reassign_to_id => 2
543 assert_redirected_to 'projects/ecookbook/issues'
543 assert_redirected_to 'projects/ecookbook/issues'
544 assert !(Issue.find_by_id(1) || Issue.find_by_id(3))
544 assert !(Issue.find_by_id(1) || Issue.find_by_id(3))
545 assert_equal 2, TimeEntry.find(1).issue_id
545 assert_equal 2, TimeEntry.find(1).issue_id
546 assert_equal 2, TimeEntry.find(2).issue_id
546 assert_equal 2, TimeEntry.find(2).issue_id
547 end
547 end
548
548
549 def test_destroy_attachment
549 def test_destroy_attachment
550 issue = Issue.find(3)
550 issue = Issue.find(3)
551 a = issue.attachments.size
551 a = issue.attachments.size
552 @request.session[:user_id] = 2
552 @request.session[:user_id] = 2
553 post :destroy_attachment, :id => 3, :attachment_id => 1
553 post :destroy_attachment, :id => 3, :attachment_id => 1
554 assert_redirected_to 'issues/show/3'
554 assert_redirected_to 'issues/show/3'
555 assert_nil Attachment.find_by_id(1)
555 assert_nil Attachment.find_by_id(1)
556 issue.reload
556 issue.reload
557 assert_equal((a-1), issue.attachments.size)
557 assert_equal((a-1), issue.attachments.size)
558 j = issue.journals.find(:first, :order => 'created_on DESC')
558 j = issue.journals.find(:first, :order => 'created_on DESC')
559 assert_equal 'attachment', j.details.first.property
559 assert_equal 'attachment', j.details.first.property
560 end
560 end
561 end
561 end
General Comments 0
You need to be logged in to leave comments. Login now