diff --git a/test/changeset_parser_test.exs b/test/changeset_parser_test.exs index c6f8c96..617323d 100644 --- a/test/changeset_parser_test.exs +++ b/test/changeset_parser_test.exs @@ -44,6 +44,7 @@ defmodule AbsintheErrorPayload.ChangesetParserTest do field(:virtual, :string, virtual: true) field(:published_at, :naive_datetime) field(:language, Ecto.Enum, values: [:en, :fr]) + field(:metadata, {:array, :map}) belongs_to(:author, Author) has_many(:tags, Tag) @@ -182,6 +183,23 @@ defmodule AbsintheErrorPayload.ChangesetParserTest do assert %ValidationMessage{code: :required, field: "tags.0.name", key: :name} = first assert %ValidationMessage{code: :required, field: "tags.1.name", key: :name} = second end + + test "nested nil has many fields with errors" do + changeset = + %{"tags" => nil} + |> changeset() + |> cast_assoc(:tags, + with: fn tag, params -> + tag + |> cast(params, ~w(name)a) + |> validate_required(:name) + end + ) + + result = ChangesetParser.extract_messages(changeset) + assert [first] = result + assert %ValidationMessage{code: :association, field: :tags, key: :tags, message: "is invalid", options: [%{key: :type, value: "array-map"}]} = first + end end describe "construct_message/2" do