aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/associations_test.rb
diff options
context:
space:
mode:
authorDavid Heinemeier Hansson <david@loudthinking.com>2005-04-03 10:52:05 +0000
committerDavid Heinemeier Hansson <david@loudthinking.com>2005-04-03 10:52:05 +0000
commitabc895b82829657d34f4902ce0cf04f0682bab63 (patch)
treedf164ff14acac26c22a3205331a5ae4898f05d03 /activerecord/test/associations_test.rb
parent17e5035bc566815b8aa8c192fec97a781f726938 (diff)
downloadrails-abc895b82829657d34f4902ce0cf04f0682bab63.tar.gz
rails-abc895b82829657d34f4902ce0cf04f0682bab63.tar.bz2
rails-abc895b82829657d34f4902ce0cf04f0682bab63.zip
Added new Base.find API and deprecated find_all, find_first. Added preliminary support for eager loading of associations
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@1077 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord/test/associations_test.rb')
-rwxr-xr-xactiverecord/test/associations_test.rb24
1 files changed, 23 insertions, 1 deletions
diff --git a/activerecord/test/associations_test.rb b/activerecord/test/associations_test.rb
index c4f1022076..68245379ed 100755
--- a/activerecord/test/associations_test.rb
+++ b/activerecord/test/associations_test.rb
@@ -5,6 +5,9 @@ require 'fixtures/company'
require 'fixtures/topic'
require 'fixtures/reply'
require 'fixtures/computer'
+require 'fixtures/post'
+require 'fixtures/comment'
+require 'fixtures/author'
# Can't declare new classes in test case methods, so tests before that
bad_collection_keys = false
@@ -203,8 +206,9 @@ end
class HasManyAssociationsTest < Test::Unit::TestCase
+ fixtures :accounts, :companies, :developers, :projects, :developers_projects, :topics, :posts, :comments
+
def setup
- create_fixtures "accounts", "companies", "developers", "projects", "developers_projects", "topics"
@signals37 = Firm.find(1)
end
@@ -530,6 +534,24 @@ class HasManyAssociationsTest < Test::Unit::TestCase
def test_adding_array_and_collection
assert_nothing_raised { Firm.find_first.clients + Firm.find_all.last.clients }
end
+
+ def test_eager_association_loading_with_one_association
+ posts = Post.find(:all, :include => :comments)
+ assert_equal 2, posts.first.comments.size
+ assert_equal @greetings.body, posts.first.comments.first.body
+ end
+
+ def test_eager_association_loading_with_multiple_associations
+ posts = Post.find(:all, :include => [ :comments, :author ])
+ assert_equal 2, posts.first.comments.size
+ assert_equal @greetings.body, posts.first.comments.first.body
+ end
+
+ def xtest_eager_association_loading_with_belongs_to
+ comments = Comment.find(:all, :include => :post)
+ assert_equal @welcome.title, comments.first.post.title
+ assert_equal @thinking.title, comments.last.post.title
+ end
end
class BelongsToAssociationsTest < Test::Unit::TestCase