mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Make sure to persist a newly-nil serialized value
The subtype will (quite reasonably) ignore the possibility that it has `changed_in_place?` by becoming nil. Fixes #19467
This commit is contained in:
parent
0347280035
commit
8b96c0b7a3
3 changed files with 20 additions and 1 deletions
|
@ -1,3 +1,10 @@
|
|||
* Correctly persist a serialized attribute that has been returned to
|
||||
its default value by an in-place modification.
|
||||
|
||||
Fixes #19467.
|
||||
|
||||
*Matthew Draper*
|
||||
|
||||
* Fix generating the schema file when using PostgreSQL `BigInt[]` data type.
|
||||
Previously the `limit: 8` was not coming through, and this caused it to
|
||||
become `Int[]` data type after rebuilding from the schema.
|
||||
|
|
|
@ -28,7 +28,9 @@ module ActiveRecord
|
|||
|
||||
def changed_in_place?(raw_old_value, value)
|
||||
return false if value.nil?
|
||||
subtype.changed_in_place?(raw_old_value, serialize(value))
|
||||
raw_new_value = serialize(value)
|
||||
raw_old_value.nil? != raw_new_value.nil? ||
|
||||
subtype.changed_in_place?(raw_old_value, raw_new_value)
|
||||
end
|
||||
|
||||
def accessor
|
||||
|
|
|
@ -264,4 +264,14 @@ class SerializedAttributeTest < ActiveRecord::TestCase
|
|||
Topic.serialize(:content, Regexp)
|
||||
end
|
||||
end
|
||||
|
||||
def test_newly_emptied_serialized_hash_is_changed
|
||||
Topic.serialize(:content, Hash)
|
||||
topic = Topic.create(content: { "things" => "stuff" })
|
||||
topic.content.delete("things")
|
||||
topic.save!
|
||||
topic.reload
|
||||
|
||||
assert_equal({}, topic.content)
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue