From 1e53404fe9c39ad0849894d73e431315be8c0bf0 Mon Sep 17 00:00:00 2001 From: Neeraj Singh Date: Sun, 27 Jun 2010 11:17:44 -0400 Subject: reset_counter should work with non-traditional belongs_to and polymorphic belongs_to MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit [#4984 state:resolved] Signed-off-by: José Valim --- activerecord/test/cases/counter_cache_test.rb | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) (limited to 'activerecord/test/cases/counter_cache_test.rb') diff --git a/activerecord/test/cases/counter_cache_test.rb b/activerecord/test/cases/counter_cache_test.rb index 377de168b9..137236255d 100644 --- a/activerecord/test/cases/counter_cache_test.rb +++ b/activerecord/test/cases/counter_cache_test.rb @@ -1,17 +1,20 @@ require 'cases/helper' require 'models/topic' +require 'models/car' +require 'models/wheel' +require 'models/engine' require 'models/reply' require 'models/category' require 'models/categorization' class CounterCacheTest < ActiveRecord::TestCase - fixtures :topics, :categories, :categorizations + fixtures :topics, :categories, :categorizations, :cars - class SpecialTopic < ::Topic + class ::SpecialTopic < ::Topic has_many :special_replies, :foreign_key => 'parent_id' end - class SpecialReply < ::Reply + class ::SpecialReply < ::Reply belongs_to :special_topic, :foreign_key => 'parent_id', :counter_cache => 'replies_count' end @@ -58,6 +61,16 @@ class CounterCacheTest < ActiveRecord::TestCase end end + test "reset counter should with belongs_to which has class_name" do + car = cars(:honda) + assert_nothing_raised do + Car.reset_counters(car.id, :engines) + end + assert_nothing_raised do + Car.reset_counters(car.id, :wheels) + end + end + test "update counter with initial null value" do category = categories(:general) assert_equal 2, category.categorizations.count -- cgit v1.2.3