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:
commit
37bacd3df2
1 changed files with 9 additions and 8 deletions
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue