mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
tests for passing a subquery to #in and #not_in
This commit is contained in:
parent
4bec8c8e9e
commit
54d62de817
1 changed files with 18 additions and 0 deletions
|
@ -137,6 +137,15 @@ module Arel
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'can handle subqueries' do
|
||||||
|
table = Table.new(:users)
|
||||||
|
subquery = table.project(:id).where(table[:name].eq('Aaron'))
|
||||||
|
node = @attr.in subquery
|
||||||
|
@visitor.accept(node).must_be_like %{
|
||||||
|
"users"."id" IN (SELECT id FROM "users" WHERE "users"."name" = 'Aaron')
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
it 'uses the same column for escaping values' do
|
it 'uses the same column for escaping values' do
|
||||||
@attr = Table.new(:users)[:name]
|
@attr = Table.new(:users)[:name]
|
||||||
visitor = Class.new(ToSql) do
|
visitor = Class.new(ToSql) do
|
||||||
|
@ -185,6 +194,15 @@ module Arel
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'can handle subqueries' do
|
||||||
|
table = Table.new(:users)
|
||||||
|
subquery = table.project(:id).where(table[:name].eq('Aaron'))
|
||||||
|
node = @attr.not_in subquery
|
||||||
|
@visitor.accept(node).must_be_like %{
|
||||||
|
"users"."id" NOT IN (SELECT id FROM "users" WHERE "users"."name" = 'Aaron')
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
it 'uses the same column for escaping values' do
|
it 'uses the same column for escaping values' do
|
||||||
@attr = Table.new(:users)[:name]
|
@attr = Table.new(:users)[:name]
|
||||||
visitor = Class.new(ToSql) do
|
visitor = Class.new(ToSql) do
|
||||||
|
|
Loading…
Reference in a new issue