From fc6c9b37618a1734f5d751b1ff4a318eaacbda01 Mon Sep 17 00:00:00 2001 From: "morten.lund@maskon.no" Date: Fri, 29 Aug 2025 15:14:34 +0200 Subject: [PATCH] Expected this to leave any records behind --- test/bulk_create_test.exs | 17 +++++++++++++++++ test/support/resources/post.ex | 6 ++++++ 2 files changed, 23 insertions(+) diff --git a/test/bulk_create_test.exs b/test/bulk_create_test.exs index d9f5767..b52350f 100644 --- a/test/bulk_create_test.exs +++ b/test/bulk_create_test.exs @@ -140,4 +140,21 @@ defmodule AshSqlite.BulkCreateTest do |> Ash.read!() end end + + describe "transaction errors" do + @tag this: "this" + test "transaction errors rolls back" do + org = + AshSqlite.Test.Organization + |> Ash.Changeset.for_create(:create, %{name: "foo"}) + |> Ash.create!() + + + assert {:error, _} = AshSqlite.Test.Post + |> Ash.Changeset.for_create(:create_with_failing_change, %{organization_id: org.id, title: "foo"}) + |> Ash.create() + + assert {:ok, []} = Ash.read(AshSqlite.Test.Post) + end + end end diff --git a/test/support/resources/post.ex b/test/support/resources/post.ex index 48001e5..58a4879 100644 --- a/test/support/resources/post.ex +++ b/test/support/resources/post.ex @@ -64,6 +64,12 @@ defmodule AshSqlite.Test.Post do destroy :destroy_only_freds do change(filter(expr(title == "fred"))) end + + create :create_with_failing_change do + change after_action(fn _cs, _post, _ctx -> + {:error, field: :org, message: "Failing action"} + end) + end end identities do