|
1 | 1 | defmodule AshSql.AggregateTest do
|
2 | 2 | use AshPostgres.RepoCase, async: false
|
3 | 3 | import ExUnit.CaptureIO
|
| 4 | + |
4 | 5 | alias AshPostgres.Test.{Author, Comment, Organization, Post, Rating, User}
|
5 | 6 |
|
6 | 7 | require Ash.Query
|
@@ -1683,4 +1684,52 @@ defmodule AshSql.AggregateTest do
|
1683 | 1684 | |> Ash.read_one!()
|
1684 | 1685 | end
|
1685 | 1686 | end
|
| 1687 | + |
| 1688 | + @tag :regression |
| 1689 | + test "aggregates with authorization policies using relates_to_actor_via with existing resources" do |
| 1690 | + org = |
| 1691 | + AshPostgres.Test.Organization |
| 1692 | + |> Ash.Changeset.for_create(:create, %{name: "Test Org"}) |
| 1693 | + |> Ash.create!() |
| 1694 | + |
| 1695 | + user = |
| 1696 | + AshPostgres.Test.User |
| 1697 | + |> Ash.Changeset.for_create(:create, %{name: "test_user", organization_id: org.id}) |
| 1698 | + |> Ash.create!() |
| 1699 | + |
| 1700 | + AshPostgres.Test.User |
| 1701 | + |> Ash.Changeset.for_create(:create, %{name: "another_user", organization_id: org.id}) |
| 1702 | + |> Ash.create!() |
| 1703 | + |
| 1704 | + author = |
| 1705 | + AshPostgres.Test.Author |
| 1706 | + |> Ash.Changeset.for_create(:create, %{first_name: "Test", last_name: "Author"}) |
| 1707 | + |> Ash.create!() |
| 1708 | + |
| 1709 | + post = |
| 1710 | + AshPostgres.Test.Post |
| 1711 | + |> Ash.Changeset.for_create(:create, %{ |
| 1712 | + title: "Test Post", |
| 1713 | + organization_id: org.id, |
| 1714 | + author_id: author.id |
| 1715 | + }) |
| 1716 | + |> Ash.create!() |
| 1717 | + |
| 1718 | + comment1 = |
| 1719 | + AshPostgres.Test.Comment |
| 1720 | + |> Ash.Changeset.for_create(:create, %{ |
| 1721 | + title: "First comment", |
| 1722 | + post_id: post.id, |
| 1723 | + author_id: author.id |
| 1724 | + }) |
| 1725 | + |> Ash.create!() |
| 1726 | + |
| 1727 | + loaded_post = |
| 1728 | + AshPostgres.Test.Post |
| 1729 | + |> Ash.Query.filter(id == ^post.id) |
| 1730 | + |> Ash.Query.load(:comments_in_my_org) |
| 1731 | + |> Ash.read_one!(actor: user) |
| 1732 | + |
| 1733 | + assert loaded_post.comments_in_my_org == 1 |
| 1734 | + end |
1686 | 1735 | end
|
0 commit comments