From 6641cdd0d0dad6e7f661bd74f31b9351f688a061 Mon Sep 17 00:00:00 2001 From: Mark Turner Date: Thu, 12 Aug 2010 09:43:15 -0700 Subject: [PATCH] added testcase for belongs_to with a counter_cache and touch -- originated from #5365 --- activerecord/test/cases/timestamp_test.rb | 16 ++++++++++++++++ 1 files changed, 16 insertions(+), 0 deletions(-) diff --git a/activerecord/test/cases/timestamp_test.rb b/activerecord/test/cases/timestamp_test.rb index 4014399..4bee63a 100644 --- a/activerecord/test/cases/timestamp_test.rb +++ b/activerecord/test/cases/timestamp_test.rb @@ -83,6 +83,22 @@ class TimestampTest < ActiveRecord::TestCase ensure Pet.belongs_to :owner, :touch => true end + + def test_touching_a_record_with_a_belongs_to_that_uses_a_counter_cache_should_update_the_parent + Pet.belongs_to :owner, :counter_cache => :use_count, :touch => true + + pet = Pet.first + owner = pet.owner + owner.update_attribute(:happy_at, (time = 3.days.ago)) + previously_owner_updated_at = owner.updated_at + + pet.name = "I'm a parrot" + pet.save + + assert_not_equal previously_owner_updated_at, pet.owner.updated_at + ensure + Pet.belongs_to :owner, :counter_cache => :use_count, :touch => true + end def test_touching_a_record_touches_parent_record_and_grandparent_record Toy.belongs_to :pet, :touch => true -- 1.7.1