From 5ab502a755d0031d229278b6f14123c45623dd04 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Tue, 7 Sep 2010 16:37:11 -0700 Subject: adding "as" and to_sql to count nodes --- spec/arel/attributes/attribute_spec.rb | 7 +++++++ spec/arel/nodes/count_spec.rb | 12 ++++++++++++ 2 files changed, 19 insertions(+) create mode 100644 spec/arel/nodes/count_spec.rb (limited to 'spec/arel') diff --git a/spec/arel/attributes/attribute_spec.rb b/spec/arel/attributes/attribute_spec.rb index e6e6483e64..f9eb56391e 100644 --- a/spec/arel/attributes/attribute_spec.rb +++ b/spec/arel/attributes/attribute_spec.rb @@ -3,6 +3,13 @@ require 'spec_helper' module Arel module Attributes describe 'attribute' do + describe '#count' do + it 'should return a count node' do + relation = Table.new(:users) + relation[:id].count.should be_kind_of Nodes::Count + end + end + describe '#eq' do it 'should return an equality node' do attribute = Attribute.new nil, nil, nil diff --git a/spec/arel/nodes/count_spec.rb b/spec/arel/nodes/count_spec.rb new file mode 100644 index 0000000000..7013a16429 --- /dev/null +++ b/spec/arel/nodes/count_spec.rb @@ -0,0 +1,12 @@ +require 'spec_helper' + +describe Arel::Nodes::Count do + describe "as" do + it 'should alias the count' do + table = Arel::Table.new :users + table[:id].count.as('foo').to_sql.should be_like %{ + COUNT("users"."id") AS foo + } + end + end +end -- cgit v1.2.3