aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test
diff options
context:
space:
mode:
authorMichael Koziarski <michael@koziarski.com>2007-04-26 00:18:38 +0000
committerMichael Koziarski <michael@koziarski.com>2007-04-26 00:18:38 +0000
commit9d08a07c48274686f8bd21e590249bfe3865df89 (patch)
tree74af0238c202d13c1b5483ea832a30de8b0a7b23 /activerecord/test
parentbaba45d68952418ccc00cbdd5f3812d95b7cc664 (diff)
downloadrails-9d08a07c48274686f8bd21e590249bfe3865df89.tar.gz
rails-9d08a07c48274686f8bd21e590249bfe3865df89.tar.bz2
rails-9d08a07c48274686f8bd21e590249bfe3865df89.zip
Improve Performance of calling create on has_many :through associations by avoiding loading the target collection. Closes #8150 [evan]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@6581 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord/test')
-rwxr-xr-xactiverecord/test/associations_test.rb16
1 files changed, 14 insertions, 2 deletions
diff --git a/activerecord/test/associations_test.rb b/activerecord/test/associations_test.rb
index 250fa1027c..aec6a47583 100755
--- a/activerecord/test/associations_test.rb
+++ b/activerecord/test/associations_test.rb
@@ -7,6 +7,7 @@ require 'fixtures/reply'
require 'fixtures/computer'
require 'fixtures/customer'
require 'fixtures/order'
+require 'fixtures/categorization'
require 'fixtures/category'
require 'fixtures/post'
require 'fixtures/author'
@@ -69,7 +70,7 @@ class AssociationsTest < Test::Unit::TestCase
end
class AssociationProxyTest < Test::Unit::TestCase
- fixtures :authors, :posts
+ fixtures :authors, :posts, :categorizations, :categories
def test_proxy_accessors
welcome = posts(:welcome)
@@ -90,6 +91,17 @@ class AssociationProxyTest < Test::Unit::TestCase
assert_equal david.posts_with_extension, david.posts_with_extension.testing_proxy_target
end
+ def test_push_does_not_load_target
+ david = authors(:david)
+ not_loaded_string = '<categories not loaded yet>'
+ not_loaded_re = Regexp.new(not_loaded_string)
+
+ david.categories << categories(:technology)
+ assert_match not_loaded_re, david.inspect
+ assert_equal not_loaded_string, david.categories.inspect
+ assert david.categories.include?(categories(:technology))
+ end
+
def test_inspect_does_not_load_target
david = authors(:david)
not_loaded_string = '<posts not loaded yet>'
@@ -660,7 +672,7 @@ class HasManyAssociationsTest < Test::Unit::TestCase
assert_equal 2, new_firm.clients_of_firm.size
assert_equal 2, new_firm.clients_of_firm(true).size
end
-
+
def test_invalid_adding
firm = Firm.find(1)
assert !(firm.clients_of_firm << c = Client.new)