fix: support only predicate in params

This commit is contained in:
Zach Daniel 2021-12-05 20:24:08 -05:00
parent 032f7d6850
commit 4c4ca71609
2 changed files with 9 additions and 5 deletions

View file

@ -87,18 +87,18 @@ defmodule AshPhoenix.FilterForm do
At present, no validation actually occurs, but this will eventually be added. At present, no validation actually occurs, but this will eventually be added.
""" """
def validate(form, params \\ %{}) do def validate(form, params \\ %{}) do
params = sanitize_params(params)
params = params =
if is_predicate?(params) do if is_predicate?(params) do
%{ %{
operator: :and, "operator" => "and",
components: %{"0" => params} "components" => %{"0" => params}
} }
else else
params params
end end
params = sanitize_params(params)
%{ %{
form form
| params: params, | params: params,

View file

@ -77,7 +77,11 @@ defmodule AshPhoenix.FilterFormTest do
describe "to_filter/1" do describe "to_filter/1" do
test "An empty form returns the filter `true`" do test "An empty form returns the filter `true`" do
form = FilterForm.new(Post) form = FilterForm.new(Post)
assert Ash.Query.equivalent_to?(FilterForm.filter!(Post, form), true)
assert Ash.Query.equivalent_to?(
FilterForm.filter!(Post, form),
true
)
end end
test "A form with a single predicate returns the corresponding filter" do test "A form with a single predicate returns the corresponding filter" do