aboutsummaryrefslogtreecommitdiffstats
path: root/spec
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2010-09-08 15:08:00 -0700
committerAaron Patterson <aaron.patterson@gmail.com>2010-09-08 15:08:00 -0700
commit7b122f9a336c8c780dcc5a29074f17f3ec493dc6 (patch)
treef1d76bf30258e0413d9ac032493225f3c4fdaddb /spec
parent301dfa5a3888a41ea36324a390241538249e9a53 (diff)
downloadrails-7b122f9a336c8c780dcc5a29074f17f3ec493dc6.tar.gz
rails-7b122f9a336c8c780dcc5a29074f17f3ec493dc6.tar.bz2
rails-7b122f9a336c8c780dcc5a29074f17f3ec493dc6.zip
adding maximum nodes
Diffstat (limited to 'spec')
-rw-r--r--spec/arel/attributes/attribute_spec.rb17
-rw-r--r--spec/arel/nodes/sum_spec.rb12
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