aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorRafael França <rafaelmfranca@gmail.com>2018-06-06 13:17:53 -0400
committerGitHub <noreply@github.com>2018-06-06 13:17:53 -0400
commit86e42b53662f535ee484630144e27ee684e8e8dc (patch)
tree60675e63b94b8a8e8c7b50911abe1cfeca34b97a /activerecord
parent03eadaec4025490d2751ca96338602e701e0f52b (diff)
parent702b1768c425e7187ef4c62beb1ed12ed7774d83 (diff)
downloadrails-86e42b53662f535ee484630144e27ee684e8e8dc.tar.gz
rails-86e42b53662f535ee484630144e27ee684e8e8dc.tar.bz2
rails-86e42b53662f535ee484630144e27ee684e8e8dc.zip
Merge pull request #33067 from kamipo/fix_force_equality
Fix force equality checking not to break the serialized attribute with Array
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/lib/active_record/relation/predicate_builder.rb1
-rw-r--r--activerecord/lib/active_record/type/serialized.rb4
-rw-r--r--activerecord/test/cases/serialized_attribute_test.rb7
3 files changed, 11 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/relation/predicate_builder.rb b/activerecord/lib/active_record/relation/predicate_builder.rb
index 4a4ceca782..f734cd0ad8 100644
--- a/activerecord/lib/active_record/relation/predicate_builder.rb
+++ b/activerecord/lib/active_record/relation/predicate_builder.rb
@@ -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)
diff --git a/activerecord/lib/active_record/type/serialized.rb b/activerecord/lib/active_record/type/serialized.rb
index e882784691..0a2f6cb9fb 100644
--- a/activerecord/lib/active_record/type/serialized.rb
+++ b/activerecord/lib/active_record/type/serialized.rb
@@ -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)
diff --git a/activerecord/test/cases/serialized_attribute_test.rb b/activerecord/test/cases/serialized_attribute_test.rb
index 7764a37273..4cd4515c3b 100644
--- a/activerecord/test/cases/serialized_attribute_test.rb
+++ b/activerecord/test/cases/serialized_attribute_test.rb
@@ -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)