mirror of
https://github.com/ash-project/ash_postgres.git
synced 2024-09-20 05:23:18 +12:00
improvement: add test for aggregates
This commit is contained in:
parent
98f24b1923
commit
f6d029d85b
2 changed files with 20 additions and 0 deletions
|
@ -1164,6 +1164,22 @@ defmodule AshPostgres.AggregateTest do
|
|||
|> Api.count!()
|
||||
end
|
||||
|
||||
test "a count with a limit and a filter can be aggregated at the query level" do
|
||||
Post
|
||||
|> Ash.Changeset.new(%{title: "foo"})
|
||||
|> Api.create!()
|
||||
|
||||
Post
|
||||
|> Ash.Changeset.new(%{title: "bar"})
|
||||
|> Api.create!()
|
||||
|
||||
assert 1 ==
|
||||
Post
|
||||
|> Ash.Query.for_read(:title_is_foo)
|
||||
|> Ash.Query.limit(1)
|
||||
|> Api.count!()
|
||||
end
|
||||
|
||||
test "a count can filter independently of the query" do
|
||||
assert {:ok, %{count: 0, count2: 0}} =
|
||||
Post
|
||||
|
|
|
@ -75,6 +75,10 @@ defmodule AshPostgres.Test.Post do
|
|||
actions do
|
||||
defaults([:update, :destroy])
|
||||
|
||||
read :title_is_foo do
|
||||
filter(expr(title == "foo"))
|
||||
end
|
||||
|
||||
read :read do
|
||||
primary?(true)
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue