Merge pull request #33804 from yskkin/num_string

Fix non_numeric_string?
This commit is contained in:
Ryuta Kamizono 2018-09-08 05:56:22 +09:00 committed by GitHub
commit c3e569550c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 14 additions and 4 deletions

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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)