Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
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...
commit 8056c57a94a2cbbbeb662ebe5b0cc6aa0ca1ef00 1 parent 5e4b946
@hardbap hardbap authored lifo committed
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?
Please sign in to comment.
Something went wrong with that request. Please try again.