Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix crash when using q=string as parameter #1374

Merged
merged 2 commits into from
Nov 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/ransack/helpers/form_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,8 @@ def search_and_sort_params
end

def search_params
@params[@search.context.search_key].presence || {}
query_params = @params[@search.context.search_key]
query_params.is_a?(Hash) ? query_params : {}
end

def sort_params
Expand Down
26 changes: 26 additions & 0 deletions spec/ransack/helpers/form_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,32 @@ module Helpers
}
end

describe '#sort_link works even if search params are a string' do
before { @controller.view_context.params[:q] = 'input error' }
specify {
expect { @controller.view_context
.sort_link(
Person.ransack({}),
:name,
controller: 'people'
)
}.not_to raise_error
}
end

describe '#sort_url works even if search params are a string' do
before { @controller.view_context.params[:q] = 'input error' }
specify {
expect { @controller.view_context
.sort_url(
Person.ransack({}),
:name,
controller: 'people'
)
}.not_to raise_error
}
end

describe '#sort_link with search_key defined as a string' do
subject { @controller.view_context
.sort_link(
Expand Down