aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/associations/has_many_associations_test.rb
diff options
context:
space:
mode:
authorMatthew Robertson <matthewrobertson03@gmail.com>2013-04-21 12:49:50 -0700
committerMatthew Robertson <matthewrobertson03@gmail.com>2013-04-21 18:34:11 -0700
commit1e27f1c5d5d177089fbda03ba31f2f55fa622a39 (patch)
treeb95d040058ff2308eebca0a542bd651cead55fa6 /activerecord/test/cases/associations/has_many_associations_test.rb
parentfae07a81badb3067a3ebdd7d81aa22625186329e (diff)
downloadrails-1e27f1c5d5d177089fbda03ba31f2f55fa622a39.tar.gz
rails-1e27f1c5d5d177089fbda03ba31f2f55fa622a39.tar.bz2
rails-1e27f1c5d5d177089fbda03ba31f2f55fa622a39.zip
Update counter cache when pushing into association
This commit fixes a regression bug in which counter_cache columns were not being updated correctly when newly created records were being pushed into an assocation. EG: # this was fine @post.comment.create! # this was fine @comment = Comment.first @post.comments << @comment # this would not update counters @post.comments << Comment.create!
Diffstat (limited to 'activerecord/test/cases/associations/has_many_associations_test.rb')
-rw-r--r--activerecord/test/cases/associations/has_many_associations_test.rb9
1 files changed, 9 insertions, 0 deletions
diff --git a/activerecord/test/cases/associations/has_many_associations_test.rb b/activerecord/test/cases/associations/has_many_associations_test.rb
index 781b87741d..d85570236f 100644
--- a/activerecord/test/cases/associations/has_many_associations_test.rb
+++ b/activerecord/test/cases/associations/has_many_associations_test.rb
@@ -755,6 +755,15 @@ class HasManyAssociationsTest < ActiveRecord::TestCase
assert_equal topic.replies.to_a.size, topic.replies_count
end
+ def test_pushing_association_updates_counter_cache
+ topic = Topic.order("id ASC").first
+ reply = Reply.create!
+
+ assert_difference "topic.reload.replies_count", 1 do
+ topic.replies << reply
+ end
+ end
+
def test_deleting_updates_counter_cache_without_dependent_option
post = posts(:welcome)