activerecord: Fix statement cache for strictly cast attributes

This commit is contained in:
Dylan Thacker-Smith 2019-01-23 10:15:06 -05:00
parent d1456e3ad5
commit 5b58cc4f44
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")