diff options
author | Mislav Marohnić <mislav.marohnic@gmail.com> | 2010-04-17 02:01:38 +0200 |
---|---|---|
committer | Mikel Lindsaar <raasdnil@gmail.com> | 2010-06-03 23:32:10 +1000 |
commit | e6b0ea3f8a252b6795156ad8c0816198f7c18cf9 (patch) | |
tree | 4994e166c01b660a44e3db476439388b6703b5d2 /activerecord/test/cases | |
parent | 4ab47f542026f7301a0cf38d7d89ee6423207021 (diff) | |
download | rails-e6b0ea3f8a252b6795156ad8c0816198f7c18cf9.tar.gz rails-e6b0ea3f8a252b6795156ad8c0816198f7c18cf9.tar.bz2 rails-e6b0ea3f8a252b6795156ad8c0816198f7c18cf9.zip |
fix `reset_counters` to work even with complex class names
e.g. it guesses that a belongs_to association to Namespace::MyModel is
named "my_model", unlike before where it would look up an association
named "namespace::mymodel" and fail.
Diffstat (limited to 'activerecord/test/cases')
-rwxr-xr-x | activerecord/test/cases/counter_cache_test.rb | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/activerecord/test/cases/counter_cache_test.rb b/activerecord/test/cases/counter_cache_test.rb index b72356cf6f..377de168b9 100755 --- a/activerecord/test/cases/counter_cache_test.rb +++ b/activerecord/test/cases/counter_cache_test.rb @@ -7,6 +7,14 @@ require 'models/categorization' class CounterCacheTest < ActiveRecord::TestCase fixtures :topics, :categories, :categorizations + class SpecialTopic < ::Topic + has_many :special_replies, :foreign_key => 'parent_id' + end + + class SpecialReply < ::Reply + belongs_to :special_topic, :foreign_key => 'parent_id', :counter_cache => 'replies_count' + end + setup do @topic = Topic.find(1) end @@ -32,6 +40,23 @@ class CounterCacheTest < ActiveRecord::TestCase Topic.reset_counters(@topic.id, :replies) end end + + test "reset counters with string argument" do + Topic.increment_counter('replies_count', @topic.id) + + assert_difference '@topic.reload.replies_count', -1 do + Topic.reset_counters(@topic.id, 'replies') + end + end + + test "reset counters with modularized and camelized classnames" do + special = SpecialTopic.create!(:title => 'Special') + SpecialTopic.increment_counter(:replies_count, special.id) + + assert_difference 'special.reload.replies_count', -1 do + SpecialTopic.reset_counters(special.id, :special_replies) + end + end test "update counter with initial null value" do category = categories(:general) |