diff options
author | Dylan Thacker-Smith <Dylan.Smith@shopify.com> | 2019-01-23 10:15:06 -0500 |
---|---|---|
committer | Dylan Thacker-Smith <Dylan.Smith@shopify.com> | 2019-01-23 14:49:42 -0500 |
commit | 5b58cc4f443b61ab157bf9ff3cb478314fdd31bd (patch) | |
tree | c212a0bc05ca58db31e0a45966f773dae2c4394d | |
parent | d1456e3ad52cdab6d2fa07ef3f239631a20a9a1f (diff) | |
download | rails-5b58cc4f443b61ab157bf9ff3cb478314fdd31bd.tar.gz rails-5b58cc4f443b61ab157bf9ff3cb478314fdd31bd.tar.bz2 rails-5b58cc4f443b61ab157bf9ff3cb478314fdd31bd.zip |
activerecord: Fix statement cache for strictly cast attributes
-rw-r--r-- | activerecord/lib/active_record/relation/query_attribute.rb | 2 | ||||
-rw-r--r-- | activerecord/test/cases/statement_cache_test.rb | 6 |
2 files changed, 7 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/relation/query_attribute.rb b/activerecord/lib/active_record/relation/query_attribute.rb index 5e0b4ac160..1dd6462d8d 100644 --- a/activerecord/lib/active_record/relation/query_attribute.rb +++ b/activerecord/lib/active_record/relation/query_attribute.rb @@ -32,7 +32,7 @@ module ActiveRecord if defined?(@_unboundable) @_unboundable else - value_for_database + value_for_database unless value_before_type_cast.is_a?(StatementCache::Substitute) @_unboundable = nil end rescue ::RangeError diff --git a/activerecord/test/cases/statement_cache_test.rb b/activerecord/test/cases/statement_cache_test.rb index e3c12f68fd..6a6d73dc38 100644 --- a/activerecord/test/cases/statement_cache_test.rb +++ b/activerecord/test/cases/statement_cache_test.rb @@ -4,6 +4,7 @@ require "cases/helper" require "models/book" require "models/liquid" require "models/molecule" +require "models/numeric_data" require "models/electron" module ActiveRecord @@ -74,6 +75,11 @@ module ActiveRecord assert_equal "salty", liquids[0].name end + def test_statement_cache_with_strictly_cast_attribute + row = NumericData.create(temperature: 1.5) + assert_equal row, NumericData.find_by(temperature: 1.5) + end + def test_statement_cache_values_differ cache = ActiveRecord::StatementCache.create(Book.connection) do |params| Book.where(name: "my book") |