mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Merge pull request #33067 from kamipo/fix_force_equality
Fix force equality checking not to break the serialized attribute with Array
This commit is contained in:
commit
86e42b5366
3 changed files with 11 additions and 1 deletions
|
@ -48,7 +48,6 @@ module ActiveRecord
|
|||
end
|
||||
|
||||
def build(attribute, value)
|
||||
# FIXME: Deprecate this and provide a public API to force equality
|
||||
if table.type(attribute.name).force_equality?(value)
|
||||
bind = build_bind_attribute(attribute.name, value)
|
||||
attribute.eq(bind)
|
||||
|
|
|
@ -51,6 +51,10 @@ module ActiveRecord
|
|||
end
|
||||
end
|
||||
|
||||
def force_equality?(value)
|
||||
coder.respond_to?(:object_class) && value.is_a?(coder.object_class)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def default_value?(value)
|
||||
|
|
|
@ -159,6 +159,13 @@ class SerializedAttributeTest < ActiveRecord::TestCase
|
|||
assert_equal(settings, Topic.find(topic.id).content)
|
||||
end
|
||||
|
||||
def test_where_by_serialized_attribute_with_array
|
||||
settings = [ "color" => "green" ]
|
||||
Topic.serialize(:content, Array)
|
||||
topic = Topic.create!(content: settings)
|
||||
assert_equal topic, Topic.where(content: settings).take
|
||||
end
|
||||
|
||||
def test_where_by_serialized_attribute_with_hash
|
||||
settings = { "color" => "green" }
|
||||
Topic.serialize(:content, Hash)
|
||||
|
|
Loading…
Reference in a new issue