aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/arel/algebra/primitives/ordering.rb13
-rw-r--r--spec/arel/algebra/unit/primitives/attribute_spec.rb4
-rw-r--r--spec/arel/algebra/unit/relations/order_spec.rb10
3 files changed, 21 insertions, 6 deletions
diff --git a/lib/arel/algebra/primitives/ordering.rb b/lib/arel/algebra/primitives/ordering.rb
index a60d794f27..3efb4c6280 100644
--- a/lib/arel/algebra/primitives/ordering.rb
+++ b/lib/arel/algebra/primitives/ordering.rb
@@ -1,7 +1,5 @@
module Arel
class Ordering
- attributes :attribute
- deriving :initialize, :==
delegate :relation, :to => :attribute
def bind(relation)
@@ -13,6 +11,13 @@ module Arel
end
end
- class Ascending < Ordering; end
- class Descending < Ordering; end
+ class Ascending < Ordering
+ attributes :attribute
+ deriving :initialize, :==
+ end
+
+ class Descending < Ordering
+ attributes :attribute
+ deriving :initialize, :==
+ end
end
diff --git a/spec/arel/algebra/unit/primitives/attribute_spec.rb b/spec/arel/algebra/unit/primitives/attribute_spec.rb
index afcf1237e0..2ca63ba48e 100644
--- a/spec/arel/algebra/unit/primitives/attribute_spec.rb
+++ b/spec/arel/algebra/unit/primitives/attribute_spec.rb
@@ -169,13 +169,13 @@ module Arel
describe Attribute::Orderings do
describe '#asc' do
it 'manufactures an ascending ordering' do
- pending
+ @attribute.asc.should == Ascending.new(@attribute)
end
end
describe '#desc' do
it 'manufactures a descending ordering' do
- pending
+ @attribute.desc.should == Descending.new(@attribute)
end
end
end
diff --git a/spec/arel/algebra/unit/relations/order_spec.rb b/spec/arel/algebra/unit/relations/order_spec.rb
index 4f163894c8..8b3c932fb9 100644
--- a/spec/arel/algebra/unit/relations/order_spec.rb
+++ b/spec/arel/algebra/unit/relations/order_spec.rb
@@ -6,6 +6,16 @@ module Arel
@relation = Table.new(:users)
@attribute = @relation[:id]
end
+
+ describe "#==" do
+ it "returns true when the Orders are for the same attribute and direction" do
+ Ascending.new(@attribute).should == Ascending.new(@attribute)
+ end
+
+ it "returns false when the Orders are for a diferent direction" do
+ Ascending.new(@attribute).should_not == Descending.new(@attribute)
+ end
+ end
end
end