##// END OF EJS Templates
Fixed: no error is raised when entering invalid hours on the issue update form (#2465)....
Jean-Philippe Lang -
r2249:6768bec4560e
parent child
Show More
@@ -32,7 +32,7 class TimeEntry < ActiveRecord::Base
32 :description => :comments
32 :description => :comments
33
33
34 validates_presence_of :user_id, :activity_id, :project_id, :hours, :spent_on
34 validates_presence_of :user_id, :activity_id, :project_id, :hours, :spent_on
35 validates_numericality_of :hours, :allow_nil => true
35 validates_numericality_of :hours, :allow_nil => true, :message => :activerecord_error_invalid
36 validates_length_of :comments, :maximum => 255, :allow_nil => true
36 validates_length_of :comments, :maximum => 255, :allow_nil => true
37
37
38 def after_initialize
38 def after_initialize
@@ -54,7 +54,7 class TimeEntry < ActiveRecord::Base
54 end
54 end
55
55
56 def hours=(h)
56 def hours=(h)
57 write_attribute :hours, (h.is_a?(String) ? h.to_hours : h)
57 write_attribute :hours, (h.is_a?(String) ? (h.to_hours || h) : h)
58 end
58 end
59
59
60 # tyear, tmonth, tweek assigned where setting spent_on attributes
60 # tyear, tmonth, tweek assigned where setting spent_on attributes
@@ -24,7 +24,9 module Redmine #:nodoc:
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 if s =~ %r{^(\d+([.,]\d+)?)h?$}
28 s = $1
29 else
28 # 2:30 => 2.5
30 # 2:30 => 2.5
29 s.gsub!(%r{^(\d+):(\d+)$}) { $1.to_i + $2.to_i / 60.0 }
31 s.gsub!(%r{^(\d+):(\d+)$}) { $1.to_i + $2.to_i / 60.0 }
30 # 2h30, 2h, 30m => 2.5, 2, 0.5
32 # 2h30, 2h, 30m => 2.5, 2, 0.5
@@ -598,6 +598,24 class IssuesControllerTest < Test::Unit::TestCase
598 assert ActionMailer::Base.deliveries.empty?
598 assert ActionMailer::Base.deliveries.empty?
599 end
599 end
600
600
601 def test_post_edit_with_invalid_spent_time
602 @request.session[:user_id] = 2
603 notes = 'Note added by IssuesControllerTest#test_post_edit_with_invalid_spent_time'
604
605 assert_no_difference('Journal.count') do
606 post :edit,
607 :id => 1,
608 :notes => notes,
609 :time_entry => {"comments"=>"", "activity_id"=>"", "hours"=>"2z"}
610 end
611 assert_response :success
612 assert_template 'edit'
613
614 assert_tag :textarea, :attributes => { :name => 'notes' },
615 :content => notes
616 assert_tag :input, :attributes => { :name => 'time_entry[hours]', :value => "2z" }
617 end
618
601 def test_bulk_edit
619 def test_bulk_edit
602 @request.session[:user_id] = 2
620 @request.session[:user_id] = 2
603 # update issues priority
621 # update issues priority
@@ -24,6 +24,7 class TimeEntryTest < Test::Unit::TestCase
24 assertions = { "2" => 2.0,
24 assertions = { "2" => 2.0,
25 "21.1" => 21.1,
25 "21.1" => 21.1,
26 "2,1" => 2.1,
26 "2,1" => 2.1,
27 "1,5h" => 1.5,
27 "7:12" => 7.2,
28 "7:12" => 7.2,
28 "10h" => 10.0,
29 "10h" => 10.0,
29 "10 h" => 10.0,
30 "10 h" => 10.0,
@@ -40,7 +41,7 class TimeEntryTest < Test::Unit::TestCase
40
41
41 assertions.each do |k, v|
42 assertions.each do |k, v|
42 t = TimeEntry.new(:hours => k)
43 t = TimeEntry.new(:hours => k)
43 assert_equal v, t.hours
44 assert_equal v, t.hours, "Converting #{k} failed:"
44 end
45 end
45 end
46 end
46 end
47 end
General Comments 0
You need to be logged in to leave comments. Login now