From f6d029d85b36c8bc76b57656b05c628923cb612e Mon Sep 17 00:00:00 2001 From: Zach Daniel Date: Sat, 24 Feb 2024 18:08:00 -0500 Subject: [PATCH] improvement: add test for aggregates --- test/aggregate_test.exs | 16 ++++++++++++++++ test/support/resources/post.ex | 4 ++++ 2 files changed, 20 insertions(+) diff --git a/test/aggregate_test.exs b/test/aggregate_test.exs index 4e7fc2e..04b576b 100644 --- a/test/aggregate_test.exs +++ b/test/aggregate_test.exs @@ -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 diff --git a/test/support/resources/post.ex b/test/support/resources/post.ex index 27b47d4..98414de 100644 --- a/test/support/resources/post.ex +++ b/test/support/resources/post.ex @@ -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