mirror of
https://github.com/ash-project/ash.git
synced 2024-09-20 05:23:03 +12:00
chore: failing test for nested calculation loading a relationship (#1283)
This commit is contained in:
parent
5a4fdcc362
commit
97cab3d767
1 changed files with 32 additions and 0 deletions
|
@ -743,6 +743,20 @@ defmodule Ash.Test.CalculationTest do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
defmodule ReversedUserFirstNameForWarranty do
|
||||||
|
use Ash.Resource.Calculation
|
||||||
|
|
||||||
|
@impl true
|
||||||
|
def load(_, _, _) do
|
||||||
|
[:user_first_name]
|
||||||
|
end
|
||||||
|
|
||||||
|
@impl true
|
||||||
|
def calculate(records, _, %{arguments: arguments}) do
|
||||||
|
Enum.map(records, &String.reverse(&1.user_first_name))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
defmodule Product do
|
defmodule Product do
|
||||||
use Ash.Resource,
|
use Ash.Resource,
|
||||||
domain: Domain,
|
domain: Domain,
|
||||||
|
@ -812,6 +826,10 @@ defmodule Ash.Test.CalculationTest do
|
||||||
argument :assert_strict?, :boolean, default: false
|
argument :assert_strict?, :boolean, default: false
|
||||||
public?(true)
|
public?(true)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
calculate :reversed_user_first_name, :string, ReversedUserFirstNameForWarranty do
|
||||||
|
public?(true)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
relationships do
|
relationships do
|
||||||
|
@ -1495,6 +1513,20 @@ defmodule Ash.Test.CalculationTest do
|
||||||
Ash.load!(warranty, user_first_name: [assert_strict?: true])
|
Ash.load!(warranty, user_first_name: [assert_strict?: true])
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "loads relationships in nested calculations", %{user1: user1} do
|
||||||
|
product =
|
||||||
|
Product
|
||||||
|
|> Ash.Changeset.for_create(:create, %{name: "SuperFoo3000", user_id: user1.id})
|
||||||
|
|> Ash.create!()
|
||||||
|
|
||||||
|
warranty =
|
||||||
|
Warranty
|
||||||
|
|> Ash.Changeset.for_create(:create, %{product_id: product.id})
|
||||||
|
|> Ash.create!()
|
||||||
|
|
||||||
|
assert %{user_first_name: "hcaz"} = Ash.load!(warranty, :reversed_user_first_name)
|
||||||
|
end
|
||||||
|
|
||||||
test "doesn't load relationships if there is no need", %{user1: user1} do
|
test "doesn't load relationships if there is no need", %{user1: user1} do
|
||||||
product =
|
product =
|
||||||
Product
|
Product
|
||||||
|
|
Loading…
Reference in a new issue