Skip to content

Commit 6f97884

Browse files
authored
test: add failing tests for loads not getting added automatically in certain situations (#612)
1 parent 36213e4 commit 6f97884

File tree

2 files changed

+38
-1
lines changed

2 files changed

+38
-1
lines changed

test/parent_filter_test.exs

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
defmodule AshPostgres.Test.ParentFilterTest do
22
use AshPostgres.RepoCase, async: false
33

4-
alias AshPostgres.Test.{Organization, Post, User}
4+
alias AshPostgres.Test.{Organization, Post, User, Comment}
55

66
require Ash.Query
77

@@ -44,4 +44,31 @@ defmodule AshPostgres.Test.ParentFilterTest do
4444
)
4545
|> Ash.read(authorize?: false)
4646
end
47+
48+
test "something else" do
49+
organization =
50+
Organization
51+
|> Ash.Changeset.for_create(:create, %{name: "test_org"})
52+
|> Ash.create!()
53+
54+
post_in_my_org =
55+
Post
56+
|> Ash.Changeset.for_create(:create, %{organization_id: organization.id, title: "test_org"})
57+
|> Ash.create!()
58+
59+
Comment
60+
|> Ash.Changeset.for_create(:create, %{title: "test_org"})
61+
|> Ash.Changeset.manage_relationship(:post, post_in_my_org, type: :append_and_remove)
62+
|> Ash.create!()
63+
64+
assert {:ok, _} =
65+
Post
66+
|> Ash.Query.for_read(:read)
67+
|> Ash.Query.filter(
68+
organizations_with_posts_that_have_the_post_title_somewhere_in_their_comments.name in [
69+
^organization.name
70+
]
71+
)
72+
|> Ash.read(authorize?: false)
73+
end
4774
end

test/support/resources/post.ex

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -614,6 +614,14 @@ defmodule AshPostgres.Test.Post do
614614
filter(expr(fragment("? = ?", title, parent(organization.name))))
615615
end
616616

617+
has_many(
618+
:organizations_with_posts_that_have_the_post_title_somewhere_in_their_comments,
619+
AshPostgres.Test.Organization
620+
) do
621+
no_attributes?(true)
622+
filter(expr(fragment("POSITION(? IN ?) > 0", posts.title, parent(concated_comment_titles))))
623+
end
624+
617625
has_many(:recommendations, __MODULE__) do
618626
public?(true)
619627
no_attributes?(true)
@@ -1020,6 +1028,8 @@ defmodule AshPostgres.Test.Post do
10201028
calculate(:author_profile_description_from_agg, :string, expr(author_profile_description))
10211029

10221030
calculate(:latest_comment_title, :string, expr(latest_comment.title), allow_nil?: true)
1031+
1032+
calculate(:concated_comment_titles, :string, expr(fragment("concat(?)", comment_titles)))
10231033
end
10241034

10251035
aggregates do

0 commit comments

Comments
 (0)