mirror of
https://github.com/ash-project/ash.git
synced 2024-09-20 05:23:03 +12:00
fix: False default value for argument is nil in changeset (#364)
This commit is contained in:
parent
3a69b3104e
commit
548247a8b7
2 changed files with 24 additions and 1 deletions
|
@ -1400,7 +1400,11 @@ defmodule Ash.Changeset do
|
|||
@doc "Gets the value of an argument provided to the changeset"
|
||||
@spec get_argument(t, atom) :: term
|
||||
def get_argument(changeset, argument) when is_atom(argument) do
|
||||
Map.get(changeset.arguments, argument) || Map.get(changeset.arguments, to_string(argument))
|
||||
if Map.has_key?(changeset.arguments, argument) do
|
||||
Map.get(changeset.arguments, argument)
|
||||
else
|
||||
Map.get(changeset.arguments, to_string(argument))
|
||||
end
|
||||
end
|
||||
|
||||
@doc "fetches the value of an argument provided to the changeset or `:error`"
|
||||
|
|
|
@ -25,6 +25,16 @@ defmodule Ash.Test.Changeset.ChangesetTest do
|
|||
allow_nil? false
|
||||
end
|
||||
|
||||
argument :false_optional_argument, :boolean do
|
||||
allow_nil? false
|
||||
default false
|
||||
end
|
||||
|
||||
argument :true_optional_argument, :boolean do
|
||||
allow_nil? false
|
||||
default true
|
||||
end
|
||||
|
||||
validate confirm(:name, :confirm_name)
|
||||
end
|
||||
end
|
||||
|
@ -855,6 +865,15 @@ defmodule Ash.Test.Changeset.ChangesetTest do
|
|||
|> Api.create!(action: :create_with_confirmation)
|
||||
end
|
||||
end
|
||||
|
||||
test "optional arguments should use the default" do
|
||||
changeset =
|
||||
Category
|
||||
|> Changeset.for_create(:create_with_confirmation)
|
||||
|
||||
assert Changeset.get_argument(changeset, :true_optional_argument) == true
|
||||
assert Changeset.get_argument(changeset, :false_optional_argument) == false
|
||||
end
|
||||
end
|
||||
|
||||
describe "for_<action>" do
|
||||
|
|
Loading…
Reference in a new issue