Permalink
Browse files

tests for merging Relations of different classes.

  • Loading branch information...
1 parent 742adce commit f081edb1fe153129a148f844174f98e2577a1f86 @senny senny committed Nov 13, 2013
Showing with 19 additions and 0 deletions.
  1. +19 −0 activerecord/test/cases/relation/merging_test.rb
@@ -129,3 +129,22 @@ def test_merging_reorders_bind_params
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

0 comments on commit f081edb

Please sign in to comment.