2010-10-18 19:54:50 -04:00
|
|
|
require '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
|
2011-05-27 17:21:40 -04:00
|
|
|
|
|
|
|
describe "eq" do
|
|
|
|
it "should compare the count" do
|
|
|
|
table = Arel::Table.new :users
|
|
|
|
table[:id].count.eq(2).to_sql.must_be_like %{
|
|
|
|
COUNT("users"."id") = 2
|
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
2012-08-18 22:33:25 -04:00
|
|
|
|
|
|
|
describe 'equality' do
|
|
|
|
it 'is equal with equal ivars' do
|
|
|
|
array = [Arel::Nodes::Count.new('foo'), Arel::Nodes::Count.new('foo')]
|
|
|
|
assert_equal 1, array.uniq.size
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'is not equal with different ivars' do
|
|
|
|
array = [Arel::Nodes::Count.new('foo'), Arel::Nodes::Count.new('foo!')]
|
|
|
|
assert_equal 2, array.uniq.size
|
|
|
|
end
|
|
|
|
end
|
2010-09-07 19:37:11 -04:00
|
|
|
end
|