diff --git a/test/embeddable_resource_test.exs b/test/embeddable_resource_test.exs index e68e933..2201acb 100644 --- a/test/embeddable_resource_test.exs +++ b/test/embeddable_resource_test.exs @@ -1,7 +1,7 @@ defmodule AshPostgres.EmbeddableResourceTest do @moduledoc false use AshPostgres.RepoCase, async: false - alias AshPostgres.Test.{Api, Post} + alias AshPostgres.Test.{Api, Author, Bio, Post} require Ash.Query @@ -18,4 +18,17 @@ defmodule AshPostgres.EmbeddableResourceTest do assert %{calc_returning_json: %AshPostgres.Test.Money{amount: 100, currency: :usd}} = Api.load!(post, :calc_returning_json) end + + test "embeds with list attributes set to nil are loaded as nil" do + post = + Author + |> Ash.Changeset.new(%{bio: %Bio{list_of_strings: nil}}) + |> Api.create!() + + assert is_nil(post.bio.list_of_strings) + + post = Api.reload!(post) + + assert is_nil(post.bio.list_of_strings) + end end diff --git a/test/support/resources/bio.ex b/test/support/resources/bio.ex index 80796ba..9f89fbe 100644 --- a/test/support/resources/bio.ex +++ b/test/support/resources/bio.ex @@ -10,5 +10,10 @@ defmodule AshPostgres.Test.Bio do attribute(:title, :string) attribute(:bio, :string) attribute(:years_of_experience, :integer) + + attribute :list_of_strings, {:array, :string} do + allow_nil?(true) + default(nil) + end end end