Merge pull request #35029 from dylanahsmith/fix-strictly-cast-attribute-types

activerecord: Fix statement cache for strictly cast attributes
This commit is contained in:
Ryuta Kamizono 2019-01-24 05:36:13 +09:00 committed by GitHub
commit 060fe16447
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 1 deletions

View File

@ -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

View File

@ -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")