mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Serialized attributes will now always be saved even with partial_updates turned on.
Signed-off-by: Michael Koziarski <michael@koziarski.com> [#788 state:committed]
This commit is contained in:
parent
81c12d1f63
commit
992fda16ed
2 changed files with 15 additions and 1 deletions
|
@ -134,7 +134,9 @@ module ActiveRecord
|
|||
|
||||
def update_with_dirty
|
||||
if partial_updates?
|
||||
update_without_dirty(changed)
|
||||
# Serialized attributes should always be written in case they've been
|
||||
# changed in place.
|
||||
update_without_dirty(changed | self.class.serialized_attributes.keys)
|
||||
else
|
||||
update_without_dirty
|
||||
end
|
||||
|
|
|
@ -191,6 +191,18 @@ class DirtyTest < ActiveRecord::TestCase
|
|||
assert !pirate.changed?
|
||||
end
|
||||
|
||||
def test_save_should_store_serialized_attributes_even_with_partial_updates
|
||||
with_partial_updates(Topic) do
|
||||
topic = Topic.create!(:content => {:a => "a"})
|
||||
topic.content[:b] = "b"
|
||||
#assert topic.changed? # Known bug, will fail
|
||||
topic.save!
|
||||
assert_equal "b", topic.content[:b]
|
||||
topic.reload
|
||||
assert_equal "b", topic.content[:b]
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
def with_partial_updates(klass, on = true)
|
||||
old = klass.partial_updates?
|
||||
|
|
Loading…
Reference in a new issue