diff options
Diffstat (limited to 'spec')
-rw-r--r-- | spec/arel/attributes/attribute_spec.rb | 17 | ||||
-rw-r--r-- | spec/arel/nodes/sum_spec.rb | 12 |
2 files changed, 29 insertions, 0 deletions
diff --git a/spec/arel/attributes/attribute_spec.rb b/spec/arel/attributes/attribute_spec.rb index 018f23ea9f..449cc38dad 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 '#maximum' do + it 'should create a MAX node' do + relation = Table.new(:users) + relation[:id].maximum.should be_kind_of Nodes::Max + end + + # FIXME: backwards compat. Is this really necessary? + it 'should set the alias to "max_id"' do + relation = Table.new(:users) + mgr = relation.project relation[:id].maximum + mgr.to_sql.should be_like %{ + SELECT MAX("users"."id") AS max_id + FROM "users" + } + end + end + describe '#sum' do it 'should create a SUM node' do relation = Table.new(:users) diff --git a/spec/arel/nodes/sum_spec.rb b/spec/arel/nodes/sum_spec.rb new file mode 100644 index 0000000000..7691b06590 --- /dev/null +++ b/spec/arel/nodes/sum_spec.rb @@ -0,0 +1,12 @@ +require 'spec_helper' + +describe Arel::Nodes::Sum do + describe "as" do + it 'should alias the sum' do + table = Arel::Table.new :users + table[:id].sum.as('foo').to_sql.should be_like %{ + SUM("users"."id") AS foo + } + end + end +end |