mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Don't treat nil
as changed in serialized types
We were ignoring the `default_value?` escape clause in the serialized type, which caused the default value to always be treated as changed. Fixes #18169
This commit is contained in:
parent
d26704a15f
commit
e35221cfd9
2 changed files with 9 additions and 1 deletions
|
@ -29,7 +29,7 @@ module ActiveRecord
|
|||
|
||||
def changed_in_place?(raw_old_value, value)
|
||||
return false if value.nil?
|
||||
subtype.changed_in_place?(raw_old_value, coder.dump(value))
|
||||
subtype.changed_in_place?(raw_old_value, type_cast_for_database(value))
|
||||
end
|
||||
|
||||
def accessor
|
||||
|
|
|
@ -256,4 +256,12 @@ class SerializedAttributeTest < ActiveRecord::TestCase
|
|||
assert_equal("second", t.content)
|
||||
assert_equal("second", t.reload.content)
|
||||
end
|
||||
|
||||
def test_nil_is_not_changed_when_serialized_with_a_class
|
||||
Topic.serialize(:content, Array)
|
||||
|
||||
topic = Topic.new(content: nil)
|
||||
|
||||
assert_not topic.content_changed?
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue