mirror of
https://github.com/github/rails.git
synced 2026-04-26 03:00:59 -04:00
added testcase for belongs_to with a counter_cache and touch
[#5365 state:committed] Signed-off-by: Santiago Pastorino <santiago@wyeworks.com>
This commit is contained in:
committed by
Santiago Pastorino
parent
ad53b68457
commit
6177a0be96
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user