Skip to content

Commit a8641ea

Browse files
committed
chore: colocate tests
1 parent 1989844 commit a8641ea

File tree

2 files changed

+31
-54
lines changed

2 files changed

+31
-54
lines changed

test/calculation_test.exs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1693,4 +1693,35 @@ defmodule AshPostgres.CalculationTest do
16931693
assert author_with_loads.true_if_actor_in_context
16941694
assert author_with_loads.true_if_actor_in_context_nested
16951695
end
1696+
1697+
describe "nested exists with calculation containing parent() inside unrelated exists" do
1698+
test "parent() references in a calculation are scoped to the calculation's own resource, not the outer exists" do
1699+
author =
1700+
Author
1701+
|> Ash.Changeset.for_create(:create, %{first_name: "Alice"})
1702+
|> Ash.create!()
1703+
1704+
Post
1705+
|> Ash.Changeset.for_create(:create, %{title: "Alice", author_id: author.id})
1706+
|> Ash.create!()
1707+
1708+
assert %{has_post_matching_author_via_nested_exists: true} =
1709+
Ash.load!(author, [:has_post_matching_author_via_nested_exists])
1710+
end
1711+
1712+
test "the inner calculation works correctly when loaded directly on the child resource" do
1713+
author =
1714+
Author
1715+
|> Ash.Changeset.for_create(:create, %{first_name: "Bob"})
1716+
|> Ash.create!()
1717+
1718+
post =
1719+
Post
1720+
|> Ash.Changeset.for_create(:create, %{title: "Bob", author_id: author.id})
1721+
|> Ash.create!()
1722+
1723+
assert %{has_matching_author_by_unrelated_exists: true} =
1724+
Ash.load!(post, [:has_matching_author_by_unrelated_exists])
1725+
end
1726+
end
16961727
end

test/nested_exists_parent_scope_test.exs

Lines changed: 0 additions & 54 deletions
This file was deleted.

0 commit comments

Comments
 (0)