Add test for search_form_for with json format and
code cleanup, maintaining Ruby 1.8.7 compatibility with hash rocket syntax on the master branch for legacy users.
This commit is contained in:
parent
7bd621ba78
commit
ebda46372b
|
@ -26,54 +26,70 @@ module Ransack
|
|||
end
|
||||
|
||||
describe '#sort_link with default search_key' do
|
||||
subject { @controller.view_context.
|
||||
sort_link(
|
||||
[:main_app, Person.search(sorts: ['name desc'])],
|
||||
subject { @controller.view_context
|
||||
.sort_link(
|
||||
[:main_app, Person.search(:sorts => ['name desc'])],
|
||||
:name,
|
||||
controller: 'people'
|
||||
:controller => 'people'
|
||||
)
|
||||
}
|
||||
it { should match(
|
||||
if ActiveRecord::VERSION::STRING =~ /^3\.[1-2]\./
|
||||
/people\?q%5Bs%5D=name\+asc/
|
||||
else
|
||||
/people\?q(%5B|\[)s(%5D|\])=name\+asc/
|
||||
end)
|
||||
}
|
||||
it { should match /sort_link desc/ }
|
||||
it { should match /Full Name ▼/ }
|
||||
it {
|
||||
should match(
|
||||
if ActiveRecord::VERSION::STRING =~ /^3\.[1-2]\./
|
||||
/people\?q%5Bs%5D=name\+asc/
|
||||
else
|
||||
/people\?q(%5B|\[)s(%5D|\])=name\+asc/
|
||||
end
|
||||
)
|
||||
}
|
||||
it {
|
||||
should match /sort_link desc/
|
||||
}
|
||||
it {
|
||||
should match /Full Name ▼/
|
||||
}
|
||||
end
|
||||
|
||||
describe '#sort_link with default search_key defined as symbol' do
|
||||
subject { @controller.
|
||||
view_context.sort_link(
|
||||
Person.search({ :sorts => ['name desc'] }, :search_key => :people_search),
|
||||
:name, :controller => 'people'
|
||||
Person.search(
|
||||
{ :sorts => ['name desc'] }, :search_key => :people_search
|
||||
),
|
||||
:name,
|
||||
:controller => 'people'
|
||||
)
|
||||
}
|
||||
it {
|
||||
should match(
|
||||
if ActiveRecord::VERSION::STRING =~ /^3\.[1-2]\./
|
||||
/people\?people_search%5Bs%5D=name\+asc/
|
||||
else
|
||||
/people\?people_search(%5B|\[)s(%5D|\])=name\+asc/
|
||||
end
|
||||
)
|
||||
}
|
||||
it { should match(
|
||||
if ActiveRecord::VERSION::STRING =~ /^3\.[1-2]\./
|
||||
/people\?people_search%5Bs%5D=name\+asc/
|
||||
else
|
||||
/people\?people_search(%5B|\[)s(%5D|\])=name\+asc/
|
||||
end)
|
||||
}
|
||||
end
|
||||
|
||||
describe '#sort_link with default search_key defined as string' do
|
||||
subject {
|
||||
@controller.view_context.sort_link(
|
||||
Person.search({ :sorts => ['name desc'] }, :search_key => 'people_search'),
|
||||
:name, :controller => 'people'
|
||||
Person.search(
|
||||
{ :sorts => ['name desc'] }, :search_key => 'people_search'
|
||||
),
|
||||
:name,
|
||||
:controller => 'people'
|
||||
)
|
||||
}
|
||||
it {
|
||||
should match(
|
||||
if ActiveRecord::VERSION::STRING =~ /^3\.[1-2]\./
|
||||
/people\?people_search%5Bs%5D=name\+asc/
|
||||
else
|
||||
/people\?people_search(%5B|\[)s(%5D|\])=name\+asc/
|
||||
end
|
||||
)
|
||||
}
|
||||
it { should match(
|
||||
if ActiveRecord::VERSION::STRING =~ /^3\.[1-2]\./
|
||||
/people\?people_search%5Bs%5D=name\+asc/
|
||||
else
|
||||
/people\?people_search(%5B|\[)s(%5D|\])=name\+asc/
|
||||
end)
|
||||
}
|
||||
end
|
||||
|
||||
context 'view has existing parameters' do
|
||||
|
@ -83,8 +99,11 @@ module Ransack
|
|||
describe '#sort_link should not remove existing params' do
|
||||
subject {
|
||||
@controller.view_context.sort_link(
|
||||
Person.search({ :sorts => ['name desc'] }, :search_key => 'people_search'),
|
||||
:name, :controller => 'people'
|
||||
Person.search(
|
||||
{ :sorts => ['name desc'] }, :search_key => 'people_search'
|
||||
),
|
||||
:name,
|
||||
:controller => 'people'
|
||||
)
|
||||
}
|
||||
it {
|
||||
|
@ -95,7 +114,8 @@ module Ransack
|
|||
|
||||
describe '#search_form_for with default format' do
|
||||
subject {
|
||||
@controller.view_context.search_form_for(Person.search) {}
|
||||
@controller.view_context
|
||||
.search_form_for(Person.search) {}
|
||||
}
|
||||
it {
|
||||
should match /action="\/people"/
|
||||
|
@ -104,12 +124,24 @@ module Ransack
|
|||
|
||||
describe '#search_form_for with pdf format' do
|
||||
subject {
|
||||
@controller.view_context.search_form_for(Person.search, format: :pdf) {}
|
||||
@controller.view_context
|
||||
.search_form_for(Person.search, :format => :pdf) {}
|
||||
}
|
||||
it {
|
||||
should match /action="\/people.pdf"/
|
||||
}
|
||||
end
|
||||
|
||||
describe '#search_form_for with json format' do
|
||||
subject {
|
||||
@controller.view_context
|
||||
.search_form_for(Person.search, :format => :json) {}
|
||||
}
|
||||
it {
|
||||
should match /action="\/people.json"/
|
||||
}
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue