0
require 'models/tagging'
0
require 'models/comment'
0
require 'models/author'
0
require 'models/category'
0
@@ -706,4 +707,68 @@ class EagerAssociationTest < ActiveRecord::TestCase
0
assert_equal 5, Developer.find(:all, :include => 'projects', :order => 'developers_projects.joined_on DESC', :limit => 5).size
0
+ def test_eager_loading_with_order_on_joined_table_preloads
0
+ posts = assert_queries(2) do
0
+ Post.find(:all, :joins => :comments, :include => :author, :order => 'comments.id DESC')
0
+ assert_equal posts(:eager_other), posts[0]
0
+ assert_equal authors(:mary), assert_no_queries { posts[0].author}
0
+ def test_eager_loading_with_conditions_on_joined_table_preloads
0
+ posts = assert_queries(2) do
0
+ Post.find(:all, :select => 'distinct posts.*', :include => :author, :joins => [:comments], :conditions => "comments.body like 'Thank you%'", :order => 'posts.id')
0
+ assert_equal [posts(:welcome)], posts
0
+ assert_equal authors(:david), assert_no_queries { posts[0].author}
0
+ posts = assert_queries(2) do
0
+ Post.find(:all, :select => 'distinct posts.*', :include => :author, :joins => [:comments], :conditions => "comments.body like 'Thank you%'", :order => 'posts.id')
0
+ assert_equal [posts(:welcome)], posts
0
+ assert_equal authors(:david), assert_no_queries { posts[0].author}
0
+ posts = assert_queries(2) do
0
+ Post.find(:all, :include => :author, :joins => {:taggings => :tag}, :conditions => "tags.name = 'General'")
0
+ assert_equal posts(:welcome, :thinking), posts
0
+ posts = assert_queries(2) do
0
+ Post.find(:all, :include => :author, :joins => {:taggings => {:tag => :taggings}}, :conditions => "taggings_tags.super_tag_id=2")
0
+ assert_equal posts(:welcome, :thinking), posts
0
+ def test_eager_loading_with_conditions_on_string_joined_table_preloads
0
+ posts = assert_queries(2) do
0
+ Post.find(:all, :select => 'distinct posts.*', :include => :author, :joins => "INNER JOIN comments on comments.post_id = posts.id", :conditions => "comments.body like 'Thank you%'", :order => 'posts.id')
0
+ assert_equal [posts(:welcome)], posts
0
+ assert_equal authors(:david), assert_no_queries { posts[0].author}
0
+ posts = assert_queries(2) do
0
+ Post.find(:all, :select => 'distinct posts.*', :include => :author, :joins => ["INNER JOIN comments on comments.post_id = posts.id"], :conditions => "comments.body like 'Thank you%'", :order => 'posts.id')
0
+ assert_equal [posts(:welcome)], posts
0
+ assert_equal authors(:david), assert_no_queries { posts[0].author}
0
+ def test_eager_loading_with_select_on_joined_table_preloads
0
+ posts = assert_queries(2) do
0
+ Post.find(:all, :select => 'posts.*, authors.name as author_name', :include => :comments, :joins => :author, :order => 'posts.id')
0
+ assert_equal 'David', posts[0].author_name
0
+ assert_equal posts(:welcome).comments, assert_no_queries { posts[0].comments}
0
+ def test_eager_loading_with_conditions_on_join_model_preloads
0
+ authors = assert_queries(2) do
0
+ Author.find(:all, :include => :author_address, :joins => :comments, :conditions => "posts.title like 'Welcome%'")
0
+ assert_equal authors(:david), authors[0]
0
+ assert_equal author_addresses(:david_address), authors[0].author_address