Merge pull request #18162 from romaimperator/master
Fixing numeric attrs when set to same negative value
This commit is contained in:
commit
d56b766056
@ -1,3 +1,10 @@
|
||||
* Fixes bug with 'ActiveRecord::Type::Numeric' that causes negative values to
|
||||
be marked as having changed when set to the same negative value.
|
||||
|
||||
Closes GH#18161
|
||||
|
||||
*Daniel Fox*
|
||||
|
||||
* Introduce `force: :cascade` option for `create_table`. Using this option
|
||||
will recreate tables even if they have dependent objects (like foreign keys).
|
||||
`db/schema.rb` now uses `force: :cascade`. This makes it possible to
|
||||
|
@ -29,7 +29,7 @@ def non_numeric_string?(value)
|
||||
# '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/
|
||||
value.to_s !~ /\A-?\d+\.?\d*\z/
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -38,6 +38,14 @@ def value.to_d
|
||||
type = Decimal.new
|
||||
assert_equal BigDecimal("1"), type.type_cast_from_user(value)
|
||||
end
|
||||
|
||||
def test_changed?
|
||||
type = Decimal.new
|
||||
|
||||
assert 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')
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -47,6 +47,8 @@ class IntegerTest < ActiveRecord::TestCase
|
||||
assert 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?(nil, nil, nil)
|
||||
end
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user