aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/associations
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2014-04-14 10:16:27 -0700
committerAaron Patterson <aaron.patterson@gmail.com>2014-04-14 10:16:27 -0700
commita1e2db2e9bb4ca2fdf6190aa8f448fe85cf76529 (patch)
tree15cae59a1040462eab651c52e30c5b25f59aed7a /activerecord/test/cases/associations
parent3bf8f8b05557c5661c9816f106c582fed1f10754 (diff)
parent655a3667aa99ae3f7e68024b3971b5783d6396bf (diff)
downloadrails-a1e2db2e9bb4ca2fdf6190aa8f448fe85cf76529.tar.gz
rails-a1e2db2e9bb4ca2fdf6190aa8f448fe85cf76529.tar.bz2
rails-a1e2db2e9bb4ca2fdf6190aa8f448fe85cf76529.zip
Merge pull request #14735 from byroot/idempotent-counter-caches
Idempotent counter caches, fix concurrency issues with counter caches
Diffstat (limited to 'activerecord/test/cases/associations')
-rw-r--r--activerecord/test/cases/associations/belongs_to_associations_test.rb21
1 files changed, 21 insertions, 0 deletions
diff --git a/activerecord/test/cases/associations/belongs_to_associations_test.rb b/activerecord/test/cases/associations/belongs_to_associations_test.rb
index bcd2b6dfaa..3b484a0d64 100644
--- a/activerecord/test/cases/associations/belongs_to_associations_test.rb
+++ b/activerecord/test/cases/associations/belongs_to_associations_test.rb
@@ -502,6 +502,27 @@ class BelongsToAssociationsTest < ActiveRecord::TestCase
assert_equal 4, topic.replies.size
end
+ def test_concurrent_counter_cache_double_destroy
+ topic = Topic.create :title => "Zoom-zoom-zoom"
+
+ 5.times do
+ topic.replies.create(:title => "re: zoom", :content => "speedy quick!")
+ end
+
+ assert_equal 5, topic.reload[:replies_count]
+ assert_equal 5, topic.replies.size
+
+ reply = topic.replies.first
+ reply_clone = Reply.find(reply.id)
+
+ reply.destroy
+ assert_equal 4, topic.reload[:replies_count]
+
+ reply_clone.destroy
+ assert_equal 4, topic.reload[:replies_count]
+ assert_equal 4, topic.replies.size
+ end
+
def test_custom_counter_cache
reply = Reply.create(:title => "re: zoom", :content => "speedy quick!")
assert_equal 0, reply[:replies_count]