Skip to content

Commit

Permalink
Fix rummage params and queryable bug
Browse files Browse the repository at this point in the history
  • Loading branch information
thebugcatcher committed Oct 8, 2018
1 parent 2943e1d commit fa74ce0
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
9 changes: 5 additions & 4 deletions lib/rummage_ecto.ex
Original file line number Diff line number Diff line change
Expand Up @@ -157,10 +157,11 @@ defmodule Rummage.Ecto do
sort: Keyword.get(opts, :sort, RConfig.sort()),
paginate: Keyword.get(opts, :paginate, RConfig.paginate())]

rummage =
Enum.reduce(hooks, rummage, &format_hook_params(&1, &2, queryable, opts))

{Enum.reduce(hooks, queryable, &run_hook(&1, &2, rummage)), rummage}
Enum.reduce(hooks, {queryable, rummage}, fn(hook, {queryable, rummage}) ->
rummage = format_hook_params(hook, rummage, queryable, opts)
queryable = run_hook(hook, queryable, rummage)
{queryable, rummage}
end)
end

defp format_hook_params({_, nil}, rummage, _, _), do: rummage
Expand Down
4 changes: 2 additions & 2 deletions test/rummage_ecto_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ defmodule Rummage.EctoTest do
search: %{price: %{search_type: :lteq, search_term: 10, assoc: [],
search_expr: :where}},
sort: %{field: :name, order: :asc, assoc: []},
paginate: %{per_page: 2, page: 2, max_page: 4, total_count: 8},
paginate: %{per_page: 2, page: 2, max_page: 1, total_count: 2},
}
end

Expand Down Expand Up @@ -263,7 +263,7 @@ defmodule Rummage.EctoTest do
search: %{name: %{assoc: [inner: :category], search_term: "1",
search_type: :like, search_expr: :where}},
sort: %{field: :name, order: :asc, assoc: [inner: :category]},
paginate: %{per_page: 2, page: 1, max_page: 4, total_count: 8}
paginate: %{per_page: 2, page: 1, max_page: 1, total_count: 2}
}
end

Expand Down

0 comments on commit fa74ce0

Please sign in to comment.