mirror of
https://github.com/ash-project/ash_postgres.git
synced 2024-09-20 13:33:50 +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!()
|
|> Api.count!()
|
||||||
end
|
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
|
test "a count can filter independently of the query" do
|
||||||
assert {:ok, %{count: 0, count2: 0}} =
|
assert {:ok, %{count: 0, count2: 0}} =
|
||||||
Post
|
Post
|
||||||
|
|
|
@ -75,6 +75,10 @@ defmodule AshPostgres.Test.Post do
|
||||||
actions do
|
actions do
|
||||||
defaults([:update, :destroy])
|
defaults([:update, :destroy])
|
||||||
|
|
||||||
|
read :title_is_foo do
|
||||||
|
filter(expr(title == "foo"))
|
||||||
|
end
|
||||||
|
|
||||||
read :read do
|
read :read do
|
||||||
primary?(true)
|
primary?(true)
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue