mirror of
https://github.com/ash-project/ash_postgres.git
synced 2024-09-19 21:13:19 +12:00
chore: Add failing test for tenanted aggregate bug.
This commit is contained in:
parent
d26a189946
commit
9ad7402227
3 changed files with 34 additions and 0 deletions
|
@ -444,6 +444,32 @@ defmodule AshSql.AggregateTest do
|
||||||
|> Ash.Query.load([:count_comment_titles, :count_uniq_comment_titles])
|
|> Ash.Query.load([:count_comment_titles, :count_uniq_comment_titles])
|
||||||
|> Ash.read_one!()
|
|> Ash.read_one!()
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
describe "first" do
|
describe "first" do
|
||||||
|
|
|
@ -51,4 +51,8 @@ defmodule AshPostgres.MultitenancyTest.Post do
|
||||||
|
|
||||||
has_one(:self, __MODULE__, destination_attribute: :id, source_attribute: :id, public?: true)
|
has_one(:self, __MODULE__, destination_attribute: :id, source_attribute: :id, public?: true)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
calculations do
|
||||||
|
calculate(:last_word, :string, expr(fragment("split_part(?, ' ', -1)", name)))
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -36,5 +36,9 @@ defmodule AshPostgres.MultitenancyTest.User do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
aggregates do
|
||||||
|
list(:years_visited, :posts, :last_word)
|
||||||
|
end
|
||||||
|
|
||||||
def parse_tenant("org_" <> id), do: id
|
def parse_tenant("org_" <> id), do: id
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue