mirror of
https://github.com/ash-project/ash_postgres.git
synced 2024-09-21 05:53:18 +12:00
43 lines
1.1 KiB
Elixir
43 lines
1.1 KiB
Elixir
defmodule AshPostgres.DestroyTest do
|
|
use AshPostgres.RepoCase, async: false
|
|
alias AshPostgres.Test.Post
|
|
|
|
test "destroy action destroys the record" do
|
|
post =
|
|
Post
|
|
|> Ash.Changeset.for_create(:create, %{})
|
|
|> Ash.create!()
|
|
|
|
post
|
|
|> Ash.Changeset.for_destroy(:destroy, %{})
|
|
|> Ash.destroy!()
|
|
|
|
assert [] = Ash.read!(Post)
|
|
end
|
|
|
|
test "before action hooks are honored" do
|
|
post =
|
|
Post
|
|
|> Ash.Changeset.for_create(:create, %{})
|
|
|> Ash.create!()
|
|
|
|
assert_raise Ash.Error.Invalid, ~r/must type CONFIRM/, fn ->
|
|
post
|
|
|> Ash.Changeset.for_destroy(:destroy_with_confirm, %{confirm: "NOT CONFIRM"})
|
|
|> Ash.destroy!()
|
|
end
|
|
end
|
|
|
|
test "before action hooks are honored, for soft destroys as well" do
|
|
post =
|
|
Post
|
|
|> Ash.Changeset.for_create(:create, %{})
|
|
|> Ash.create!()
|
|
|
|
assert_raise Ash.Error.Invalid, ~r/must type CONFIRM/, fn ->
|
|
post
|
|
|> Ash.Changeset.for_destroy(:soft_destroy_with_confirm, %{confirm: "NOT CONFIRM"})
|
|
|> Ash.destroy!()
|
|
end
|
|
end
|
|
end
|