Skip to content

Commit f081edb

Browse files
committed
tests for merging Relations of different classes.
1 parent 742adce commit f081edb

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

activerecord/test/cases/relation/merging_test.rb

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,3 +129,22 @@ def test_merging_reorders_bind_params
129129
assert_equal post, merged.first
130130
end
131131
end
132+
133+
class MergingDifferentRelationsTest < ActiveRecord::TestCase
134+
fixtures :posts, :authors
135+
136+
test "merging where relations" do
137+
hello_by_bob = Post.where(body: "hello").joins(:author).
138+
merge(Author.where(name: "Bob")).pluck("posts.id")
139+
140+
assert_equal [posts(:misc_by_bob).id,
141+
posts(:other_by_bob).id], hello_by_bob
142+
end
143+
144+
test "merging order relations" do
145+
posts_by_author_name = Post.limit(3).joins(:author).
146+
merge(Author.order(:name)).pluck("authors.name")
147+
148+
assert_equal ["Bob", "Bob", "David"], posts_by_author_name
149+
end
150+
end

0 commit comments

Comments
 (0)