diff options
author | Andrew White <andyw@pixeltrix.co.uk> | 2013-04-24 13:37:33 +0100 |
---|---|---|
committer | Andrew White <andyw@pixeltrix.co.uk> | 2013-04-24 15:07:39 +0100 |
commit | 1a30cfec2ff6257792dde20105f5986398e2acd3 (patch) | |
tree | 8a3e38523e2573aedcdbacb8e442219b3706c3af /activerecord/test/cases | |
parent | ed5caf0993ac3504c0216ec65d8800f14daeafa4 (diff) | |
download | rails-1a30cfec2ff6257792dde20105f5986398e2acd3.tar.gz rails-1a30cfec2ff6257792dde20105f5986398e2acd3.tar.bz2 rails-1a30cfec2ff6257792dde20105f5986398e2acd3.zip |
Revert "Revert "`belongs_to :touch` behavior now touches old association when transitioning to new association" until a proper fix is found for #10197"
This reverts commit 7389df139a35436f00876c96d20e81ba23c93f0a.
Conflicts:
activerecord/test/cases/timestamp_test.rb
Diffstat (limited to 'activerecord/test/cases')
-rw-r--r-- | activerecord/test/cases/timestamp_test.rb | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/activerecord/test/cases/timestamp_test.rb b/activerecord/test/cases/timestamp_test.rb index 777a2b70dd..9d84f64c96 100644 --- a/activerecord/test/cases/timestamp_test.rb +++ b/activerecord/test/cases/timestamp_test.rb @@ -176,6 +176,52 @@ class TimestampTest < ActiveRecord::TestCase assert_not_equal time, owner.updated_at end + def test_changing_parent_of_a_record_touches_both_new_and_old_parent_record + klass = Class.new(ActiveRecord::Base) do + def self.name; 'Toy'; end + belongs_to :pet, touch: true + end + + toy1 = klass.find(1) + old_pet = toy1.pet + + toy2 = klass.find(2) + new_pet = toy2.pet + time = 3.days.ago.at_beginning_of_hour + + old_pet.update_columns(updated_at: time) + new_pet.update_columns(updated_at: time) + + toy1.pet = new_pet + toy1.save! + + old_pet.reload + new_pet.reload + + assert_not_equal time, new_pet.updated_at + assert_not_equal time, old_pet.updated_at + end + + def test_clearing_association_touches_the_old_record + klass = Class.new(ActiveRecord::Base) do + def self.name; 'Toy'; end + belongs_to :pet, touch: true + end + + toy = klass.find(1) + pet = toy.pet + time = 3.days.ago.at_beginning_of_hour + + pet.update_columns(updated_at: time) + + toy.pet = nil + toy.save! + + pet.reload + + assert_not_equal time, pet.updated_at + end + def test_timestamp_attributes_for_create toy = Toy.first assert_equal toy.send(:timestamp_attributes_for_create), [:created_at, :created_on] |