diff options
author | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2014-05-17 16:21:41 -0300 |
---|---|---|
committer | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2014-05-17 16:21:41 -0300 |
commit | 067131524b5b5cb6100aca8bf5b48a3006a93acd (patch) | |
tree | 365807e82aa8bae4dcecf86396fb4f53d2039b08 /activerecord/test/cases | |
parent | 7caf3ffffd368926f78e30a371d17a524c9fb13e (diff) | |
parent | fec7bfe8d13b7f5a076011364cf68e6ae56f03ff (diff) | |
download | rails-067131524b5b5cb6100aca8bf5b48a3006a93acd.tar.gz rails-067131524b5b5cb6100aca8bf5b48a3006a93acd.tar.bz2 rails-067131524b5b5cb6100aca8bf5b48a3006a93acd.zip |
Merge pull request #14428 from jnormore/reset_counters_alias
Updates reset_counters to allow counter name in params
Diffstat (limited to 'activerecord/test/cases')
-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 |