2010-10-18 19:34:44 -04:00
|
|
|
require 'test_helper'
|
2010-09-07 19:37:11 -04:00
|
|
|
|
|
|
|
describe Arel::Nodes::Count do
|
2010-09-10 21:19:31 -04:00
|
|
|
describe 'backwards compatibility' do
|
|
|
|
it 'must be an expression' do
|
2010-10-18 18:41:21 -04:00
|
|
|
Arel::Nodes::Count.new('foo').must_be_kind_of Arel::Expression
|
2010-09-10 21:19:31 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2010-09-07 19:37:11 -04:00
|
|
|
describe "as" do
|
|
|
|
it 'should alias the count' do
|
|
|
|
table = Arel::Table.new :users
|
2010-10-18 18:41:21 -04:00
|
|
|
table[:id].count.as('foo').to_sql.must_be_like %{
|
2010-09-07 19:37:11 -04:00
|
|
|
COUNT("users"."id") AS foo
|
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|