1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Ensure save always updates timestamps when serialized attributes are present

This commit is contained in:
Pratik Naik 2010-11-02 01:42:47 +00:00
parent c5c2e4fefd
commit e911ed1f0f
2 changed files with 18 additions and 0 deletions

View file

@ -41,6 +41,10 @@ module ActiveRecord
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 file

@ -395,6 +395,20 @@ class DirtyTest < ActiveRecord::TestCase
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"})