mirror of https://github.com/rails/rails
Merge pull request #33804 from yskkin/num_string
Fix non_numeric_string?
This commit is contained in:
commit
c3e569550c
|
@ -29,7 +29,7 @@ module ActiveModel
|
|||
# 'wibble'.to_i will give zero, we want to make sure
|
||||
# that we aren't marking int zero to string zero as
|
||||
# changed.
|
||||
value.to_s !~ /\A-?\d+\.?\d*\z/
|
||||
!/\A[-+]?\d+/.match?(value.to_s)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -57,9 +57,12 @@ module ActiveModel
|
|||
def test_changed?
|
||||
type = Decimal.new
|
||||
|
||||
assert type.changed?(5.0, 5.0, "5.0wibble")
|
||||
assert type.changed?(0.0, 0, "wibble")
|
||||
assert type.changed?(5.0, 0, "wibble")
|
||||
assert_not type.changed?(5.0, 5.0, "5.0wibble")
|
||||
assert_not type.changed?(5.0, 5.0, "5.0")
|
||||
assert_not type.changed?(-5.0, -5.0, "-5.0")
|
||||
assert_not type.changed?(5.0, 5.0, "0.5e+1")
|
||||
end
|
||||
|
||||
def test_scale_is_applied_before_precision_to_prevent_rounding_errors
|
||||
|
|
|
@ -21,9 +21,12 @@ module ActiveModel
|
|||
def test_changing_float
|
||||
type = Type::Float.new
|
||||
|
||||
assert type.changed?(5.0, 5.0, "5wibble")
|
||||
assert type.changed?(0.0, 0, "wibble")
|
||||
assert type.changed?(5.0, 0, "wibble")
|
||||
assert_not type.changed?(5.0, 5.0, "5wibble")
|
||||
assert_not type.changed?(5.0, 5.0, "5")
|
||||
assert_not type.changed?(5.0, 5.0, "5.0")
|
||||
assert_not type.changed?(500.0, 500.0, "0.5E+4")
|
||||
assert_not type.changed?(nil, nil, nil)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -53,9 +53,13 @@ module ActiveModel
|
|||
test "changed?" do
|
||||
type = Type::Integer.new
|
||||
|
||||
assert type.changed?(5, 5, "5wibble")
|
||||
assert type.changed?(0, 0, "wibble")
|
||||
assert type.changed?(5, 0, "wibble")
|
||||
assert_not type.changed?(5, 5, "5wibble")
|
||||
assert_not type.changed?(5, 5, "5")
|
||||
assert_not type.changed?(5, 5, "5.0")
|
||||
assert_not type.changed?(5, 5, "+5")
|
||||
assert_not type.changed?(5, 5, "+5.0")
|
||||
assert_not type.changed?(-5, -5, "-5")
|
||||
assert_not type.changed?(-5, -5, "-5.0")
|
||||
assert_not type.changed?(nil, nil, nil)
|
||||
|
|
Loading…
Reference in New Issue