diff options
author | Ryuta Kamizono <kamipo@gmail.com> | 2018-08-10 19:42:00 +0900 |
---|---|---|
committer | Ryuta Kamizono <kamipo@gmail.com> | 2018-08-13 23:28:46 +0900 |
commit | 2fece9036d8ea778fca63a0d5df9a9dfc330dfa5 (patch) | |
tree | b98c0513ce7cb277dc900c43b5adafeef5d7b50c /activemodel | |
parent | f2970a08b57ebcdb9cbf8eec5d10a7f04eb7b9d3 (diff) | |
download | rails-2fece9036d8ea778fca63a0d5df9a9dfc330dfa5.tar.gz rails-2fece9036d8ea778fca63a0d5df9a9dfc330dfa5.tar.bz2 rails-2fece9036d8ea778fca63a0d5df9a9dfc330dfa5.zip |
Fix numericality validator not to be affected by custom getter
Since fe9547b6, numericality validator would parse raw value only when a
value came from user to work type casting to a value from database.
But that was caused a regression that the validator would work against
getter value instead of parsed raw value, a getter is sometimes
customized by people. #33550
There we never guarantees that the value before type cast was going to
the used in this validation (actually here is only place that getter
value might not be used), but we should not change the behavior unless
there is some particular reason.
The purpose of fe9547b6 is to work type casting to a value from
database. We could achieve the purpose by using `read_attribute`,
without using getter value.
Fixes #33550.
Diffstat (limited to 'activemodel')
-rw-r--r-- | activemodel/lib/active_model/validations/numericality.rb | 2 |
1 files changed, 2 insertions, 0 deletions
diff --git a/activemodel/lib/active_model/validations/numericality.rb b/activemodel/lib/active_model/validations/numericality.rb index 0478915be7..3753040316 100644 --- a/activemodel/lib/active_model/validations/numericality.rb +++ b/activemodel/lib/active_model/validations/numericality.rb @@ -23,6 +23,8 @@ module ActiveModel if record.respond_to?(came_from_user) && record.public_send(came_from_user) raw_value = record.read_attribute_before_type_cast(attr_name) + elsif record.respond_to?(:read_attribute) + raw_value = record.read_attribute(attr_name) end raw_value ||= value |