diff options
author | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2013-05-06 22:22:07 -0300 |
---|---|---|
committer | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2013-05-06 22:22:07 -0300 |
commit | 19d32e89af09af4a6f7c7b49f57f4e4d1ef02b10 (patch) | |
tree | 11003cf01ec859d9755cce6cf7c6c02adc7ac800 /activerecord/test/cases/associations/belongs_to_associations_test.rb | |
parent | 8d85baa0e317c5baa3b8671d7fdd79e36f7058c7 (diff) | |
parent | 228720ef19e7dcf7c21f4ef2171906cc7c8c97f1 (diff) | |
download | rails-19d32e89af09af4a6f7c7b49f57f4e4d1ef02b10.tar.gz rails-19d32e89af09af4a6f7c7b49f57f4e4d1ef02b10.tar.bz2 rails-19d32e89af09af4a6f7c7b49f57f4e4d1ef02b10.zip |
Merge pull request #10489 from greenriver/ar_counter_cache_multiple_destroy
Confirm a record has not already been destroyed before decrementing counter cache
Conflicts:
activerecord/CHANGELOG.md
Diffstat (limited to 'activerecord/test/cases/associations/belongs_to_associations_test.rb')
-rw-r--r-- | activerecord/test/cases/associations/belongs_to_associations_test.rb | 20 |
1 files changed, 20 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 f5316952b8..87af24cbe6 100644 --- a/activerecord/test/cases/associations/belongs_to_associations_test.rb +++ b/activerecord/test/cases/associations/belongs_to_associations_test.rb @@ -414,6 +414,26 @@ class BelongsToAssociationsTest < ActiveRecord::TestCase assert_equal 15, topic.replies.size end + def test_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.destroy + assert_equal 4, topic.reload[:replies_count] + + reply.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] |