chore: Add failing test for tenanted aggregate bug.

This commit is contained in:
James Harton 2024-04-23 10:07:53 +12:00
parent d26a189946
commit 9ad7402227
Signed by: james
GPG key ID: 90E82DAA13F624F4
3 changed files with 34 additions and 0 deletions

View file

@ -444,6 +444,32 @@ defmodule AshSql.AggregateTest do
|> Ash.Query.load([:count_comment_titles, :count_uniq_comment_titles])
|> Ash.read_one!()
end
test "when related data that uses schema-based multitenancy, it returns the uniq" do
alias AshPostgres.MultitenancyTest.{Org, Post, User}
org =
Org
|> Ash.Changeset.for_create(:create, %{name: "BTTF"})
|> Ash.create!()
user =
User
|> Ash.Changeset.for_create(:create, %{name: "Marty", org_id: org.id})
|> Ash.create!()
posts =
["Back to 1955", "Forwards to 1985", "Forward to 2015", "Back again to 1985"]
|> Enum.map(
&(Post
|> Ash.Changeset.for_create(:create, %{name: &1})
|> Ash.create!(tenant: "org_#{org.id}", load: [:last_word]))
)
user = Ash.load!(user, :years_visited, tenant: "org_#{org.id}")
assert Enum.sort(user.years_visited) == ["1955", "1985", "2015"]
end
end
describe "first" do

View file

@ -51,4 +51,8 @@ defmodule AshPostgres.MultitenancyTest.Post do
has_one(:self, __MODULE__, destination_attribute: :id, source_attribute: :id, public?: true)
end
calculations do
calculate(:last_word, :string, expr(fragment("split_part(?, ' ', -1)", name)))
end
end

View file

@ -36,5 +36,9 @@ defmodule AshPostgres.MultitenancyTest.User do
end
end
aggregates do
list(:years_visited, :posts, :last_word)
end
def parse_tenant("org_" <> id), do: id
end