aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJamis Buck <jamis@37signals.com>2006-03-09 18:11:41 +0000
committerJamis Buck <jamis@37signals.com>2006-03-09 18:11:41 +0000
commitb95b09f32daf4da5eb9986ba3444f7dd968a72a1 (patch)
treec8dfa7ab37dcb3fe1e736d34a44b292f2c3c878a
parent87898badba211540d9c1d4dae0cd513a9d525554 (diff)
downloadrails-b95b09f32daf4da5eb9986ba3444f7dd968a72a1.tar.gz
rails-b95b09f32daf4da5eb9986ba3444f7dd968a72a1.tar.bz2
rails-b95b09f32daf4da5eb9986ba3444f7dd968a72a1.zip
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
-rwxr-xr-xactiverecord/test/associations_test.rb25
-rwxr-xr-xactiverecord/test/fixtures/reply.rb2
2 files changed, 9 insertions, 18 deletions
diff --git a/activerecord/test/associations_test.rb b/activerecord/test/associations_test.rb
index 8616c4d4ad..df15d0d0b0 100755
--- a/activerecord/test/associations_test.rb
+++ b/activerecord/test/associations_test.rb
@@ -662,7 +662,7 @@ class HasManyAssociationsTest < Test::Unit::TestCase
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 @@ class BelongsToAssociationsTest < Test::Unit::TestCase
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 @@ class BelongsToAssociationsTest < Test::Unit::TestCase
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 04a50e9322..44a23cd2dd 100755
--- a/activerecord/test/fixtures/reply.rb
+++ b/activerecord/test/fixtures/reply.rb
@@ -2,7 +2,7 @@ require 'fixtures/topic'
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