diff options
author | Sean Griffin <sean@thoughtbot.com> | 2014-06-24 06:55:24 -0600 |
---|---|---|
committer | Sean Griffin <sean@thoughtbot.com> | 2014-06-24 08:32:30 -0600 |
commit | 50fa366783c2403d909a6fa5b7fc6d4c7fdacf7f (patch) | |
tree | 20c9ec3ac39490d6a56c44013bfe92a985c193d0 /activerecord/lib | |
parent | 9ac1ce11ad9ec22157d2e542437c5c5cccaf58fe (diff) | |
download | rails-50fa366783c2403d909a6fa5b7fc6d4c7fdacf7f.tar.gz rails-50fa366783c2403d909a6fa5b7fc6d4c7fdacf7f.tar.bz2 rails-50fa366783c2403d909a6fa5b7fc6d4c7fdacf7f.zip |
Always assume strings with non-numeric characters change numeric types
We previously only did this if the old value was zero, to make sure
numericality validations run and failed if the user gave 'wibble' as the
value, which would be type cast to 0. However, numericality validations
will fail if there are any non-numeric characters in the string, so 5 ->
'5wibble' should also be marked as changed.
Diffstat (limited to 'activerecord/lib')
-rw-r--r-- | activerecord/lib/active_record/type/numeric.rb | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/activerecord/lib/active_record/type/numeric.rb b/activerecord/lib/active_record/type/numeric.rb index a7bf0657b9..fa43266504 100644 --- a/activerecord/lib/active_record/type/numeric.rb +++ b/activerecord/lib/active_record/type/numeric.rb @@ -16,13 +16,13 @@ module ActiveRecord end def changed?(old_value, _new_value, new_value_before_type_cast) # :nodoc: - super || zero_to_non_number?(old_value, new_value_before_type_cast) + super || number_to_non_number?(old_value, new_value_before_type_cast) end private - def zero_to_non_number?(old_value, new_value_before_type_cast) - old_value == 0 && non_numeric_string?(new_value_before_type_cast) + def number_to_non_number?(old_value, new_value_before_type_cast) + old_value != nil && non_numeric_string?(new_value_before_type_cast) end def non_numeric_string?(value) |