aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/associations_go_eager_test.rb
diff options
context:
space:
mode:
authorDavid Heinemeier Hansson <david@loudthinking.com>2005-10-18 12:02:25 +0000
committerDavid Heinemeier Hansson <david@loudthinking.com>2005-10-18 12:02:25 +0000
commit851dd0806be4e21f9a4fdcc77162711f46095bc5 (patch)
treef2a0c5801239d9b15039eb8a0a9044530b2eaeec /activerecord/test/associations_go_eager_test.rb
parentd82c51bb16590090103f3d954e48fddd12c8ad45 (diff)
downloadrails-851dd0806be4e21f9a4fdcc77162711f46095bc5.tar.gz
rails-851dd0806be4e21f9a4fdcc77162711f46095bc5.tar.bz2
rails-851dd0806be4e21f9a4fdcc77162711f46095bc5.zip
Added support for using limits in eager loads that involve has_many and has_and_belongs_to_many associations
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@2675 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord/test/associations_go_eager_test.rb')
-rw-r--r--activerecord/test/associations_go_eager_test.rb31
1 files changed, 29 insertions, 2 deletions
diff --git a/activerecord/test/associations_go_eager_test.rb b/activerecord/test/associations_go_eager_test.rb
index ec088eebb7..3dccc8e65a 100644
--- a/activerecord/test/associations_go_eager_test.rb
+++ b/activerecord/test/associations_go_eager_test.rb
@@ -95,8 +95,35 @@ class EagerAssociationTest < Test::Unit::TestCase
assert_equal [], posts
end
- def test_eager_association_raise_on_limit
- assert_raises(ActiveRecord::ConfigurationError) { Post.find(:all, :include => [:author, :comments], :limit => 1) }
+ def test_eager_with_has_many_and_limit
+ posts = Post.find(:all, :include => [ :author, :comments ], :limit => 2)
+ assert_equal 2, posts.size
+ assert_equal 3, posts.inject(0) { |sum, post| sum += post.comments.size }
+ end
+
+ def test_eager_with_has_many_and_limit_with_no_results
+ posts = Post.find(:all, :include => [ :author, :comments ], :limit => 2, :conditions => "posts.title = 'magic forest'")
+ assert_equal 0, posts.size
+ end
+
+ def test_eager_with_has_and_belongs_to_many_and_limit
+ posts = Post.find(:all, :include => :categories, :order => "posts.id", :limit => 3)
+ assert_equal 3, posts.size
+ assert_equal 2, posts[0].categories.size
+ assert_equal 1, posts[1].categories.size
+ assert_equal 0, posts[2].categories.size
+ assert posts[0].categories.include?(categories(:technology))
+ assert posts[1].categories.include?(categories(:general))
+ end
+
+ def test_eager_with_has_many_and_limit_and_conditions_on_the_eagers
+ assert_raises(ArgumentError) do
+ posts = authors(:david).posts.find(:all,
+ :include => :comments,
+ :conditions => "comments.body like 'Normal%' OR comments.type = 'SpecialComment'",
+ :limit => 2
+ )
+ end
end
def test_eager_association_loading_with_habtm