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.create!()
|
||||
|
||||
Logger.configure(level: :debug)
|
||||
|
||||
assert_raise Ash.Error.Invalid, ~r/Can only delete if Post has no comments/, fn ->
|
||||
post
|
||||
|> Ash.Changeset.for_destroy(:destroy_if_no_comments, %{})
|
||||
|
|
|
@ -18,9 +18,15 @@ defmodule HasNoComments do
|
|||
use Ash.Resource.Validation
|
||||
|
||||
def atomic(_changeset, _opts, _context) do
|
||||
# This uses the list aggregate because we want to specifically test this aggregate
|
||||
{:atomic, [], expr(list(comments, field: :id) > 0),
|
||||
expr(error(^Invalid, %{message: "Can only delete if Post has no comments"}))}
|
||||
# Test multiple types of aggregates in a single validation
|
||||
[
|
||||
{: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
|
||||
|
||||
|
|
Loading…
Reference in a new issue