Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Backport "Fix in [] to be false, in [] to be true"

This is in response to discussion at rails/rails#9216
The original commit was in response to discussion on 62207fa
  • Loading branch information...
commit d3a8fa952792c284eb63a91e36a593683ad76b93 1 parent b454667
@ernie ernie authored
Showing with 14 additions and 10 deletions.
  1. +10 −2 lib/arel/visitors/to_sql.rb
  2. +4 −8 test/visitors/test_to_sql.rb
View
12 lib/arel/visitors/to_sql.rb
@@ -370,11 +370,19 @@ def visit_Arel_Table o
end
def visit_Arel_Nodes_In o
- "#{visit o.left} IN (#{visit o.right})"
+ if Array === o.right && o.right.empty?
+ '1=0'
+ else
+ "#{visit o.left} IN (#{visit o.right})"
+ end
end
def visit_Arel_Nodes_NotIn o
- "#{visit o.left} NOT IN (#{visit o.right})"
+ if Array === o.right && o.right.empty?
+ '1=1'
+ else
+ "#{visit o.left} NOT IN (#{visit o.right})"
+ end
end
def visit_Arel_Nodes_And o
View
12 test/visitors/test_to_sql.rb
@@ -167,11 +167,9 @@ def dispatch
}
end
- it "should turn empty right to NULL" do
+ it "should return 1=0 when empty right which is always false" do
node = @attr.in []
- @visitor.accept(node).must_be_like %{
- "users"."id" IN (NULL)
- }
+ @visitor.accept(node).must_equal '1=0'
end
it 'can handle two dot ranges' do
@@ -255,11 +253,9 @@ def quote value, column = nil
}
end
- it "should turn empty right to NULL" do
+ it "should return 1=1 when empty right which is always true" do
node = @attr.not_in []
- @visitor.accept(node).must_be_like %{
- "users"."id" NOT IN (NULL)
- }
+ @visitor.accept(node).must_equal '1=1'
end
it 'can handle two dot ranges' do
Please sign in to comment.
Something went wrong with that request. Please try again.