aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases
diff options
context:
space:
mode:
authorMatthew Robertson <matthewrobertson03@gmail.com>2012-12-01 17:56:28 -0800
committerMatthew Robertson <matthew@cloudclinic.ca>2012-12-14 10:03:05 -0800
commita765c8426fe39c73cf9f3ad7f8edcf588c01a11d (patch)
tree237335100d1015cb7b40f8b8eecc4afa38d78f53 /activerecord/test/cases
parent01d3a36bfe5d56d85f8a36f2fe10ad96662b4530 (diff)
downloadrails-a765c8426fe39c73cf9f3ad7f8edcf588c01a11d.tar.gz
rails-a765c8426fe39c73cf9f3ad7f8edcf588c01a11d.tar.bz2
rails-a765c8426fe39c73cf9f3ad7f8edcf588c01a11d.zip
Fix for has_many_through counter_cache bug
This commit fixes reported issue #7630 in which counter caches were not being updated properly when replacing has_many_through relationships
Diffstat (limited to 'activerecord/test/cases')
-rw-r--r--activerecord/test/cases/associations/has_many_through_associations_test.rb11
1 files changed, 11 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 8e52ce1d91..2b96b42032 100644
--- a/activerecord/test/cases/associations/has_many_through_associations_test.rb
+++ b/activerecord/test/cases/associations/has_many_through_associations_test.rb
@@ -330,6 +330,17 @@ class HasManyThroughAssociationsTest < ActiveRecord::TestCase
end
end
+ def test_update_counter_caches_on_replace_association
+ post = posts(:welcome)
+ tag = post.tags.create!(:name => 'doomed')
+ tag.tagged_posts << posts(:thinking)
+
+ tag.tagged_posts = []
+ post.reload
+
+ assert_equal(post.taggings.count, post.taggings_count)
+ end
+
def test_replace_association
assert_queries(4){posts(:welcome);people(:david);people(:michael); posts(:welcome).people(true)}