Add tests & fix for sort_link `default_order` parsing
This commit is contained in:
parent
3322f6fcfa
commit
d17ec758f1
|
@ -128,7 +128,7 @@ module Ransack
|
||||||
|
|
||||||
def extract_options_and_mutate_args!(args)
|
def extract_options_and_mutate_args!(args)
|
||||||
if args.first.is_a? Hash
|
if args.first.is_a? Hash
|
||||||
args.shift
|
args.shift.with_indifferent_access
|
||||||
else
|
else
|
||||||
{}
|
{}
|
||||||
end
|
end
|
||||||
|
|
|
@ -121,7 +121,7 @@ module Ransack
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '#sort_link with default search_key defined as string' do
|
describe '#sort_link with search_key defined as a string' do
|
||||||
subject {
|
subject {
|
||||||
@controller.view_context.sort_link(
|
@controller.view_context.sort_link(
|
||||||
Person.search(
|
Person.search(
|
||||||
|
@ -142,6 +142,18 @@ module Ransack
|
||||||
}
|
}
|
||||||
end
|
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
|
describe '#sort_link with multiple search_keys defined as an array' do
|
||||||
subject { @controller.view_context
|
subject { @controller.view_context
|
||||||
.sort_link(
|
.sort_link(
|
||||||
|
@ -205,13 +217,31 @@ module Ransack
|
||||||
it { should match /Full Name ▼/ }
|
it { should match /Full Name ▼/ }
|
||||||
end
|
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
|
subject { @controller.view_context
|
||||||
.sort_link(
|
.sort_link(
|
||||||
[:main_app, Person.search()],
|
[:main_app, Person.search()],
|
||||||
:name, [:name, :email],
|
:name, [:name, :email],
|
||||||
:controller => 'people',
|
: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 {
|
it {
|
||||||
|
|
Loading…
Reference in New Issue