diff options
author | Jeremy Kemper <jeremy@bitsweat.net> | 2006-12-21 23:28:12 +0000 |
---|---|---|
committer | Jeremy Kemper <jeremy@bitsweat.net> | 2006-12-21 23:28:12 +0000 |
commit | 4cf8bf7312a124cb96e615923ebb373380fb60bd (patch) | |
tree | 6e52754eb2bfa9e94c2648239f18d7626cdd5309 /activerecord/test/associations_test.rb | |
parent | 8cb6cb58a29b422ab7d2f2917262e40ec340816d (diff) | |
download | rails-4cf8bf7312a124cb96e615923ebb373380fb60bd.tar.gz rails-4cf8bf7312a124cb96e615923ebb373380fb60bd.tar.bz2 rails-4cf8bf7312a124cb96e615923ebb373380fb60bd.zip |
Pushing a record on an association collection doesn't unnecessarily load all the associated records.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@5769 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord/test/associations_test.rb')
-rwxr-xr-x | activerecord/test/associations_test.rb | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/activerecord/test/associations_test.rb b/activerecord/test/associations_test.rb index 511653dfce..c5d89bb216 100755 --- a/activerecord/test/associations_test.rb +++ b/activerecord/test/associations_test.rb @@ -637,12 +637,15 @@ class HasManyAssociationsTest < Test::Unit::TestCase def test_adding_before_save no_of_firms = Firm.count no_of_clients = Client.count + new_firm = Firm.new("name" => "A New Firm, Inc") + c = Client.new("name" => "Apple") + new_firm.clients_of_firm.push Client.new("name" => "Natural Company") - new_firm.clients_of_firm << (c = Client.new("name" => "Apple")) - assert new_firm.new_record? - assert c.new_record? + assert_equal 1, new_firm.clients_of_firm.size + new_firm.clients_of_firm << c assert_equal 2, new_firm.clients_of_firm.size + assert_equal no_of_firms, Firm.count # Firm was not saved to database. assert_equal no_of_clients, Client.count # Clients were not saved to database. assert new_firm.save @@ -651,6 +654,7 @@ class HasManyAssociationsTest < Test::Unit::TestCase assert_equal new_firm, c.firm assert_equal no_of_firms+1, Firm.count # Firm was saved to database. assert_equal no_of_clients+2, Client.count # Clients were saved to database. + assert_equal 2, new_firm.clients_of_firm.size assert_equal 2, new_firm.clients_of_firm(true).size end |