-
Notifications
You must be signed in to change notification settings - Fork 87
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add some explicit destroy/soft destroy tests
- Loading branch information
1 parent
a66a0f6
commit 8f1ae86
Showing
2 changed files
with
71 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters