a cloned object no longer mimics changed flags from creator , plus a test case [#4614 state:resolved]

Signed-off-by: José Valim <jose.valim@gmail.com>
This commit is contained in:
Federico Brubacher 2010-05-16 07:24:41 -03:00 committed by José Valim
parent ade756fe42
commit 6b4e0cc526
3 changed files with 15 additions and 4 deletions

View File

@ -124,11 +124,12 @@ module ActiveModel
@previously_changed
end
# Map of change <tt>attr => original value</tt>.
def changed_attributes
@changed_attributes ||= {}
end
private
# Map of change <tt>attr => original value</tt>.
def changed_attributes
@changed_attributes ||= {}
end
# Handle <tt>*_changed?</tt> for +method_missing+.
def attribute_changed?(attr)

View File

@ -1467,6 +1467,7 @@ module ActiveRecord #:nodoc:
@attributes_cache = {}
@new_record = true
ensure_proper_type
@changed_attributes = other.changed_attributes.dup
if scope = self.class.send(:current_scoped_methods)
create_with = scope.scope_for_create

View File

@ -338,6 +338,15 @@ class DirtyTest < ActiveRecord::TestCase
assert !pirate.changed?
end
def test_cloned_objects_should_not_copy_dirty_flag_from_creator
pirate = Pirate.create!(:catchphrase => "shiver me timbers")
pirate_clone = pirate.clone
pirate_clone.reset_catchphrase!
pirate.catchphrase = "I love Rum"
assert pirate.catchphrase_changed?
assert !pirate_clone.catchphrase_changed?
end
def test_reverted_changes_are_not_dirty
phrase = "shiver me timbers"
pirate = Pirate.create!(:catchphrase => phrase)