Skip to content
Browse files

Ensure save always updates timestamps when serialized attributes are …

…present
  • Loading branch information...
1 parent c5c2e4f commit e911ed1f0f1633b0ae1b5146805eee6388b1f02f @lifo lifo committed Nov 2, 2010
Showing with 18 additions and 0 deletions.
  1. +4 −0 activerecord/lib/active_record/attribute_methods/dirty.rb
  2. +14 −0 activerecord/test/cases/dirty_test.rb
View
4 activerecord/lib/active_record/attribute_methods/dirty.rb
@@ -41,6 +41,10 @@ def reload(*) #:nodoc:
end
end
+ def changed?
+ super || (attributes.keys & self.class.serialized_attributes.keys).present?
+ end
+
private
# Wrap write_attribute to remember original attribute value.
def write_attribute(attr, value)
View
14 activerecord/test/cases/dirty_test.rb
@@ -395,6 +395,20 @@ def test_save_should_store_serialized_attributes_even_with_partial_updates
end
end
+ def test_save_always_should_update_timestamps_when_serialized_attributes_are_present
+ with_partial_updates(Topic) do
+ topic = Topic.create!(:content => {:a => "a"})
+ topic.save!
+
+ updated_at = topic.updated_at
+ topic.content[:hello] = 'world'
+ topic.save!
+
+ assert_not_equal updated_at, topic.updated_at
+ assert_equal 'world', topic.content[:hello]
+ 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"})

0 comments on commit e911ed1

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