Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions test/calculation_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -1669,4 +1669,25 @@
assert Ash.calculate!(post, :past_datetime1?)
assert Ash.calculate!(post, :past_datetime2?)
end

test "bug repro" do

Check failure on line 1673 in test/calculation_test.exs

View workflow job for this annotation

GitHub Actions / ash-ci (15) / mix test

test bug repro (AshPostgres.CalculationTest)

Check failure on line 1673 in test/calculation_test.exs

View workflow job for this annotation

GitHub Actions / ash-ci (16) / mix test

test bug repro (AshPostgres.CalculationTest)

Check failure on line 1673 in test/calculation_test.exs

View workflow job for this annotation

GitHub Actions / ash-ci (14) / mix test

test bug repro (AshPostgres.CalculationTest)
author =
Author
|> Ash.Changeset.for_create(:create, %{
first_name: "Bill",
last_name: "Jones",
bio: %{title: "Mr.", bio: "Bones"}
})
|> Ash.create!()

[author_with_loads] =
Author
|> Ash.Query.for_read(:read, %{}, actor: %{id: "it's a me"})
|> Ash.Query.load([:true_if_actor_from_context, :true_if_actor_from_context_nested])
|> Ash.Query.filter(id == ^author.id)
|> Ash.read!()

assert author_with_loads.true_if_actor_in_context
assert author_with_loads.true_if_actor_in_context_nested
end
end
25 changes: 25 additions & 0 deletions test/support/resources/author.ex
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,23 @@ defmodule AshPostgres.Test.Author do
end
end

defmodule TrueIfActorInContext do
@moduledoc """
An example of a calculation that references the actor from context, in a trivial way for demonstration purposes.
"""
use Ash.Resource.Calculation

def expression(_opts, context) do
actor = context.actor

if is_nil(actor) do
expr(false)
else
expr(true)
end
end
end

postgres do
table("authors")
repo(AshPostgres.TestRepo)
Expand Down Expand Up @@ -190,6 +207,14 @@ defmodule AshPostgres.Test.Author do
)

calculate(:profile_description_calc, :string, expr(profile.description), allow_nil?: true)

calculate(:true_if_actor_in_context, :boolean, TrueIfActorInContext)

calculate(
:true_if_actor_in_context_nested,
:boolean,
expr(true_if_actor_in_context and fragment("1 = 1"))
)
end

aggregates do
Expand Down
Loading