From 2a35baa0bb4312d95e1340074cce731afedecde0 Mon Sep 17 00:00:00 2001 From: Jamis Buck Date: Sat, 24 Sep 2005 23:58:13 +0000 Subject: Wrap :conditions in parentheses to prevent problems with OR's #1871 git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@2324 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- activerecord/test/associations_go_eager_test.rb | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) (limited to 'activerecord/test/associations_go_eager_test.rb') diff --git a/activerecord/test/associations_go_eager_test.rb b/activerecord/test/associations_go_eager_test.rb index 750e8bd208..ec088eebb7 100644 --- a/activerecord/test/associations_go_eager_test.rb +++ b/activerecord/test/associations_go_eager_test.rb @@ -20,14 +20,19 @@ class EagerAssociationTest < Test::Unit::TestCase assert post.comments.include?(comments(:greetings)) end + def test_loading_conditions_with_or + posts = authors(:david).posts.find(:all, :include => :comments, :conditions => "comments.body like 'Normal%' OR comments.type = 'SpecialComment'") + assert_nil posts.detect { |p| p.author_id != authors(:david).id }, + "expected to find only david's posts" + end + def test_with_ordering - posts = Post.find(:all, :include => :comments, :order => "posts.id DESC") - assert_equal posts(:sti_habtm), posts[0] - assert_equal posts(:sti_post_and_comments), posts[1] - assert_equal posts(:sti_comments), posts[2] - assert_equal posts(:authorless), posts[3] - assert_equal posts(:thinking), posts[4] - assert_equal posts(:welcome), posts[5] + list = Post.find(:all, :include => :comments, :order => "posts.id DESC") + [:eager_other, :sti_habtm, :sti_post_and_comments, :sti_comments, + :authorless, :thinking, :welcome + ].each_with_index do |post, index| + assert_equal posts(post), list[index] + end end def test_loading_with_multiple_associations @@ -48,7 +53,7 @@ class EagerAssociationTest < Test::Unit::TestCase def test_eager_association_loading_with_belongs_to comments = Comment.find(:all, :include => :post) - assert_equal 9, comments.length + assert_equal 10, comments.length titles = comments.map { |c| c.post.title } assert titles.include?(posts(:welcome).title) assert titles.include?(posts(:sti_post_and_comments).title) -- cgit v1.2.3