From 7b8944cb7662509d7ba6869ff571518ac7f848ea Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Wed, 8 Sep 2010 14:36:10 -0700 Subject: adding a sum node --- spec/arel/attributes/attribute_spec.rb | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'spec/arel') diff --git a/spec/arel/attributes/attribute_spec.rb b/spec/arel/attributes/attribute_spec.rb index d6f07f8d99..018f23ea9f 100644 --- a/spec/arel/attributes/attribute_spec.rb +++ b/spec/arel/attributes/attribute_spec.rb @@ -3,6 +3,23 @@ require 'spec_helper' module Arel module Attributes describe 'attribute' do + describe '#sum' do + it 'should create a SUM node' do + relation = Table.new(:users) + relation[:id].sum.should be_kind_of Nodes::Sum + end + + # FIXME: backwards compat. Is this really necessary? + it 'should set the alias to "sum_id"' do + relation = Table.new(:users) + mgr = relation.project relation[:id].sum + mgr.to_sql.should be_like %{ + SELECT SUM("users"."id") AS sum_id + FROM "users" + } + end + end + describe '#count' do it 'should return a count node' do relation = Table.new(:users) -- cgit v1.2.3