diff options
author | Eugene Kenny <elkenny@gmail.com> | 2018-01-14 20:46:19 +0000 |
---|---|---|
committer | Eugene Kenny <elkenny@gmail.com> | 2018-01-14 20:46:19 +0000 |
commit | 3e71bc4b048bef2ae7723dde5082020fd984bbd6 (patch) | |
tree | 988395bcd199720560661a316b8c2ee99b44c984 /activerecord/test/cases/associations | |
parent | fd04c8cbb6627ef65ea728b5026b21bd24471c18 (diff) | |
download | rails-3e71bc4b048bef2ae7723dde5082020fd984bbd6.tar.gz rails-3e71bc4b048bef2ae7723dde5082020fd984bbd6.tar.bz2 rails-3e71bc4b048bef2ae7723dde5082020fd984bbd6.zip |
Don't update counter cache when through record was not destroyed
When removing a record from a has many through association, the counter
cache was being updated even if the through record halted the callback
chain and prevented itself from being destroyed.
Diffstat (limited to 'activerecord/test/cases/associations')
-rw-r--r-- | activerecord/test/cases/associations/has_many_through_associations_test.rb | 10 |
1 files changed, 10 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 56a4b7c4d1..dabeeff1be 100644 --- a/activerecord/test/cases/associations/has_many_through_associations_test.rb +++ b/activerecord/test/cases/associations/has_many_through_associations_test.rb @@ -538,6 +538,16 @@ class HasManyThroughAssociationsTest < ActiveRecord::TestCase end end + def test_update_counter_caches_on_destroy_with_indestructible_through_record + post = posts(:welcome) + tag = post.indestructible_tags.create!(name: "doomed") + post.update_columns(indestructible_tags_count: post.indestructible_tags.count) + + assert_no_difference "post.reload.indestructible_tags_count" do + posts(:welcome).indestructible_tags.destroy(tag) + end + end + def test_replace_association assert_queries(4) { posts(:welcome);people(:david);people(:michael); posts(:welcome).people.reload } |