diff options
author | Jason Normore <jnormore@gmail.com> | 2014-03-19 12:24:46 -0400 |
---|---|---|
committer | Jason Normore <jnormore@gmail.com> | 2014-05-16 22:27:44 -0400 |
commit | fec7bfe8d13b7f5a076011364cf68e6ae56f03ff (patch) | |
tree | 60c08e8d88184ded69c648e2280513219ac0f9af /activerecord/test/cases/counter_cache_test.rb | |
parent | ada8e50ecde55123cc95dd62390ac46e29c52ec5 (diff) | |
download | rails-fec7bfe8d13b7f5a076011364cf68e6ae56f03ff.tar.gz rails-fec7bfe8d13b7f5a076011364cf68e6ae56f03ff.tar.bz2 rails-fec7bfe8d13b7f5a076011364cf68e6ae56f03ff.zip |
Updates reset_counters to allow counter name in params
Add support for counter name to be passed as parameter
on `CounterCache::ClassMethods#reset_counters`. This is
to be consistent with the other methods in the module
that all accept counter name.
Diffstat (limited to 'activerecord/test/cases/counter_cache_test.rb')
-rw-r--r-- | activerecord/test/cases/counter_cache_test.rb | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/activerecord/test/cases/counter_cache_test.rb b/activerecord/test/cases/counter_cache_test.rb index ee3d8a81c2..ab2a749ba8 100644 --- a/activerecord/test/cases/counter_cache_test.rb +++ b/activerecord/test/cases/counter_cache_test.rb @@ -51,6 +51,16 @@ class CounterCacheTest < ActiveRecord::TestCase end end + test "reset counters by counter name" do + # throw the count off by 1 + Topic.increment_counter(:replies_count, @topic.id) + + # check that it gets reset + assert_difference '@topic.reload.replies_count', -1 do + Topic.reset_counters(@topic.id, :replies_count) + end + end + 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 @@ -154,10 +164,10 @@ class CounterCacheTest < ActiveRecord::TestCase end end - test "the passed symbol needs to be an association name" do + test "the passed symbol needs to be an association name or counter name" do e = assert_raises(ArgumentError) do - Topic.reset_counters(@topic.id, :replies_count) + Topic.reset_counters(@topic.id, :undefined_count) end - assert_equal "'Topic' has no association called 'replies_count'", e.message + assert_equal "'Topic' has no association called 'undefined_count'", e.message end end |