Skip to content

Commit

Permalink
added testcase for belongs_to with a counter_cache and touch
Browse files Browse the repository at this point in the history
[#5365 state:committed]

Signed-off-by: Santiago Pastorino <santiago@wyeworks.com>
  • Loading branch information
amerine authored and spastorino committed Aug 17, 2010
1 parent b9281e8 commit fc43c62
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions activerecord/test/cases/timestamp_test.rb
Expand Up @@ -84,6 +84,22 @@ def test_saving_a_record_with_a_belongs_to_that_specifies_touching_a_specific_at
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
Expand Down

0 comments on commit fc43c62

Please sign in to comment.