aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test
diff options
context:
space:
mode:
authorDavid Heinemeier Hansson <david@loudthinking.com>2006-05-21 19:17:37 +0000
committerDavid Heinemeier Hansson <david@loudthinking.com>2006-05-21 19:17:37 +0000
commit66586bc168f358e3385416def6eb30ad1242ffe6 (patch)
tree5123f76617348e2f3ad908945586f426650b097b /activerecord/test
parent59c8c63ecd751136c5ed6d2e3c04a54af2025eb0 (diff)
downloadrails-66586bc168f358e3385416def6eb30ad1242ffe6.tar.gz
rails-66586bc168f358e3385416def6eb30ad1242ffe6.tar.bz2
rails-66586bc168f358e3385416def6eb30ad1242ffe6.zip
Fixed that has_many collections shouldn't load the entire association to do build or create [DHH]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@4354 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord/test')
-rwxr-xr-xactiverecord/test/associations_test.rb29
1 files changed, 29 insertions, 0 deletions
diff --git a/activerecord/test/associations_test.rb b/activerecord/test/associations_test.rb
index 6076b10446..f3e210bf77 100755
--- a/activerecord/test/associations_test.rb
+++ b/activerecord/test/associations_test.rb
@@ -512,6 +512,35 @@ class HasManyAssociationsTest < Test::Unit::TestCase
assert_equal 3, companies(:first_firm).clients_of_firm(true).size
end
+ def test_build_without_loading_association
+ first_topic = Topic.find(:first)
+ Reply.column_names
+
+ assert_equal 1, first_topic.replies.length
+
+ assert_no_queries do
+ first_topic.replies.build(:title => "Not saved", :content => "Superstars")
+ assert_equal 2, first_topic.replies.size
+ end
+
+ assert_equal 2, first_topic.replies.to_ary.size
+ end
+
+ def test_create_without_loading_association
+ first_firm = companies(:first_firm)
+ Firm.column_names
+ Client.column_names
+
+ assert_equal 1, first_firm.clients_of_firm.size
+ first_firm.clients_of_firm.reset
+
+ assert_queries(1) do
+ first_firm.clients_of_firm.create(:name => "Superstars")
+ end
+
+ assert_equal 2, first_firm.clients_of_firm.size
+ end
+
def test_invalid_build
new_client = companies(:first_firm).clients_of_firm.build
assert new_client.new_record?