Permalink
Browse files

Write the failing test case for concurrent counter cache

  • Loading branch information...
1 parent 0bccde9 commit dd063f6ef436b5e6a594e70eeb50532a09ef7a57 @byroot byroot committed Apr 13, 2014
Showing with 21 additions and 0 deletions.
  1. +21 −0 activerecord/test/cases/associations/belongs_to_associations_test.rb
@@ -502,6 +502,27 @@ def test_counter_cache_double_destroy
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]

0 comments on commit dd063f6

Please sign in to comment.