Permalink
Browse files

Merge pull request #10730 from tkhr/add_test_for_AR__CounterCache#upd…

…ate_counters

Add test for AR::CounterCache.update_counters
  • Loading branch information...
2 parents dfafac9 + 805bad7 commit 37bacd3df278f65127fce14bd4d8e69b29dabf38 @carlosantoniodasilva carlosantoniodasilva committed Jun 26, 2013
Showing with 9 additions and 8 deletions.
  1. +9 −8 activerecord/test/cases/counter_cache_test.rb
@@ -51,14 +51,9 @@ class ::SpecialReply < ::Reply
end
end
- test 'reset multiple association counters' do
- Topic.increment_counter(:replies_count, @topic.id)
- assert_difference '@topic.reload.replies_count', -1 do
- Topic.reset_counters(@topic.id, :replies, :unique_replies)
- end
-
- Topic.increment_counter(:unique_replies_count, @topic.id)
- assert_difference '@topic.reload.unique_replies_count', -1 do
+ test 'reset multiple counters' do
+ Topic.update_counters @topic.id, replies_count: 1, unique_replies_count: 1
+ assert_difference ['@topic.reload.replies_count', '@topic.reload.unique_replies_count'], -1 do
Topic.reset_counters(@topic.id, :replies, :unique_replies)
end
end
@@ -127,6 +122,12 @@ class ::SpecialReply < ::Reply
end
end
+ test 'update multiple counters' do
+ assert_difference ['@topic.reload.replies_count', '@topic.reload.unique_replies_count'], 2 do
+ Topic.update_counters @topic.id, replies_count: 2, unique_replies_count: 2
+ end
+ end
+
test "update other counters on parent destroy" do
david, joanna = dog_lovers(:david, :joanna)
joanna = joanna # squelch a warning

0 comments on commit 37bacd3

Please sign in to comment.