From f081edb1fe153129a148f844174f98e2577a1f86 Mon Sep 17 00:00:00 2001 From: Yves Senn Date: Wed, 13 Nov 2013 16:36:12 +0100 Subject: tests for merging Relations of different classes. --- activerecord/test/cases/relation/merging_test.rb | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/activerecord/test/cases/relation/merging_test.rb b/activerecord/test/cases/relation/merging_test.rb index 8b71b5b2e9..49c8d07026 100644 --- a/activerecord/test/cases/relation/merging_test.rb +++ b/activerecord/test/cases/relation/merging_test.rb @@ -129,3 +129,22 @@ class RelationMergingTest < ActiveRecord::TestCase assert_equal post, merged.first end end + +class MergingDifferentRelationsTest < ActiveRecord::TestCase + fixtures :posts, :authors + + test "merging where relations" do + hello_by_bob = Post.where(body: "hello").joins(:author). + merge(Author.where(name: "Bob")).pluck("posts.id") + + assert_equal [posts(:misc_by_bob).id, + posts(:other_by_bob).id], hello_by_bob + end + + test "merging order relations" do + posts_by_author_name = Post.limit(3).joins(:author). + merge(Author.order(:name)).pluck("authors.name") + + assert_equal ["Bob", "Bob", "David"], posts_by_author_name + end +end -- cgit v1.2.3