mirror of
https://github.com/ash-project/ash.git
synced 2024-09-19 13:03:02 +12:00
fix: union array argument/attribute handling when current attribute is (#1023)
This commit is contained in:
parent
417d39e7de
commit
45b76c209d
2 changed files with 61 additions and 1 deletions
|
@ -700,6 +700,7 @@ defmodule Ash.Type.Union do
|
|||
end) do
|
||||
old_values_by_type =
|
||||
old_values
|
||||
|> List.wrap()
|
||||
|> Stream.with_index()
|
||||
|> Stream.map(fn {item, index} ->
|
||||
Map.put(item, :__index__, index)
|
||||
|
@ -860,6 +861,7 @@ defmodule Ash.Type.Union do
|
|||
end) do
|
||||
old_values_by_type =
|
||||
old_values
|
||||
|> List.wrap()
|
||||
|> Stream.with_index()
|
||||
|> Stream.map(fn {item, index} ->
|
||||
Map.put(item, :__index__, index)
|
||||
|
|
|
@ -72,7 +72,7 @@ defmodule Ash.Test.Type.UnionTest do
|
|||
new_thing =
|
||||
Ash.Changeset.get_argument(changeset, :new_thing)
|
||||
|
||||
things = Ash.Changeset.get_attribute(changeset, :things)
|
||||
things = Ash.Changeset.get_attribute(changeset, :things) || []
|
||||
|
||||
Ash.Changeset.change_attribute(
|
||||
changeset,
|
||||
|
@ -81,6 +81,11 @@ defmodule Ash.Test.Type.UnionTest do
|
|||
)
|
||||
end
|
||||
end
|
||||
|
||||
update :add_things do
|
||||
require_atomic? false
|
||||
accept [:things]
|
||||
end
|
||||
end
|
||||
|
||||
attributes do
|
||||
|
@ -384,4 +389,57 @@ defmodule Ash.Test.Type.UnionTest do
|
|||
|> Ash.Changeset.for_update(:add_thing, %{new_thing: %{type: :foo, foo: "foo"}})
|
||||
|> Ash.update()
|
||||
end
|
||||
|
||||
test "it should handle union arguments appropriately" do
|
||||
assert {:ok, _} =
|
||||
Example
|
||||
|> Ash.Changeset.for_create(:create, %{things: []})
|
||||
|> Ash.create!()
|
||||
|> Ash.Changeset.for_update(:add_thing, %{
|
||||
new_thing: %Ash.Union{type: :foo, value: %{type: :foo, foo: "foo"}}
|
||||
})
|
||||
|> Ash.update()
|
||||
end
|
||||
|
||||
test "it should cast union arguments appropriately when the array is nil" do
|
||||
assert {:ok, _} =
|
||||
Example
|
||||
|> Ash.Changeset.for_create(:create, %{})
|
||||
|> Ash.create!()
|
||||
|> Ash.Changeset.for_update(:add_thing, %{new_thing: %{type: :foo, foo: "foo"}})
|
||||
|> Ash.update()
|
||||
end
|
||||
|
||||
test "it should handle union arguments appropriately when the array is nil" do
|
||||
assert {:ok, _} =
|
||||
Example
|
||||
|> Ash.Changeset.for_create(:create, %{})
|
||||
|> Ash.create!()
|
||||
|> Ash.Changeset.for_update(:add_thing, %{
|
||||
new_thing: %Ash.Union{type: :foo, value: %{type: :foo, foo: "foo"}}
|
||||
})
|
||||
|> Ash.update()
|
||||
end
|
||||
|
||||
test "it should handle union attribute" do
|
||||
assert {:ok, _} =
|
||||
Example
|
||||
|> Ash.Changeset.for_create(:create, %{})
|
||||
|> Ash.create!()
|
||||
|> Ash.Changeset.for_update(:add_things, %{
|
||||
things: [%Ash.Union{type: :foo, value: %{type: :foo, foo: "foo"}}]
|
||||
})
|
||||
|> Ash.update()
|
||||
end
|
||||
|
||||
test "it should handle union attribute appropriately when the array is nil" do
|
||||
assert {:ok, _} =
|
||||
Example
|
||||
|> Ash.Changeset.for_create(:create, %{})
|
||||
|> Ash.create!()
|
||||
|> Ash.Changeset.for_update(:add_things, %{
|
||||
things: [%Ash.Union{type: :foo, value: %{type: :foo, foo: "foo"}}]
|
||||
})
|
||||
|> Ash.update()
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue