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