diff options
author | Neeraj Singh <neerajdotname@gmail.com> | 2010-06-27 11:17:44 -0400 |
---|---|---|
committer | José Valim <jose.valim@gmail.com> | 2010-07-08 23:24:12 +0200 |
commit | 1e53404fe9c39ad0849894d73e431315be8c0bf0 (patch) | |
tree | 57f1bc98e37e8f5ed17ed8126d1b43d3c6578288 /activerecord/test/cases | |
parent | 87f64ef05e48ad8b374022ca944e34a7ad68551d (diff) | |
download | rails-1e53404fe9c39ad0849894d73e431315be8c0bf0.tar.gz rails-1e53404fe9c39ad0849894d73e431315be8c0bf0.tar.bz2 rails-1e53404fe9c39ad0849894d73e431315be8c0bf0.zip |
reset_counter should work with non-traditional belongs_to and polymorphic belongs_to
[#4984 state:resolved]
Signed-off-by: José Valim <jose.valim@gmail.com>
Diffstat (limited to 'activerecord/test/cases')
-rw-r--r-- | activerecord/test/cases/counter_cache_test.rb | 19 |
1 files changed, 16 insertions, 3 deletions
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 |