diff options
author | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2012-10-02 09:23:02 -0700 |
---|---|---|
committer | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2012-10-02 09:23:02 -0700 |
commit | 2bc1ac77f688c90fa7e1efc83e60068c64006269 (patch) | |
tree | 281ab209e7ad1c580fb919c29ad0ff30f73a6fb7 /activerecord/test/cases | |
parent | 0d41d6956f3dda7e8eb133b623bcfd6ad1eb41a1 (diff) | |
parent | 6e56a03f834202af4e57c50a71cc74ea08303bfd (diff) | |
download | rails-2bc1ac77f688c90fa7e1efc83e60068c64006269.tar.gz rails-2bc1ac77f688c90fa7e1efc83e60068c64006269.tar.bz2 rails-2bc1ac77f688c90fa7e1efc83e60068c64006269.zip |
Merge pull request #7822 from lulalala/reset-counter-cache-for-has-many-through
Fix reset_counters crashing on has_many :through associations.
Diffstat (limited to 'activerecord/test/cases')
-rw-r--r-- | activerecord/test/cases/counter_cache_test.rb | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/activerecord/test/cases/counter_cache_test.rb b/activerecord/test/cases/counter_cache_test.rb index ee443741ca..fc46a249c8 100644 --- a/activerecord/test/cases/counter_cache_test.rb +++ b/activerecord/test/cases/counter_cache_test.rb @@ -10,9 +10,12 @@ require 'models/dog' require 'models/dog_lover' require 'models/person' require 'models/friendship' +require 'models/subscriber' +require 'models/subscription' +require 'models/book' class CounterCacheTest < ActiveRecord::TestCase - fixtures :topics, :categories, :categorizations, :cars, :dogs, :dog_lovers, :people, :friendships + fixtures :topics, :categories, :categorizations, :cars, :dogs, :dog_lovers, :people, :friendships, :subscribers, :subscriptions, :books class ::SpecialTopic < ::Topic has_many :special_replies, :foreign_key => 'parent_id' @@ -118,4 +121,14 @@ class CounterCacheTest < ActiveRecord::TestCase Person.reset_counters(michael.id, :followers) end end + + test "reset counter of has_many :through association" do + subscriber = subscribers('second') + Subscriber.reset_counters(subscriber.id, 'books') + Subscriber.increment_counter('books_count', subscriber.id) + + assert_difference 'subscriber.reload.books_count', -1 do + Subscriber.reset_counters(subscriber.id, 'books') + end + end end |