Add tests & fix for sort_link `default_order` parsing

This commit is contained in:
Jon Atack 2014-12-18 23:51:02 +01:00
parent 3322f6fcfa
commit d17ec758f1
2 changed files with 34 additions and 4 deletions

View File

@ -128,7 +128,7 @@ module Ransack
def extract_options_and_mutate_args!(args)
if args.first.is_a? Hash
args.shift
args.shift.with_indifferent_access
else
{}
end

View File

@ -121,7 +121,7 @@ module Ransack
}
end
describe '#sort_link with default search_key defined as string' do
describe '#sort_link with search_key defined as a string' do
subject {
@controller.view_context.sort_link(
Person.search(
@ -142,6 +142,18 @@ module Ransack
}
end
describe '#sort_link with default_order defined with a string key' do
subject { @controller.view_context
.sort_link(
[:main_app, Person.search()],
:name,
:controller => 'people',
'default_order' => 'desc'
)
}
it { should_not match /default_order/ }
end
describe '#sort_link with multiple search_keys defined as an array' do
subject { @controller.view_context
.sort_link(
@ -205,13 +217,31 @@ module Ransack
it { should match /Full Name ▼/ }
end
describe '#sort_link with multiple search_keys should allow a default_order to be specified' do
describe '#sort_link with multiple search_keys and default_order specified as a string' do
subject { @controller.view_context
.sort_link(
[:main_app, Person.search()],
:name, [:name, :email],
:controller => 'people',
:default_order => 'desc'
'default_order' => 'desc'
)
}
it {
should match(
/people\?q(%5B|\[)s(%5D|\])(%5B|\[)(%5D|\])=name\+desc&q(%5B|\[)s(%5D|\])(%5B|\[)(%5D|\])=email\+desc/
)
}
it { should match /sort_link/ }
it { should match /Full Name/ }
end
describe '#sort_link with multiple search_keys and default_order specified as a symbol' do
subject { @controller.view_context
.sort_link(
[:main_app, Person.search()],
:name, [:name, :email],
:controller => 'people',
:default_order => :desc
)
}
it {