提交 b95b09f3 编写于 作者: J Jamis Buck

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
上级 87898bad
......@@ -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
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册