diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2005-07-11 06:09:08 +0000 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2005-07-11 06:09:08 +0000 |
commit | 5b9b904f149f8ae41255096ba7b210c912329103 (patch) | |
tree | ba7c8c0e9c97024503b962158499d78bcd688096 /activerecord/test | |
parent | 16669774903dd7bfaaf1bf8f0c72e49ebaeffeeb (diff) | |
download | rails-5b9b904f149f8ae41255096ba7b210c912329103.tar.gz rails-5b9b904f149f8ae41255096ba7b210c912329103.tar.bz2 rails-5b9b904f149f8ae41255096ba7b210c912329103.zip |
Added support for limit and offset with eager loading of has_one and belongs_to associations. Using the options with has_many and has_and_belongs_to_many associations will now raise an ActiveRecord::ConfigurationError #1692 [Rick Olsen]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@1811 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord/test')
-rw-r--r-- | activerecord/test/associations_go_eager_test.rb | 45 |
1 files changed, 43 insertions, 2 deletions
diff --git a/activerecord/test/associations_go_eager_test.rb b/activerecord/test/associations_go_eager_test.rb index 892a879283..cecc41ab50 100644 --- a/activerecord/test/associations_go_eager_test.rb +++ b/activerecord/test/associations_go_eager_test.rb @@ -48,10 +48,51 @@ class EagerAssociationTest < Test::Unit::TestCase def test_eager_association_loading_with_belongs_to comments = Comment.find(:all, :include => :post) + assert_equal 9, comments.length titles = comments.map { |c| c.post.title } assert titles.include?(posts(:welcome).title) assert titles.include?(posts(:sti_post_and_comments).title) end + + def test_eager_association_loading_with_belongs_to_and_limit + comments = Comment.find(:all, :include => :post, :limit => 5) + assert_equal 5, comments.length + assert_equal [1,2,3,5,6], comments.collect { |c| c.id } + end + + def test_eager_association_loading_with_belongs_to_and_limit_and_conditions + comments = Comment.find(:all, :include => :post, :conditions => 'post_id = 4', :limit => 3) + assert_equal 3, comments.length + assert_equal [5,6,7], comments.collect { |c| c.id } + end + + def test_eager_association_loading_with_belongs_to_and_limit_and_offset + comments = Comment.find(:all, :include => :post, :limit => 3, :offset => 2) + assert_equal 3, comments.length + assert_equal [3,5,6], comments.collect { |c| c.id } + end + + def test_eager_association_loading_with_belongs_to_and_limit_and_offset_and_conditions + comments = Comment.find(:all, :include => :post, :conditions => 'post_id = 4', :limit => 3, :offset => 1) + assert_equal 3, comments.length + assert_equal [6,7,8], comments.collect { |c| c.id } + end + + def test_eager_association_loading_with_belongs_to_and_limit_and_multiple_associations + posts = Post.find(:all, :include => [:author, :very_special_comment], :limit => 1) + assert_equal 1, posts.length + assert_equal [4], posts.collect { |p| p.id } + end + + def test_eager_association_loading_with_belongs_to_and_limit_and_offset_and_multiple_associations + posts = Post.find(:all, :include => [:author, :very_special_comment], :limit => 1, :offset => 1) + assert_equal 0, posts.length + assert_equal [], posts + end + + def test_eager_association_raise_on_limit + assert_raises(ActiveRecord::ConfigurationError) { Post.find(:all, :include => [:author, :comments], :limit => 1) } + end def test_eager_association_loading_with_habtm posts = Post.find(:all, :include => :categories, :order => "posts.id") @@ -95,10 +136,10 @@ class EagerAssociationTest < Test::Unit::TestCase end def test_eager_with_invalid_association_reference - assert_raises(NoMethodError, "Association was not found; perhaps you misspelled it? You specified :include=>:monkeys") { + assert_raises(ActiveRecord::ConfigurationError, "Association was not found; perhaps you misspelled it? You specified :include => :monkeys") { post = Post.find(6, :include=>[ :monkeys ]) } - assert_raises(NoMethodError, "Association was not found; perhaps you misspelled it? You specified :include=>:monkeys, :elephants") { + assert_raises(ActiveRecord::ConfigurationError, "Association was not found; perhaps you misspelled it? You specified :include => :monkeys, :elephants") { post = Post.find(6, :include=>[ :monkeys, :elephants ]) } end |