From eef61ab909b614ce6f2d100cfb50044c063bc24a Mon Sep 17 00:00:00 2001 From: Ernie Miller Date: Wed, 29 Sep 2010 20:08:57 -0400 Subject: Support Attribute#asc and Attribute#desc to create orderings --- spec/attributes/attribute_spec.rb | 32 ++++++++++++++++++++++++++++++++ spec/visitors/to_sql_spec.rb | 9 +++++++++ 2 files changed, 41 insertions(+) (limited to 'spec') diff --git a/spec/attributes/attribute_spec.rb b/spec/attributes/attribute_spec.rb index c6d4fcebd4..562781ade9 100644 --- a/spec/attributes/attribute_spec.rb +++ b/spec/attributes/attribute_spec.rb @@ -601,6 +601,38 @@ module Arel } end end + + describe '#asc' do + it 'should create an Ordering node' do + relation = Table.new(:users) + relation[:id].asc.should be_kind_of Nodes::Ordering + end + + it 'should generate ASC in sql' do + relation = Table.new(:users) + mgr = relation.project relation[:id] + mgr.order relation[:id].asc + mgr.to_sql.should be_like %{ + SELECT "users"."id" FROM "users" ORDER BY "users"."id" ASC + } + end + end + + describe '#desc' do + it 'should create an Ordering node' do + relation = Table.new(:users) + relation[:id].desc.should be_kind_of Nodes::Ordering + end + + it 'should generate DESC in sql' do + relation = Table.new(:users) + mgr = relation.project relation[:id] + mgr.order relation[:id].desc + mgr.to_sql.should be_like %{ + SELECT "users"."id" FROM "users" ORDER BY "users"."id" DESC + } + end + end end describe 'equality' do diff --git a/spec/visitors/to_sql_spec.rb b/spec/visitors/to_sql_spec.rb index 1302d73e1c..a2862e4c4f 100644 --- a/spec/visitors/to_sql_spec.rb +++ b/spec/visitors/to_sql_spec.rb @@ -66,6 +66,15 @@ module Arel @visitor.accept(test).should be_like %{ "users"."id" = 't' } end + describe "Nodes::Ordering" do + it "should know how to visit" do + node = @attr.desc + @visitor.accept(node).should be_like %{ + "users"."id" DESC + } + end + end + describe "Nodes::In" do it "should know how to visit" do node = @attr.in [1, 2, 3] -- cgit v1.2.3