mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
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
This commit is contained in:
parent
87898badba
commit
b95b09f32d
2 changed files with 9 additions and 18 deletions
|
@ -662,7 +662,7 @@ class HasManyAssociationsTest < Test::Unit::TestCase
|
||||||
def test_three_levels_of_dependence
|
def test_three_levels_of_dependence
|
||||||
topic = Topic.create "title" => "neat and simple"
|
topic = Topic.create "title" => "neat and simple"
|
||||||
reply = topic.replies.create "title" => "neat and simple", "content" => "still digging it"
|
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 }
|
assert_nothing_raised { topic.destroy }
|
||||||
end
|
end
|
||||||
|
@ -925,6 +925,10 @@ class BelongsToAssociationsTest < Test::Unit::TestCase
|
||||||
reply.topic = topic
|
reply.topic = topic
|
||||||
|
|
||||||
assert_equal 1, topic.reload[:replies_count]
|
assert_equal 1, topic.reload[:replies_count]
|
||||||
|
assert_equal 1, topic.replies.size
|
||||||
|
|
||||||
|
topic[:replies_count] = 15
|
||||||
|
assert_equal 15, topic.replies.size
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_custom_counter_cache
|
def test_custom_counter_cache
|
||||||
|
@ -935,23 +939,10 @@ class BelongsToAssociationsTest < Test::Unit::TestCase
|
||||||
silly.reply = reply
|
silly.reply = reply
|
||||||
|
|
||||||
assert_equal 1, reply.reload[:replies_count]
|
assert_equal 1, reply.reload[:replies_count]
|
||||||
end
|
assert_equal 1, reply.replies.size
|
||||||
|
|
||||||
def xtest_size_uses_counter_cache
|
reply[:replies_count] = 17
|
||||||
apple = Firm.create("name" => "Apple")
|
assert_equal 17, reply.replies.size
|
||||||
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"
|
|
||||||
|
|
||||||
apple.clients.to_s
|
|
||||||
assert_equal 1, apple.clients.size, "Should not use the cached number, but go to the database"
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_store_two_association_with_one_save
|
def test_store_two_association_with_one_save
|
||||||
|
|
2
activerecord/test/fixtures/reply.rb
vendored
2
activerecord/test/fixtures/reply.rb
vendored
|
@ -2,7 +2,7 @@ require 'fixtures/topic'
|
||||||
|
|
||||||
class Reply < Topic
|
class Reply < Topic
|
||||||
belongs_to :topic, :foreign_key => "parent_id", :counter_cache => true
|
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 :errors_on_empty_content
|
||||||
validate_on_create :title_is_wrong_create
|
validate_on_create :title_is_wrong_create
|
||||||
|
|
Loading…
Reference in a new issue