Skip to content

Commit 8822418

Browse files
authored
chore: Add failing test for after action transaction bug. (#88)
1 parent 27430e8 commit 8822418

File tree

3 files changed

+34
-0
lines changed

3 files changed

+34
-0
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
defmodule AshSqlite.Test.FailingAfterActionChange do
2+
@moduledoc false
3+
use Ash.Resource.Change
4+
5+
def change(changeset, _, _) do
6+
changeset
7+
|> Ash.Changeset.after_action(fn _changeset, _record ->
8+
{:error, "Things could always be better"}
9+
end)
10+
end
11+
end

test/support/resources/post.ex

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@ defmodule AshSqlite.Test.Post do
6060
argument(:amount, :integer, default: 1)
6161
change(atomic_update(:score, expr((score || 0) + ^arg(:amount))))
6262
end
63+
64+
create :failing_after_action do
65+
change(AshSqlite.Test.FailingAfterActionChange)
66+
end
6367
end
6468

6569
identities do

test/transaction_test.exs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
defmodule AshSqlite.Test.TransactionTest do
2+
@moduledoc false
3+
use AshSqlite.RepoCase, async: false
4+
5+
test "when an after action hook fails, it rolls back the transaction" do
6+
assert [] =
7+
AshSqlite.Test.Post
8+
|> AshSqlite.TestRepo.all()
9+
10+
assert {:error, _} =
11+
AshSqlite.Test.Post
12+
|> Ash.Changeset.for_create(:failing_after_action, %{title: "turtle the title"})
13+
|> Ash.create()
14+
15+
assert [] =
16+
AshSqlite.Test.Post
17+
|> AshSqlite.TestRepo.all()
18+
end
19+
end

0 commit comments

Comments
 (0)