2010-10-18 19:54:50 -04:00
|
|
|
require 'helper'
|
2010-10-18 18:41:21 -04:00
|
|
|
|
2010-08-23 13:14:02 -04:00
|
|
|
module Arel
|
|
|
|
module Nodes
|
|
|
|
describe 'sql literal' do
|
2011-08-08 18:23:51 -04:00
|
|
|
before do
|
|
|
|
@visitor = Visitors::ToSql.new Table.engine.connection_pool
|
|
|
|
end
|
|
|
|
|
2010-09-28 20:08:28 -04:00
|
|
|
describe 'sql' do
|
|
|
|
it 'makes a sql literal node' do
|
|
|
|
sql = Arel.sql 'foo'
|
2010-10-18 18:41:21 -04:00
|
|
|
sql.must_be_kind_of Arel::Nodes::SqlLiteral
|
2010-09-28 20:08:28 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2010-08-23 13:14:02 -04:00
|
|
|
describe 'count' do
|
|
|
|
it 'makes a count node' do
|
|
|
|
node = SqlLiteral.new('*').count
|
2011-08-08 18:23:51 -04:00
|
|
|
@visitor.accept(node).must_be_like %{ COUNT(*) }
|
2010-08-23 13:14:02 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'makes a distinct node' do
|
|
|
|
node = SqlLiteral.new('*').count true
|
2011-08-08 18:23:51 -04:00
|
|
|
@visitor.accept(node).must_be_like %{ COUNT(DISTINCT *) }
|
2010-08-23 13:14:02 -04:00
|
|
|
end
|
|
|
|
end
|
2010-10-27 09:43:20 -04:00
|
|
|
|
|
|
|
describe 'equality' do
|
|
|
|
it 'makes an equality node' do
|
|
|
|
node = SqlLiteral.new('foo').eq(1)
|
2011-08-08 18:23:51 -04:00
|
|
|
@visitor.accept(node).must_be_like %{ foo = 1 }
|
2010-10-27 09:43:20 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'grouped "or" equality' do
|
|
|
|
it 'makes a grouping node with an or node' do
|
|
|
|
node = SqlLiteral.new('foo').eq_any([1,2])
|
2011-08-08 18:23:51 -04:00
|
|
|
@visitor.accept(node).must_be_like %{ (foo = 1 OR foo = 2) }
|
2010-10-27 09:43:20 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'grouped "and" equality' do
|
|
|
|
it 'makes a grouping node with an or node' do
|
|
|
|
node = SqlLiteral.new('foo').eq_all([1,2])
|
2011-08-08 18:23:51 -04:00
|
|
|
@visitor.accept(node).must_be_like %{ (foo = 1 AND foo = 2) }
|
2010-10-27 09:43:20 -04:00
|
|
|
end
|
|
|
|
end
|
2010-08-23 13:14:02 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|