Skip to content

Commit ea4c416

Browse files
committed
write some sexy specs
1 parent 11bddb3 commit ea4c416

File tree

4 files changed

+22
-5
lines changed

4 files changed

+22
-5
lines changed

Gemfile.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
PATH
22
remote: .
33
specs:
4-
searchlogic (2.5.9)
4+
searchlogic (2.5.10)
55
activerecord (~> 2.3.12)
66
activesupport (~> 2.3.12)
77

lib/searchlogic/search/ordering.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ class Search
33
module Ordering
44
# Returns the column we are currently ordering by
55
def ordering_by
6-
@ordering_by ||= order && order.to_s.gsub(/^(ascend|descend)_by_/, '')
6+
@ordering_by ||= order && order.to_s.match(/^(ascend|descend)_by_(.*)$/).try(:[], 2)
77
end
88

99
def ordering_direction

spec/searchlogic/named_scopes/ordering_spec.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55
%w(bjohnson thunt).each { |username| User.create(:username => username) }
66
User.ascend_by_username.all.should == User.all(:order => "username ASC")
77
end
8-
8+
99
it "should have descending" do
1010
%w(bjohnson thunt).each { |username| User.create(:username => username) }
1111
User.descend_by_username.all.should == User.all(:order => "username DESC")
1212
end
13-
13+
1414
it "should have order" do
1515
User.order("ascend_by_username").proxy_options.should == User.ascend_by_username.proxy_options
1616
end
@@ -21,7 +21,7 @@
2121
User.named_scope(:ascend_by_custom, :order => "username ASC, name DESC")
2222
User.order("ascend_by_custom").proxy_options.should == User.ascend_by_custom.proxy_options
2323
end
24-
24+
2525
it "should have priorty to columns over conflicting association columns" do
2626
Company.ascend_by_users_count
2727
end

spec/searchlogic/search_spec.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,23 @@
372372
end
373373
end
374374

375+
context "#ordering_direction" do
376+
it "should return nil if we aren't ordering" do
377+
search = User.search
378+
search.ordering_direction.should be_nil
379+
end
380+
381+
it "should return the column name for ascending" do
382+
search = User.search(:order => "ascend_by_ticket_request_event_occurs_at")
383+
search.ordering_direction.should == "ascend"
384+
end
385+
386+
it "should return the column name for descending" do
387+
search = User.search(:order => "descend_by_ticket_request_event_occurs_at")
388+
search.ordering_direction.should == "descend"
389+
end
390+
end
391+
375392
context "#method_missing" do
376393
context "setting" do
377394
it "should call named scopes for conditions" do

0 commit comments

Comments
 (0)