ash_postgres/test/ecto_compatibility_test.exs
Alan Heywood acc947292d Add failing test for inserting via Ecto.Repo.insert!
It should be possible to use this function, and it did work as of ash
v2.5.9. This test fails as of ash v2.5.10, which introduced adding
relationships to underlying ecto schemas. The bug is related to a
has_many relationship being present on the resource.

The test fails with:

1) test call Ecto.Repo.insert! via Ash Repo (AshPostgres.EctoCompatibilityTest)
     test/ecto_compatibility_test.exs:6
     ** (Ecto.InvalidChangesetError) could not perform insert because changeset is invalid.

     Errors

         %{posts: [{"is invalid", [type: {:array, :map}]}]}

     Applied changes

         %{name: "The Org"}

     Params

         nil

     Changeset

         #Ecto.Changeset<
           action: :insert,
           changes: %{name: "The Org"},
           errors: [posts: {"is invalid", [type: {:array, :map}]}],
           data: #AshPostgres.Test.Organization<>,
           valid?: false
         >

     code: |> AshPostgres.TestRepo.insert!()
     stacktrace:
       (ecto 3.9.4) lib/ecto/repo/schema.ex:270: Ecto.Repo.Schema.insert!/4
       test/ecto_compatibility_test.exs:9: (test)
2023-01-30 10:40:45 +10:00

12 lines
305 B
Elixir

defmodule AshPostgres.EctoCompatibilityTest do
use AshPostgres.RepoCase, async: false
require Ash.Query
test "call Ecto.Repo.insert! via Ash Repo" do
org =
%AshPostgres.Test.Organization{name: "The Org"}
|> AshPostgres.TestRepo.insert!()
assert org.name == "The Org"
end
end