Permalink
Browse files

a few more tests for the custom counter_cache naming code

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@3826 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
1 parent 87898ba commit b95b09f32daf4da5eb9986ba3444f7dd968a72a1 @jamis jamis committed Mar 9, 2006
Showing with 9 additions and 18 deletions.
  1. +8 −17 activerecord/test/associations_test.rb
  2. +1 −1 activerecord/test/fixtures/reply.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
@@ -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

0 comments on commit b95b09f

Please sign in to comment.