1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Merge pull request #39330 from kamipo/fix_merge_not_in

Fix merging NOT IN clause to behave the same as before
This commit is contained in:
Ryuta Kamizono 2020-05-18 21:48:36 +09:00 committed by GitHub
commit cdbce035a5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 1 deletions

View file

@ -21,7 +21,7 @@ module Arel # :nodoc: all
alias :== :eql?
def equality?
true
type == :in
end
def invert

View file

@ -88,6 +88,16 @@ class RelationMergingTest < ActiveRecord::TestCase
assert_equal [david, mary], mary_and_bob.merge(david_and_mary, rewhere: true)
end
def test_merge_not_in_clause
david, mary, bob = authors(:david, :mary, :bob)
non_mary_and_bob = Author.where.not(id: [mary, bob])
assert_equal [david], non_mary_and_bob
assert_equal [david], Author.where(id: david).merge(non_mary_and_bob)
assert_equal [], Author.where(id: mary).merge(non_mary_and_bob)
end
def test_relation_merging
devs = Developer.where("salary >= 80000").merge(Developer.limit(2)).merge(Developer.order("id ASC").where("id < 3"))
assert_equal [developers(:david), developers(:jamis)], devs.to_a