Skip to content

Commit

Permalink
Bugfix for #1365 (#1374)
Browse files Browse the repository at this point in the history
* Failing tests

* bugfix
  • Loading branch information
stereobooster committed Nov 14, 2022
1 parent c08b4c4 commit 8e43558
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
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

0 comments on commit 8e43558

Please sign in to comment.