##// 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 32 :description => :comments
33 33
34 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 36 validates_length_of :comments, :maximum => 255, :allow_nil => true
37 37
38 38 def after_initialize
@@ -54,7 +54,7 class TimeEntry < ActiveRecord::Base
54 54 end
55 55
56 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 58 end
59 59
60 60 # tyear, tmonth, tweek assigned where setting spent_on attributes
@@ -24,7 +24,9 module Redmine #:nodoc:
24 24 def to_hours
25 25 s = self.dup
26 26 s.strip!
27 unless s =~ %r{^[\d\.,]+$}
27 if s =~ %r{^(\d+([.,]\d+)?)h?$}
28 s = $1
29 else
28 30 # 2:30 => 2.5
29 31 s.gsub!(%r{^(\d+):(\d+)$}) { $1.to_i + $2.to_i / 60.0 }
30 32 # 2h30, 2h, 30m => 2.5, 2, 0.5
@@ -597,6 +597,24 class IssuesControllerTest < Test::Unit::TestCase
597 597 # No email should be sent
598 598 assert ActionMailer::Base.deliveries.empty?
599 599 end
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
600 618
601 619 def test_bulk_edit
602 620 @request.session[:user_id] = 2
@@ -24,6 +24,7 class TimeEntryTest < Test::Unit::TestCase
24 24 assertions = { "2" => 2.0,
25 25 "21.1" => 21.1,
26 26 "2,1" => 2.1,
27 "1,5h" => 1.5,
27 28 "7:12" => 7.2,
28 29 "10h" => 10.0,
29 30 "10 h" => 10.0,
@@ -40,7 +41,7 class TimeEntryTest < Test::Unit::TestCase
40 41
41 42 assertions.each do |k, v|
42 43 t = TimeEntry.new(:hours => k)
43 assert_equal v, t.hours
44 assert_equal v, t.hours, "Converting #{k} failed:"
44 45 end
45 46 end
46 47 end
General Comments 0
You need to be logged in to leave comments. Login now