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

Added tests for Nodes::NotIn.

This commit is contained in:
Rolf Timmermans 2010-11-17 22:18:25 +08:00 committed by Aaron Patterson
parent 7c9845e770
commit 35f25f643c

View file

@ -132,6 +132,52 @@ module Arel
end end
end end
describe "Nodes::NotIn" do
it "should know how to visit" do
node = @attr.not_in [1, 2, 3]
@visitor.accept(node).must_be_like %{
"users"."id" NOT IN (1, 2, 3)
}
end
it "should turn empty right to NULL" do
node = @attr.not_in []
@visitor.accept(node).must_be_like %{
"users"."id" NOT IN (NULL)
}
end
it 'can handle two dot ranges' do
node = @attr.not_in 1..3
@visitor.accept(node).must_be_like %{
"users"."id" < 1 OR "users"."id" > 3
}
end
it 'can handle three dot ranges' do
node = @attr.not_in 1...3
@visitor.accept(node).must_be_like %{
"users"."id" < 1 OR "users"."id" >= 3
}
end
it 'uses the same column for escaping values' do
@attr = Table.new(:users)[:name]
visitor = Class.new(ToSql) do
attr_accessor :expected
def quote value, column = nil
raise unless column == expected
super
end
end
in_node = Nodes::NotIn.new @attr, %w{ a b c }
visitor = visitor.new(Table.engine)
visitor.expected = @attr.column
visitor.accept(in_node).must_equal %("users"."name" NOT IN ('a', 'b', 'c'))
end
end
describe 'Equality' do describe 'Equality' do
it "should escape strings" do it "should escape strings" do
test = Table.new(:users)[:name].eq 'Aaron Patterson' test = Table.new(:users)[:name].eq 'Aaron Patterson'