Permalink
Browse files

Serialized attributes should only be saved with partial_updates when …

…the serialized attribute is present [#2397 state:resolved]

Signed-off-by: Pratik Naik <pratiknaik@gmail.com>
  • Loading branch information...
1 parent 5e4b946 commit 8056c57a94a2cbbbeb662ebe5b0cc6aa0ca1ef00 @hardbap hardbap committed with lifo Aug 9, 2009
Showing with 11 additions and 1 deletion.
  1. +1 −1 activerecord/lib/active_record/dirty.rb
  2. +10 −0 activerecord/test/cases/dirty_test.rb
View
2 activerecord/lib/active_record/dirty.rb
@@ -143,7 +143,7 @@ def update_with_dirty
if partial_updates?
# Serialized attributes should always be written in case they've been
# changed in place.
- update_without_dirty(changed | self.class.serialized_attributes.keys)
+ update_without_dirty(changed | (attributes.keys & self.class.serialized_attributes.keys))
else
update_without_dirty
end
View
10 activerecord/test/cases/dirty_test.rb
@@ -288,6 +288,16 @@ def test_save_should_store_serialized_attributes_even_with_partial_updates
end
end
+ def test_save_should_not_save_serialized_attribute_with_partial_updates_if_not_present
+ with_partial_updates(Topic) do
+ Topic.create!(:author_name => 'Bill', :content => {:a => "a"})
+ topic = Topic.first(:select => 'id, author_name')
+ topic.update_attribute :author_name, 'John'
+ topic = Topic.first
+ assert_not_nil topic.content
+ end
+ end
+
private
def with_partial_updates(klass, on = true)
old = klass.partial_updates?

0 comments on commit 8056c57

Please sign in to comment.