Skip to content

Commit

Permalink
sort direction change to lower case.
Browse files Browse the repository at this point in the history
  • Loading branch information
mashiro committed Oct 24, 2011
1 parent a5cda64 commit 2811144
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
4 changes: 2 additions & 2 deletions lib/kashiwamochi/sort.rb
Expand Up @@ -3,7 +3,7 @@
module Kashiwamochi

class Sort
DIRS = {:asc => 'ASC', :desc => 'DESC'}.freeze
DIRS = {:asc => 'asc', :desc => 'desc'}.freeze

def initialize(key, dir = nil)
self.key = key
Expand Down Expand Up @@ -60,7 +60,7 @@ def self.sanitize(value)
end

def self.sanitize_dir(dir)
sanitize(dir).upcase != DIRS[:desc] ? DIRS[:asc] : DIRS[:desc]
sanitize(dir).downcase != DIRS[:desc] ? DIRS[:asc] : DIRS[:desc]
end

def self.parse(value)
Expand Down
6 changes: 3 additions & 3 deletions spec/kashiwamochi/action_view_extension_spec.rb
Expand Up @@ -8,13 +8,13 @@
describe Kashiwamochi::ActionViewExtension do
describe '#search_form_for' do
end
describe '#search_link_to' do

describe '#search_sort_link_to' do
before do
@q = Kashiwamochi::Query.new(:name => 'test', :s => ['name desc'])
@link = search_sort_link_to(@q, :name)
end
subject { @q }
it { should be_an_instance_of String }
#it { should be_an_instance_of String }
end
end
16 changes: 8 additions & 8 deletions spec/kashiwamochi/query_spec.rb
Expand Up @@ -43,22 +43,22 @@

context 'with empty' do
let(:keys) { [] }
it { should eq 'name ASC, created_at DESC' }
it { should eq 'name asc, created_at desc' }
end

context 'with :name' do
let(:keys) { [:name] }
it { should eq 'name ASC' }
it { should eq 'name asc' }
end

context 'with :created_at' do
let(:keys) { [:created_at] }
it { should eq 'created_at DESC' }
it { should eq 'created_at desc' }
end

context 'with [:name, :created_at]' do
let(:keys) { [:name, :created_at] }
it { should eq 'name ASC, created_at DESC' }
it { should eq 'name asc, created_at desc' }
end

context 'with [:foo, :bar]' do
Expand All @@ -69,9 +69,9 @@
end

describe '#to_option' do
context 'build with {:s => ["name asc", " ", "created_at desc"]}' do
before { @q = Kashiwamochi::Query.new(:s => ["name asc", " ", "created_at desc"]) }
subject { @q.sorts_query(keys) }
end
before { @q = Kashiwamochi::Query.new(:name => 'aira', :s => ["created_at desc"]) }
subject { @q.to_option }
it { should be_an_instance_of Hash }
it { should eq ({:name => 'aira', :s => ['created_at desc']}) }
end
end

0 comments on commit 2811144

Please sign in to comment.