Permalink
Browse files

add Search#ordering_by

  • Loading branch information...
1 parent e9cad2f commit b4f8ca887e5ce96b6d467ba6f6f91b75d0c52575 @binarylogic committed Apr 15, 2010
Showing with 22 additions and 0 deletions.
  1. +5 −0 lib/searchlogic/search.rb
  2. +17 −0 spec/searchlogic/search_spec.rb
@@ -97,6 +97,11 @@ def delete(*names)
self
end
+ # Returns the column we are currently ordering by
+ def ordering_by
+ order && order.gsub(/^(ascend|descend)_by_/, '')
+ end
+
private
def method_missing(name, *args, &block)
condition_name = condition_name(name)
@@ -335,6 +335,23 @@
end
end
+ context "#ordering_by" do
+ it "should return nil if we aren't ordering" do
+ search = User.search
+ search.ordering_by.should be_nil
+ end
+
+ it "should return the column name for ascending" do
+ search = User.search(:order => "ascend_by_first_name")
+ search.ordering_by.should == "first_name"
+ end
+
+ it "should return the column name for descending" do
+ search = User.search(:order => "descend_by_first_name")
+ search.ordering_by.should == "first_name"
+ end
+ end
+
context "#method_missing" do
context "setting" do
it "should call named scopes for conditions" do

0 comments on commit b4f8ca8

Please sign in to comment.