From 2fece9036d8ea778fca63a0d5df9a9dfc330dfa5 Mon Sep 17 00:00:00 2001 From: Ryuta Kamizono Date: Fri, 10 Aug 2018 19:42:00 +0900 Subject: 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. --- activerecord/test/models/price_estimate.rb | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'activerecord/test/models/price_estimate.rb') diff --git a/activerecord/test/models/price_estimate.rb b/activerecord/test/models/price_estimate.rb index f1f88d8d8d..669d0991f7 100644 --- a/activerecord/test/models/price_estimate.rb +++ b/activerecord/test/models/price_estimate.rb @@ -1,6 +1,14 @@ # frozen_string_literal: true class PriceEstimate < ActiveRecord::Base + include ActiveSupport::NumberHelper + belongs_to :estimate_of, polymorphic: true belongs_to :thing, polymorphic: true + + validates_numericality_of :price + + def price + number_to_currency super + end end -- cgit v1.2.3