Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Valid hex strings aren't valid float column values, to match the inte…
…ger restriction. [#4622 state:resolved]
  • Loading branch information
jeremy committed May 17, 2010
1 parent c2fb8af commit 5371242
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
11 changes: 8 additions & 3 deletions activemodel/lib/active_model/validations/numericality.rb
Expand Up @@ -57,10 +57,15 @@ def validate_each(record, attr_name, value)
protected

def parse_raw_value_as_a_number(raw_value)
begin
Kernel.Float(raw_value)
rescue ArgumentError, TypeError
case raw_value
when /\A0x/
nil
else
begin
Kernel.Float(raw_value)
rescue ArgumentError, TypeError
nil
end
end
end

Expand Down
Expand Up @@ -18,7 +18,7 @@ def teardown
FLOATS = [0.0, 10.0, 10.5, -10.5, -0.0001] + FLOAT_STRINGS
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"]
JUNK = ["not a number", "42 not a number", "0xdeadbeef", "0xinvalidhex", "00-1", "--3", "+-3", "+3-1", "-+019.0", "12.12.13.12", "123\nnot a number"]
INFINITY = [1.0/0.0]

def test_default_validates_numericality_of
Expand Down

0 comments on commit 5371242

Please sign in to comment.