diff options
author | dm1try <dmitry.dedov@tut.by> | 2013-11-11 19:41:54 +0300 |
---|---|---|
committer | dm1try <dmitry.dedov@tut.by> | 2013-11-11 19:53:02 +0300 |
commit | dbb7ee1bfd16d9aabd3b3ed1a566c8752e9af3c0 (patch) | |
tree | 5876bd466300396612893a17e6746f9cabf049cc /activerecord/test/cases | |
parent | b31b6e669935cfa7e88e75c02dbd0892d1b9853e (diff) | |
download | rails-dbb7ee1bfd16d9aabd3b3ed1a566c8752e9af3c0.tar.gz rails-dbb7ee1bfd16d9aabd3b3ed1a566c8752e9af3c0.tar.bz2 rails-dbb7ee1bfd16d9aabd3b3ed1a566c8752e9af3c0.zip |
Prevent the counter cache from being decremented twice
when destroying a record on a has_many :through association.
:destroy method has own counter_cache callbacks.
Diffstat (limited to 'activerecord/test/cases')
-rw-r--r-- | activerecord/test/cases/associations/has_many_through_associations_test.rb | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/activerecord/test/cases/associations/has_many_through_associations_test.rb b/activerecord/test/cases/associations/has_many_through_associations_test.rb index c450b1beb5..47592f312e 100644 --- a/activerecord/test/cases/associations/has_many_through_associations_test.rb +++ b/activerecord/test/cases/associations/has_many_through_associations_test.rb @@ -514,6 +514,15 @@ class HasManyThroughAssociationsTest < ActiveRecord::TestCase assert_equal(post.taggings.count, post.taggings_count) end + def test_update_counter_caches_on_destroy + post = posts(:welcome) + tag = post.tags.create!(name: 'doomed') + + assert_difference 'post.reload.taggings_count', -1 do + tag.tagged_posts.destroy(post) + end + end + def test_replace_association assert_queries(4){posts(:welcome);people(:david);people(:michael); posts(:welcome).people(true)} |