File tree Expand file tree Collapse file tree 4 files changed +22
-5
lines changed Expand file tree Collapse file tree 4 files changed +22
-5
lines changed Original file line number Diff line number Diff line change 11PATH
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
Original file line number Diff line number Diff 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
Original file line number Diff line number Diff line change 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
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
Original file line number Diff line number Diff line change 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
You can’t perform that action at this time.
0 commit comments