diff options
-rw-r--r-- | activerecord/test/cases/counter_cache_test.rb | 12 | ||||
-rw-r--r-- | activerecord/test/models/reply.rb | 1 | ||||
-rw-r--r-- | activerecord/test/schema/schema.rb | 1 |
3 files changed, 14 insertions, 0 deletions
diff --git a/activerecord/test/cases/counter_cache_test.rb b/activerecord/test/cases/counter_cache_test.rb index ac093251a5..61f9d4cdae 100644 --- a/activerecord/test/cases/counter_cache_test.rb +++ b/activerecord/test/cases/counter_cache_test.rb @@ -51,6 +51,18 @@ 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 + Topic.reset_counters(@topic.id, :replies, :unique_replies) + end + end + test "reset counters with string argument" do Topic.increment_counter('replies_count', @topic.id) diff --git a/activerecord/test/models/reply.rb b/activerecord/test/models/reply.rb index c88262580e..3e82e55d89 100644 --- a/activerecord/test/models/reply.rb +++ b/activerecord/test/models/reply.rb @@ -7,6 +7,7 @@ class Reply < Topic end class UniqueReply < Reply + belongs_to :topic, :foreign_key => 'parent_id', :counter_cache => true validates_uniqueness_of :content, :scope => 'parent_id' end diff --git a/activerecord/test/schema/schema.rb b/activerecord/test/schema/schema.rb index 8beb58f3fc..188a3f0164 100644 --- a/activerecord/test/schema/schema.rb +++ b/activerecord/test/schema/schema.rb @@ -675,6 +675,7 @@ ActiveRecord::Schema.define do end t.boolean :approved, :default => true t.integer :replies_count, :default => 0 + t.integer :unique_replies_count, :default => 0 t.integer :parent_id t.string :parent_title t.string :type |