Skip to content

Commit

Permalink
Merge pull request #1462 from mamhoff/allow-sort-parameter-in-resourc…
Browse files Browse the repository at this point in the history
…e-controller

Fix sorting in Resources controller
  • Loading branch information
tvdeyen authored Aug 20, 2018
2 parents efd97d9 + ea1b4f0 commit 878ad35
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
5 changes: 4 additions & 1 deletion app/controllers/alchemy/admin/resources_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,10 @@ def common_search_filter_includes
[
# contrary to Rails' documentation passing an empty hash to permit all keys does not work
{options: options_from_params.keys},
{q: resource_handler.search_field_name},
{q: [
resource_handler.search_field_name,
:s
]},
:tagged_with,
:filter,
:page
Expand Down
9 changes: 9 additions & 0 deletions spec/controllers/alchemy/admin/resources_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,15 @@
expect(assigns(:events)).not_to include(lustig)
end
end

context 'with sort parameter given' do
let(:params) { {q: {s: "name asc"}} }

it "returns records in the right order" do
get :index, params: params
expect(assigns(:events)).to eq([lustig, peter])
end
end
end
end

Expand Down

0 comments on commit 878ad35

Please sign in to comment.