aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xactiverecord/lib/active_record/validations.rb2
-rwxr-xr-xactiverecord/test/cases/validations_test.rb11
2 files changed, 7 insertions, 6 deletions
diff --git a/activerecord/lib/active_record/validations.rb b/activerecord/lib/active_record/validations.rb
index 741649f764..1035308aa5 100755
--- a/activerecord/lib/active_record/validations.rb
+++ b/activerecord/lib/active_record/validations.rb
@@ -854,7 +854,7 @@ module ActiveRecord
raw_value = raw_value.to_i
else
begin
- raw_value = Kernel.Float(raw_value.to_s)
+ raw_value = Kernel.Float(raw_value)
rescue ArgumentError, TypeError
record.errors.add(attr_name, configuration[:message] || ActiveRecord::Errors.default_error_messages[:not_a_number])
next
diff --git a/activerecord/test/cases/validations_test.rb b/activerecord/test/cases/validations_test.rb
index 60566cd064..0742e2c632 100755
--- a/activerecord/test/cases/validations_test.rb
+++ b/activerecord/test/cases/validations_test.rb
@@ -1391,6 +1391,7 @@ class ValidatesNumericalityTest < ActiveRecord::TestCase
INTEGERS = [0, 10, -10] + INTEGER_STRINGS
BIGDECIMAL = BIGDECIMAL_STRINGS.collect! { |bd| BigDecimal.new(bd) }
JUNK = ["not a number", "42 not a number", "0xdeadbeef", "00-1", "--3", "+-3", "+3-1", "-+019.0", "12.12.13.12", "123\nnot a number"]
+ INFINITY = [1.0/0.0]
def setup
Topic.instance_variable_set("@validate_callbacks", ActiveSupport::Callbacks::CallbackChain.new)
@@ -1402,27 +1403,27 @@ class ValidatesNumericalityTest < ActiveRecord::TestCase
Topic.validates_numericality_of :approved
invalid!(NIL + BLANK + JUNK)
- valid!(FLOATS + INTEGERS + BIGDECIMAL)
+ valid!(FLOATS + INTEGERS + BIGDECIMAL + INFINITY)
end
def test_validates_numericality_of_with_nil_allowed
Topic.validates_numericality_of :approved, :allow_nil => true
invalid!(BLANK + JUNK)
- valid!(NIL + FLOATS + INTEGERS + BIGDECIMAL)
+ valid!(NIL + FLOATS + INTEGERS + BIGDECIMAL + INFINITY)
end
def test_validates_numericality_of_with_integer_only
Topic.validates_numericality_of :approved, :only_integer => true
- invalid!(NIL + BLANK + JUNK + FLOATS + BIGDECIMAL)
+ invalid!(NIL + BLANK + JUNK + FLOATS + BIGDECIMAL + INFINITY)
valid!(INTEGERS)
end
def test_validates_numericality_of_with_integer_only_and_nil_allowed
Topic.validates_numericality_of :approved, :only_integer => true, :allow_nil => true
- invalid!(BLANK + JUNK + FLOATS + BIGDECIMAL)
+ invalid!(BLANK + JUNK + FLOATS + BIGDECIMAL + INFINITY)
valid!(NIL + INTEGERS)
end
@@ -1443,7 +1444,7 @@ class ValidatesNumericalityTest < ActiveRecord::TestCase
def test_validates_numericality_with_equal_to
Topic.validates_numericality_of :approved, :equal_to => 10
- invalid!([-10, 11], 'must be equal to 10')
+ invalid!([-10, 11] + INFINITY, 'must be equal to 10')
valid!([10])
end