mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Add test to AR's counter_cache_test.rb
According to https://github.com/rails/rails/blob/b601399b72ab56cc01368f02615af99f45d1 4f02/activerecord/lib/active_record/counter_cache.rb#L14, u can pass more then one association to the `reset_counters` method.
This commit is contained in:
parent
677b64fcd5
commit
0123c39f41
3 changed files with 14 additions and 0 deletions
|
@ -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)
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue