Valid hex strings aren't valid float column values, to match the integer restriction. [#4622 state:resolved]
This commit is contained in:
parent
c2fb8afaa0
commit
5371242384
@ -57,12 +57,17 @@ def validate_each(record, attr_name, value)
|
||||
protected
|
||||
|
||||
def parse_raw_value_as_a_number(raw_value)
|
||||
case raw_value
|
||||
when /\A0x/
|
||||
nil
|
||||
else
|
||||
begin
|
||||
Kernel.Float(raw_value)
|
||||
rescue ArgumentError, TypeError
|
||||
nil
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def parse_raw_value_as_an_integer(raw_value)
|
||||
raw_value.to_i if raw_value.to_s =~ /\A[+-]?\d+\Z/
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user