aboutsummaryrefslogtreecommitdiffstats
path: root/activemodel/lib/active_model/validations
diff options
context:
space:
mode:
authorRyuta Kamizono <kamipo@gmail.com>2018-05-25 12:05:50 +0900
committerRyuta Kamizono <kamipo@gmail.com>2018-05-28 10:12:15 +0900
commitfe9547b6fb60d92af181c8613166fa4322f8e307 (patch)
treee09b34beb48e37ea66d5c7df19fd3e7e7db5f531 /activemodel/lib/active_model/validations
parent17bf62033edd4f0934c9f4a9e0c7a5f0f765975b (diff)
downloadrails-fe9547b6fb60d92af181c8613166fa4322f8e307.tar.gz
rails-fe9547b6fb60d92af181c8613166fa4322f8e307.tar.bz2
rails-fe9547b6fb60d92af181c8613166fa4322f8e307.zip
Parse raw value only when a value came from user in numericality validator
Since `parse_raw_value_as_a_number` may not always parse raw value from database as a number without type casting (e.g. "$150.55" as money format). Fixes #32531.
Diffstat (limited to 'activemodel/lib/active_model/validations')
-rw-r--r--activemodel/lib/active_model/validations/numericality.rb6
1 files changed, 4 insertions, 2 deletions
diff --git a/activemodel/lib/active_model/validations/numericality.rb b/activemodel/lib/active_model/validations/numericality.rb
index 31750ba78e..0478915be7 100644
--- a/activemodel/lib/active_model/validations/numericality.rb
+++ b/activemodel/lib/active_model/validations/numericality.rb
@@ -19,9 +19,11 @@ module ActiveModel
end
def validate_each(record, attr_name, value)
- before_type_cast = :"#{attr_name}_before_type_cast"
+ came_from_user = :"#{attr_name}_came_from_user?"
- raw_value = record.send(before_type_cast) if record.respond_to?(before_type_cast) && record.send(before_type_cast) != value
+ if record.respond_to?(came_from_user) && record.public_send(came_from_user)
+ raw_value = record.read_attribute_before_type_cast(attr_name)
+ end
raw_value ||= value
if record_attribute_changed_in_place?(record, attr_name)