diff options
author | Carlos Antonio da Silva <carlosantoniodasilva@gmail.com> | 2013-03-05 05:15:22 -0800 |
---|---|---|
committer | Carlos Antonio da Silva <carlosantoniodasilva@gmail.com> | 2013-03-05 05:15:22 -0800 |
commit | 09d1fb25c30149a04d756d80709a17f2912efb47 (patch) | |
tree | 2557417010edcc2b41f18f13a334f7ea452a9e23 /activerecord/lib | |
parent | 5cf472e04398ac2c67236a41566d95c0287b34fa (diff) | |
parent | 4b7a33e1423c207b25da7e34d8ea45c71ba12298 (diff) | |
download | rails-09d1fb25c30149a04d756d80709a17f2912efb47.tar.gz rails-09d1fb25c30149a04d756d80709a17f2912efb47.tar.bz2 rails-09d1fb25c30149a04d756d80709a17f2912efb47.zip |
Merge pull request #9042 from senny/9034_float_0_0_is_always_dirty
Assigning '0.0' to a nullable numeric column does not make it dirty
Example:
product = Product.create price: 0.0
product.price = '0.0'
product.changed? # => false (this used to return true)
product.changes # => {} (this used to return { price: [0.0, 0.0] })
Diffstat (limited to 'activerecord/lib')
-rw-r--r-- | activerecord/lib/active_record/attribute_methods/dirty.rb | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/attribute_methods/dirty.rb b/activerecord/lib/active_record/attribute_methods/dirty.rb index 616ae1631f..6315dd9549 100644 --- a/activerecord/lib/active_record/attribute_methods/dirty.rb +++ b/activerecord/lib/active_record/attribute_methods/dirty.rb @@ -107,7 +107,11 @@ module ActiveRecord def changes_from_zero_to_string?(old, value) # For columns with old 0 and value non-empty string - old == 0 && value.is_a?(String) && value.present? && value != '0' + old == 0 && value.is_a?(String) && value.present? && non_zero?(value) + end + + def non_zero?(value) + value !~ /\A0+(\.0+)?\z/ end end end |