aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/counter_cache_test.rb
diff options
context:
space:
mode:
authorCade Truitt <cadetruitt@gmail.com>2014-07-02 20:09:05 -0500
committerCade Truitt <cadetruitt@gmail.com>2014-07-02 20:21:36 -0500
commitc8e48f08d528c0e4537bf1df1adac1fa8f4f48ff (patch)
treefa232948dc2392cc6fa846377cb167fc494f327d /activerecord/test/cases/counter_cache_test.rb
parentbeab403fc31199bbb01f1e6e1ba0f839af047afe (diff)
downloadrails-c8e48f08d528c0e4537bf1df1adac1fa8f4f48ff.tar.gz
rails-c8e48f08d528c0e4537bf1df1adac1fa8f4f48ff.tar.bz2
rails-c8e48f08d528c0e4537bf1df1adac1fa8f4f48ff.zip
Add `:all` argument to `count` in `reset_counters`
Prior to this fix, if an association had a scope with a `select`, calls to `reset_counters` would generate invalid SQL and throw: ActiveRecord::StatementInvalid: [$DB_ADAPTER]: wrong number of arguments to function COUNT() References #10710, #13648
Diffstat (limited to 'activerecord/test/cases/counter_cache_test.rb')
-rw-r--r--activerecord/test/cases/counter_cache_test.rb10
1 files changed, 10 insertions, 0 deletions
diff --git a/activerecord/test/cases/counter_cache_test.rb b/activerecord/test/cases/counter_cache_test.rb
index ab2a749ba8..07a182070b 100644
--- a/activerecord/test/cases/counter_cache_test.rb
+++ b/activerecord/test/cases/counter_cache_test.rb
@@ -19,6 +19,7 @@ class CounterCacheTest < ActiveRecord::TestCase
class ::SpecialTopic < ::Topic
has_many :special_replies, :foreign_key => 'parent_id'
+ has_many :lightweight_special_replies, -> { select('topics.id, topics.title') }, :foreign_key => 'parent_id', :class_name => 'SpecialReply'
end
class ::SpecialReply < ::Reply
@@ -170,4 +171,13 @@ class CounterCacheTest < ActiveRecord::TestCase
end
assert_equal "'Topic' has no association called 'undefined_count'", e.message
end
+
+ test "reset counter works with select declared on association" do
+ special = SpecialTopic.create!(:title => 'Special')
+ SpecialTopic.increment_counter(:replies_count, special.id)
+
+ assert_difference 'special.reload.replies_count', -1 do
+ SpecialTopic.reset_counters(special.id, :lightweight_special_replies)
+ end
+ end
end