aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/associations_go_eager_test.rb
diff options
context:
space:
mode:
authorDavid Heinemeier Hansson <david@loudthinking.com>2005-04-03 17:50:11 +0000
committerDavid Heinemeier Hansson <david@loudthinking.com>2005-04-03 17:50:11 +0000
commitf8783abf0cd409d53e7e104b576d45966252378b (patch)
tree2f8a0e604a7639e0b7983631208a7e7360928be0 /activerecord/test/associations_go_eager_test.rb
parent46f2b03eacf5dd39c9283697d7d05f0ccb5f4a72 (diff)
downloadrails-f8783abf0cd409d53e7e104b576d45966252378b.tar.gz
rails-f8783abf0cd409d53e7e104b576d45966252378b.tar.bz2
rails-f8783abf0cd409d53e7e104b576d45966252378b.zip
Made eager loading work even more
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@1083 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord/test/associations_go_eager_test.rb')
-rw-r--r--activerecord/test/associations_go_eager_test.rb36
1 files changed, 36 insertions, 0 deletions
diff --git a/activerecord/test/associations_go_eager_test.rb b/activerecord/test/associations_go_eager_test.rb
new file mode 100644
index 0000000000..59ca4cac85
--- /dev/null
+++ b/activerecord/test/associations_go_eager_test.rb
@@ -0,0 +1,36 @@
+require 'abstract_unit'
+require 'fixtures/post'
+require 'fixtures/comment'
+require 'fixtures/author'
+
+class EagerAssociationTest < Test::Unit::TestCase
+ fixtures :posts, :comments, :authors
+
+ def test_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
+
+ post = Post.find(:first, :include => :comments, :conditions => "posts.title = 'Welcome to the weblog'")
+ assert_equal 2, post.comments.size
+ assert_equal @greetings.body, post.comments.first.body
+ end
+
+ def test_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 test_loading_from_an_association
+ posts = @david.posts.find(:all, :include => :comments)
+ assert_equal 2, posts.first.comments.size
+ end
+
+ def test_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
+