diff options
author | PikachuEXE <pikachuexe@gmail.com> | 2013-01-30 12:55:37 +0800 |
---|---|---|
committer | Adam Gamble <adamgamble@gmail.com> | 2013-03-14 12:45:56 -0500 |
commit | 7fc339059cbace0af8f8dbfb5c68db3f5dffd5a3 (patch) | |
tree | f0e12b9ffef95ef21bb8b6911e6091781e47fb73 /activerecord/test | |
parent | 36f7732e820ce4d3c4a46bd0a1b15fd8902467b3 (diff) | |
download | rails-7fc339059cbace0af8f8dbfb5c68db3f5dffd5a3.tar.gz rails-7fc339059cbace0af8f8dbfb5c68db3f5dffd5a3.tar.bz2 rails-7fc339059cbace0af8f8dbfb5c68db3f5dffd5a3.zip |
+ Add test for auto timestamps update of both old & new parent records
Diffstat (limited to 'activerecord/test')
-rw-r--r-- | activerecord/test/cases/timestamp_test.rb | 34 | ||||
-rw-r--r-- | activerecord/test/fixtures/toys.yml | 4 |
2 files changed, 38 insertions, 0 deletions
diff --git a/activerecord/test/cases/timestamp_test.rb b/activerecord/test/cases/timestamp_test.rb index 777a2b70dd..6f983bce75 100644 --- a/activerecord/test/cases/timestamp_test.rb +++ b/activerecord/test/cases/timestamp_test.rb @@ -176,6 +176,40 @@ 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_and_grandparent_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 + old_owner = old_pet.owner + + toy2 = klass.find(2) + new_pet = toy2.pet + new_owner = new_pet.owner + time = 3.days.ago + + old_pet.update_columns(updated_at: time) + old_owner.update_columns(updated_at: time) + new_pet.update_columns(updated_at: time) + new_owner.update_columns(updated_at: time) + + toy1.pet = new_pet + toy1.save! + + old_pet.reload + old_owner.reload + new_pet.reload + new_owner.reload + + assert_not_equal time, old_pet.updated_at + assert_not_equal time, old_owner.updated_at + assert_not_equal time, new_pet.updated_at + assert_not_equal time, new_owner.updated_at + end + def test_timestamp_attributes_for_create toy = Toy.first assert_equal toy.send(:timestamp_attributes_for_create), [:created_at, :created_on] diff --git a/activerecord/test/fixtures/toys.yml b/activerecord/test/fixtures/toys.yml index 037e335e0a..07ed75e98e 100644 --- a/activerecord/test/fixtures/toys.yml +++ b/activerecord/test/fixtures/toys.yml @@ -2,3 +2,7 @@ bone: toy_id: 1 name: Bone pet_id: 1 +doll: + toy_id: 2 + name: Doll + pet_id: 2 |