1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Merge pull request #10730 from tkhr/add_test_for_AR__CounterCache#update_counters

Add test for AR::CounterCache.update_counters
This commit is contained in:
Carlos Antonio da Silva 2013-06-25 17:29:33 -07:00
commit 37bacd3df2

View file

@ -51,14 +51,9 @@ class CounterCacheTest < ActiveRecord::TestCase
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 CounterCacheTest < ActiveRecord::TestCase
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