aboutsummaryrefslogtreecommitdiffstats
path: root/activemodel
diff options
context:
space:
mode:
authorRyuta Kamizono <kamipo@gmail.com>2018-11-12 03:39:28 +0900
committerRyuta Kamizono <kamipo@gmail.com>2018-11-12 03:39:28 +0900
commita741208f80dd33420a56486bd9ed2b0b9862234a (patch)
treed718f93e317084e299379b134135d600520150ea /activemodel
parent44bee7f242da1df49a31416b762e0a03467ae2bb (diff)
downloadrails-a741208f80dd33420a56486bd9ed2b0b9862234a.tar.gz
rails-a741208f80dd33420a56486bd9ed2b0b9862234a.tar.bz2
rails-a741208f80dd33420a56486bd9ed2b0b9862234a.zip
Ensure casting by decimal attribute when querying
Related 34cc301f03aea2e579d6687a9ea9782afc1089a0. `QueryAttribute#value_for_database` calls only `type.serialize`, and `Decimal#serialize` is a no-op unlike other attribute types. Whether or not `serialize` will invoke `cast` is undefined in our test cases, but it actually does not work properly unless it does so for now.
Diffstat (limited to 'activemodel')
-rw-r--r--activemodel/lib/active_model/type/decimal.rb4
1 files changed, 4 insertions, 0 deletions
diff --git a/activemodel/lib/active_model/type/decimal.rb b/activemodel/lib/active_model/type/decimal.rb
index e8ee18c00e..b37dad1c41 100644
--- a/activemodel/lib/active_model/type/decimal.rb
+++ b/activemodel/lib/active_model/type/decimal.rb
@@ -12,6 +12,10 @@ module ActiveModel
:decimal
end
+ def serialize(value)
+ cast(value)
+ end
+
def type_cast_for_schema(value)
value.to_s.inspect
end