aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/timestamp_test.rb
diff options
context:
space:
mode:
authorMark Turner <mark@amerine.net>2010-08-12 09:43:15 -0700
committerSantiago Pastorino <santiago@wyeworks.com>2010-08-16 22:41:12 -0300
commit6177a0be96cebac129d0e20d2b5ec009a00fa56c (patch)
tree5cb46459f07c38143bd866f12208271a3c8bc6b6 /activerecord/test/cases/timestamp_test.rb
parentad53b68457af0f3c4e875309f298335a17b9029c (diff)
downloadrails-6177a0be96cebac129d0e20d2b5ec009a00fa56c.tar.gz
rails-6177a0be96cebac129d0e20d2b5ec009a00fa56c.tar.bz2
rails-6177a0be96cebac129d0e20d2b5ec009a00fa56c.zip
added testcase for belongs_to with a counter_cache and touch
[#5365 state:committed] Signed-off-by: Santiago Pastorino <santiago@wyeworks.com>
Diffstat (limited to 'activerecord/test/cases/timestamp_test.rb')
-rw-r--r--activerecord/test/cases/timestamp_test.rb16
1 files changed, 16 insertions, 0 deletions
diff --git a/activerecord/test/cases/timestamp_test.rb b/activerecord/test/cases/timestamp_test.rb
index 597b954d84..f5f116f3e6 100644
--- a/activerecord/test/cases/timestamp_test.rb
+++ b/activerecord/test/cases/timestamp_test.rb
@@ -84,6 +84,22 @@ class TimestampTest < ActiveRecord::TestCase
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
Pet.belongs_to :owner, :touch => true