Skip to content
Browse files

Serialized attributes will now always be saved even with partial_upda…

…tes turned on.

Signed-off-by: Michael Koziarski <michael@koziarski.com>
[#788 state:committed]
  • Loading branch information...
1 parent 88eec83 commit decc9730959de85b4c4873986bcd33e12fa1985d @cwninja cwninja committed with NZKoz
Showing with 15 additions and 1 deletion.
  1. +3 −1 activerecord/lib/active_record/dirty.rb
  2. +12 −0 activerecord/test/cases/dirty_test.rb
View
4 activerecord/lib/active_record/dirty.rb
@@ -134,7 +134,9 @@ def write_attribute_with_dirty(attr, value)
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
View
12 activerecord/test/cases/dirty_test.rb
@@ -191,6 +191,18 @@ def test_reload_should_clear_changed_attributes
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?

0 comments on commit decc973

Please sign in to comment.
Something went wrong with that request. Please try again.