1
0
Fork 0
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:
Rafael França 2018-06-06 13:17:53 -04:00 committed by GitHub
commit 86e42b5366
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 11 additions and 1 deletions

View file

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

View file

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

View file

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