From 18ce894d87388d8f8d0109c6eec9d17e3636ae32 Mon Sep 17 00:00:00 2001 From: Federico Brubacher Date: Sat, 15 May 2010 13:55:34 -0300 Subject: [PATCH] AR::Base clone now marks clones as dirty --- activerecord/lib/active_record/base.rb | 2 +- activerecord/test/cases/dirty_test.rb | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletions(-) diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb index 04c474c..810bb1d 100755 --- a/activerecord/lib/active_record/base.rb +++ b/activerecord/lib/active_record/base.rb @@ -1462,7 +1462,7 @@ module ActiveRecord #:nodoc: callback(:after_initialize) if respond_to_without_attributes?(:after_initialize) cloned_attributes = other.clone_attributes(:read_attribute_before_type_cast) cloned_attributes.delete(self.class.primary_key) - @attributes = cloned_attributes + @attributes = cloned_attributes.each { |attr,value| self.send("#{attr}_will_change!") if !value.blank? } clear_aggregation_cache @attributes_cache = {} @new_record = true diff --git a/activerecord/test/cases/dirty_test.rb b/activerecord/test/cases/dirty_test.rb index 7a17ef1..0878f30 100644 --- a/activerecord/test/cases/dirty_test.rb +++ b/activerecord/test/cases/dirty_test.rb @@ -338,6 +338,19 @@ class DirtyTest < ActiveRecord::TestCase assert !pirate.changed? end + def test_cloned_object_should_threat_as_changed_only_non_blank_default_attributes + pirate = Pirate.new + pirate_cloned = pirate.clone + assert !pirate_cloned.catchphrase_changed? + end + + def test_cloned_models_should_be_dirty + phrase = "shiver me timbers" + pirate = Pirate.create!(:catchphrase => phrase) + pirate_cloned = pirate.clone + assert pirate_cloned.changed? + end + def test_reverted_changes_are_not_dirty phrase = "shiver me timbers" pirate = Pirate.create!(:catchphrase => phrase) -- 1.7.0.5