mirror of
https://github.com/ash-project/ash_postgres.git
synced 2024-09-19 13:03:14 +12:00
test more aggregates
This commit is contained in:
parent
ece56c2bc9
commit
e3ac63f5d6
2 changed files with 9 additions and 5 deletions
|
@ -303,8 +303,6 @@ defmodule AshPostgres.AtomicsTest do
|
||||||
|> Ash.Changeset.for_create(:create, %{post_id: post.id, title: "foo"})
|
|> Ash.Changeset.for_create(:create, %{post_id: post.id, title: "foo"})
|
||||||
|> Ash.create!()
|
|> Ash.create!()
|
||||||
|
|
||||||
Logger.configure(level: :debug)
|
|
||||||
|
|
||||||
assert_raise Ash.Error.Invalid, ~r/Can only delete if Post has no comments/, fn ->
|
assert_raise Ash.Error.Invalid, ~r/Can only delete if Post has no comments/, fn ->
|
||||||
post
|
post
|
||||||
|> Ash.Changeset.for_destroy(:destroy_if_no_comments, %{})
|
|> Ash.Changeset.for_destroy(:destroy_if_no_comments, %{})
|
||||||
|
|
|
@ -18,9 +18,15 @@ defmodule HasNoComments do
|
||||||
use Ash.Resource.Validation
|
use Ash.Resource.Validation
|
||||||
|
|
||||||
def atomic(_changeset, _opts, _context) do
|
def atomic(_changeset, _opts, _context) do
|
||||||
# This uses the list aggregate because we want to specifically test this aggregate
|
# Test multiple types of aggregates in a single validation
|
||||||
{:atomic, [], expr(list(comments, field: :id) > 0),
|
[
|
||||||
expr(error(^Invalid, %{message: "Can only delete if Post has no comments"}))}
|
{:atomic, [],
|
||||||
|
expr(
|
||||||
|
list(comments, field: :id) > 0 or
|
||||||
|
count(comments) > 0 or
|
||||||
|
exists(comments, true)
|
||||||
|
), expr(error(^Invalid, %{message: "Can only delete if Post has no comments"}))}
|
||||||
|
]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue