Skip to content

Commit 5428e89

Browse files
committed
chore: tests for aggregate error w/ modify_query
1 parent db24c4e commit 5428e89

File tree

3 files changed

+30
-0
lines changed

3 files changed

+30
-0
lines changed

test/aggregate_test.exs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1667,4 +1667,15 @@ defmodule AshSql.AggregateTest do
16671667
Ash.Query.filter_input(AshPostgres.Test.StandupClub, filter)
16681668
|> Ash.read!(load: [:punchline_count])
16691669
end
1670+
1671+
@tag :regression
1672+
test "aggregates with modify_query raise an appropriate error" do
1673+
assert_raise Ash.Error.Unknown, ~r/does not currently support aggregates/, fn ->
1674+
Post
1675+
|> Ash.Query.load([
1676+
:count_comments_with_modify_query
1677+
])
1678+
|> Ash.read_one!()
1679+
end
1680+
end
16701681
end

test/support/resources/comment.ex

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ defmodule AshPostgres.Test.Comment do
3333

3434
change(manage_relationship(:rating, :ratings, on_missing: :ignore, on_match: :create))
3535
end
36+
37+
read :with_modify_query do
38+
modify_query({AshPostgres.Test.Comment.ModifyQuery, :modify, []})
39+
end
3640
end
3741

3842
attributes do
@@ -104,3 +108,14 @@ defmodule AshPostgres.Test.Comment do
104108
)
105109
end
106110
end
111+
112+
defmodule AshPostgres.Test.Comment.ModifyQuery do
113+
@moduledoc """
114+
Raises when modifying query so we can assert
115+
this code path is called.
116+
"""
117+
118+
def modify(_ash_query, _ecto_query) do
119+
raise "modifying query!"
120+
end
121+
end

test/support/resources/post.ex

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1164,6 +1164,10 @@ defmodule AshPostgres.Test.Post do
11641164
end
11651165

11661166
first(:author_profile_description, :author, :description)
1167+
1168+
count :count_comments_with_modify_query, :comments do
1169+
read_action(:with_modify_query)
1170+
end
11671171
end
11681172
end
11691173

0 commit comments

Comments
 (0)