diff options
author | Emilio Tagua <miloops@gmail.com> | 2009-10-07 11:57:59 -0300 |
---|---|---|
committer | Emilio Tagua <miloops@gmail.com> | 2009-10-07 11:57:59 -0300 |
commit | 1d5854826b27e5e8bfb041c57a49d1e46178b49e (patch) | |
tree | 25762234a182342cf4a64d7a715bd295239edae5 /activerecord/test | |
parent | c3b4da7796f0aab23b11521cf86171a83d84ad3e (diff) | |
download | rails-1d5854826b27e5e8bfb041c57a49d1e46178b49e.tar.gz rails-1d5854826b27e5e8bfb041c57a49d1e46178b49e.tar.bz2 rails-1d5854826b27e5e8bfb041c57a49d1e46178b49e.zip |
Allow preload and eager_load to work on relations at the same time.
Diffstat (limited to 'activerecord/test')
-rw-r--r-- | activerecord/test/cases/relations_test.rb | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/activerecord/test/cases/relations_test.rb b/activerecord/test/cases/relations_test.rb index 17c228616b..54b72554b9 100644 --- a/activerecord/test/cases/relations_test.rb +++ b/activerecord/test/cases/relations_test.rb @@ -4,6 +4,7 @@ require 'models/topic' require 'models/comment' require 'models/reply' require 'models/author' +require 'models/comment' require 'models/entrant' require 'models/developer' require 'models/company' @@ -125,5 +126,26 @@ class RelationTest < ActiveRecord::TestCase assert_equal 'Jamis', DeveloperCalledJamis.create!.name end + def test_loading_with_one_association + posts = Post.all(:include => :comments).to_a + post = posts.find { |p| p.id == 1 } + assert_equal 2, post.comments.size + assert post.comments.include?(comments(:greetings)) + + post = Post.find(:first, :include => :comments, :conditions => "posts.title = 'Welcome to the weblog'") + assert_equal 2, post.comments.size + assert post.comments.include?(comments(:greetings)) + + posts = Post.all(:include => :last_comment).to_a + post = posts.find { |p| p.id == 1 } + assert_equal Post.find(1).last_comment, post.last_comment + end + + def test_loading_with_one_association_with_non_preload + posts = Post.all(:include => :last_comment, :order => 'comments.id DESC').to_a + post = posts.find { |p| p.id == 1 } + assert_equal Post.find(1).last_comment, post.last_comment + end + end |