test: add test confirming embedded array behavior

This commit is contained in:
Zach Daniel 2022-12-18 02:35:42 -05:00
parent 360274c7c0
commit 01d1a8aa5d
2 changed files with 19 additions and 1 deletions

View file

@ -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

View file

@ -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