diff --git a/activerecord/test/associations_test.rb b/activerecord/test/associations_test.rb index 8616c4d4ad4da70e3e8d5f50e40586f6a2bcfe90..df15d0d0b009d055de74344caeac84ea338135ec 100755 --- a/activerecord/test/associations_test.rb +++ b/activerecord/test/associations_test.rb @@ -662,7 +662,7 @@ def test_destroy_dependent_when_deleted_from_association def test_three_levels_of_dependence topic = Topic.create "title" => "neat and simple" reply = topic.replies.create "title" => "neat and simple", "content" => "still digging it" - silly_reply = reply.silly_replies.create "title" => "neat and simple", "content" => "ain't complaining" + silly_reply = reply.replies.create "title" => "neat and simple", "content" => "ain't complaining" assert_nothing_raised { topic.destroy } end @@ -925,6 +925,10 @@ def test_counter_cache reply.topic = topic assert_equal 1, topic.reload[:replies_count] + assert_equal 1, topic.replies.size + + topic[:replies_count] = 15 + assert_equal 15, topic.replies.size end def test_custom_counter_cache @@ -935,23 +939,10 @@ def test_custom_counter_cache silly.reply = reply assert_equal 1, reply.reload[:replies_count] - end - - def xtest_size_uses_counter_cache - apple = Firm.create("name" => "Apple") - final_cut = apple.clients.create("name" => "Final Cut") - - apple.clients.to_s - assert_equal 1, apple.clients.size, "Created one client" - - apple.companies_count = 2 - apple.save - - apple = Firm.find(:first, :conditions => "name = 'Apple'") - assert_equal 2, apple.clients.size, "Should use the new cached number" + assert_equal 1, reply.replies.size - apple.clients.to_s - assert_equal 1, apple.clients.size, "Should not use the cached number, but go to the database" + reply[:replies_count] = 17 + assert_equal 17, reply.replies.size end def test_store_two_association_with_one_save diff --git a/activerecord/test/fixtures/reply.rb b/activerecord/test/fixtures/reply.rb index 04a50e9322f1944750ddf4e3b16bb5e0ccd77b43..44a23cd2ddfc511fd53b22a9f39fb24e9f409d44 100755 --- a/activerecord/test/fixtures/reply.rb +++ b/activerecord/test/fixtures/reply.rb @@ -2,7 +2,7 @@ class Reply < Topic belongs_to :topic, :foreign_key => "parent_id", :counter_cache => true - has_many :silly_replies, :dependent => true, :foreign_key => "parent_id" + has_many :replies, :class_name => "SillyReply", :dependent => true, :foreign_key => "parent_id" validate :errors_on_empty_content validate_on_create :title_is_wrong_create