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