aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/associations/cascaded_eager_loading_test.rb
diff options
context:
space:
mode:
authorJon Leighton <j@jonathanleighton.com>2011-12-29 14:26:38 +0000
committerJon Leighton <j@jonathanleighton.com>2011-12-29 14:27:33 +0000
commitc99d507fccca2e9e4d12e49b4387e007c5481ae9 (patch)
tree269b10745091c0c0e3941ab756cec0130cbc11bd /activerecord/test/cases/associations/cascaded_eager_loading_test.rb
parent0b8b68209ded58e40cc18f3fef2f2c38e3730bb8 (diff)
downloadrails-c99d507fccca2e9e4d12e49b4387e007c5481ae9.tar.gz
rails-c99d507fccca2e9e4d12e49b4387e007c5481ae9.tar.bz2
rails-c99d507fccca2e9e4d12e49b4387e007c5481ae9.zip
Deprecate implicit eager loading. Closes #950.
Diffstat (limited to 'activerecord/test/cases/associations/cascaded_eager_loading_test.rb')
-rw-r--r--activerecord/test/cases/associations/cascaded_eager_loading_test.rb32
1 files changed, 26 insertions, 6 deletions
diff --git a/activerecord/test/cases/associations/cascaded_eager_loading_test.rb b/activerecord/test/cases/associations/cascaded_eager_loading_test.rb
index ff376a68d8..90e5609782 100644
--- a/activerecord/test/cases/associations/cascaded_eager_loading_test.rb
+++ b/activerecord/test/cases/associations/cascaded_eager_loading_test.rb
@@ -61,15 +61,31 @@ class CascadedEagerLoadingTest < ActiveRecord::TestCase
end
def test_cascaded_eager_association_loading_with_duplicated_includes
- categories = Category.includes(:categorizations).includes(:categorizations => :author).where("categorizations.id is not null")
+ categories = Category.includes(:categorizations).includes(:categorizations => :author)
+ assert_nothing_raised do
+ assert_equal Category.count, categories.count
+ assert_equal Category.count, categories.all.size
+ end
+ end
+
+ def test_cascaded_eager_association_loading_with_twice_includes_edge_cases
+ categories = Category.includes(:categorizations => :author).includes(:categorizations => :post)
+ assert_nothing_raised do
+ assert_equal Category.count, categories.count
+ assert_equal Category.count, categories.all.size
+ end
+ end
+
+ def test_cascaded_eager_association_loading_with_duplicated_eager_load
+ categories = Category.eager_load(:categorizations).eager_load(:categorizations => :author).where("categorizations.id is not null")
assert_nothing_raised do
assert_equal 3, categories.count
assert_equal 3, categories.all.size
end
end
- def test_cascaded_eager_association_loading_with_twice_includes_edge_cases
- categories = Category.includes(:categorizations => :author).includes(:categorizations => :post).where("posts.id is not null")
+ def test_cascaded_eager_association_loading_with_twice_eager_load_edge_cases
+ categories = Category.eager_load(:categorizations => :author).eager_load(:categorizations => :post).where("posts.id is not null")
assert_nothing_raised do
assert_equal 3, categories.count
assert_equal 3, categories.all.size
@@ -127,7 +143,7 @@ class CascadedEagerLoadingTest < ActiveRecord::TestCase
silly.parent_id = 1
assert silly.save
- topics = Topic.find(:all, :include => :replies, :order => 'topics.id, replies_topics.id')
+ topics = Topic.eager_load(:replies).order('topics.id, replies_topics.id').to_a
assert_no_queries do
assert_equal 2, topics[0].replies.size
assert_equal 0, topics[1].replies.size
@@ -142,7 +158,9 @@ class CascadedEagerLoadingTest < ActiveRecord::TestCase
end
def test_eager_association_loading_with_multiple_stis_and_order
- author = Author.find(:first, :include => { :posts => [ :special_comments , :very_special_comment ] }, :order => ['authors.name', 'comments.body', 'very_special_comments_posts.body'], :conditions => 'posts.id = 4')
+ author = Author.eager_load(:posts => [ :special_comments , :very_special_comment ]).
+ order('authors.name', 'comments.body', 'very_special_comments_posts.body').
+ where('posts.id = 4').first
assert_equal authors(:david), author
assert_no_queries do
author.posts.first.special_comments
@@ -151,7 +169,9 @@ class CascadedEagerLoadingTest < ActiveRecord::TestCase
end
def test_eager_association_loading_of_stis_with_multiple_references
- authors = Author.find(:all, :include => { :posts => { :special_comments => { :post => [ :special_comments, :very_special_comment ] } } }, :order => 'comments.body, very_special_comments_posts.body', :conditions => 'posts.id = 4')
+ authors = Author.eager_load(:posts => { :special_comments => { :post => [ :special_comments, :very_special_comment ] } }).
+ order('comments.body, very_special_comments_posts.body').
+ where('posts.id = 4')
assert_equal [authors(:david)], authors
assert_no_queries do
authors.first.posts.first.special_comments.first.post.special_comments