diff options
author | Ryuta Kamizono <kamipo@gmail.com> | 2019-01-24 05:36:13 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-01-24 05:36:13 +0900 |
commit | 060fe164471213209de9637c19ee5c25492d0c1c (patch) | |
tree | c212a0bc05ca58db31e0a45966f773dae2c4394d | |
parent | d1456e3ad52cdab6d2fa07ef3f239631a20a9a1f (diff) | |
parent | 5b58cc4f443b61ab157bf9ff3cb478314fdd31bd (diff) | |
download | rails-060fe164471213209de9637c19ee5c25492d0c1c.tar.gz rails-060fe164471213209de9637c19ee5c25492d0c1c.tar.bz2 rails-060fe164471213209de9637c19ee5c25492d0c1c.zip |
Merge pull request #35029 from dylanahsmith/fix-strictly-cast-attribute-types
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") |