提交 95962c4f 编写于 作者: S Sean Griffin 提交者: GitHub

Merge pull request #27517 from maclover7/jm-fix-27502

Compare deserialized values for `PostgreSQL::OID::Hstore` types
* Compare deserialized values for `PostgreSQL::OID::Hstore` types when
calling `ActiveRecord::Dirty#changed_in_place?`
Fixes #27502.
*Jon Moss*
* Raise `ArgumentError` when passing an `ActiveRecord::Base` instance to `.find`
and `.exists?`.
......
......@@ -35,6 +35,14 @@ def accessor
ActiveRecord::Store::StringKeyedHashAccessor
end
# Will compare the Hash equivalents of +raw_old_value+ and +new_value+.
# By comparing hashes, this avoids an edge case where the order of
# the keys change between the two hashes, and they would not be marked
# as equal.
def changed_in_place?(raw_old_value, new_value)
deserialize(raw_old_value) != new_value
end
private
HstorePair = begin
......
......@@ -171,6 +171,25 @@ def test_changes_in_place
assert_not hstore.changed?
end
def test_dirty_from_user_equal
settings = { "alongkey" => "anything", "key" => "value" }
hstore = Hstore.create!(settings: settings)
hstore.settings = { "key" => "value", "alongkey" => "anything" }
assert_equal settings, hstore.settings
refute hstore.changed?
end
def test_hstore_dirty_from_database_equal
settings = { "alongkey" => "anything", "key" => "value" }
hstore = Hstore.create!(settings: settings)
hstore.reload
assert_equal settings, hstore.settings
hstore.settings = settings
refute hstore.changed?
end
def test_gen1
assert_equal('" "=>""', @type.serialize(" " => ""))
end
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册