mirror of
https://github.com/ash-project/ash.git
synced 2024-09-20 05:23:03 +12:00
chore: fix test
This commit is contained in:
parent
1db7025b41
commit
43d0233ae9
1 changed files with 33 additions and 12 deletions
|
@ -29,6 +29,20 @@ defmodule Ash.Test.CalculationTest do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
defmodule FullNameWithSelect do
|
||||||
|
use Ash.Calculation
|
||||||
|
|
||||||
|
def select(_, _, _) do
|
||||||
|
[:first_name, :last_name]
|
||||||
|
end
|
||||||
|
|
||||||
|
def calculate(records, _, _) do
|
||||||
|
Enum.map(records, fn record ->
|
||||||
|
"#{record.first_name} #{record.last_name}"
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
defmodule Concat do
|
defmodule Concat do
|
||||||
# An example concatenation calculation, that accepts the delimiter as an argument
|
# An example concatenation calculation, that accepts the delimiter as an argument
|
||||||
use Ash.Calculation
|
use Ash.Calculation
|
||||||
|
@ -166,7 +180,7 @@ defmodule Ash.Test.CalculationTest do
|
||||||
use Ash.Calculation
|
use Ash.Calculation
|
||||||
|
|
||||||
def load(_, _, _) do
|
def load(_, _, _) do
|
||||||
[:full_name]
|
[:full_name_with_select]
|
||||||
end
|
end
|
||||||
|
|
||||||
def select(_, _, _) do
|
def select(_, _, _) do
|
||||||
|
@ -175,7 +189,7 @@ defmodule Ash.Test.CalculationTest do
|
||||||
|
|
||||||
def calculate(records, _, _) do
|
def calculate(records, _, _) do
|
||||||
Enum.map(records, fn record ->
|
Enum.map(records, fn record ->
|
||||||
record.full_name <> " #{record.first_name}"
|
record.full_name_with_select <> " #{record.first_name}"
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -243,6 +257,14 @@ defmodule Ash.Test.CalculationTest do
|
||||||
constraints: [allow_empty?: true, trim?: false]
|
constraints: [allow_empty?: true, trim?: false]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
calculate :full_name_with_select, :string, FullNameWithSelect do
|
||||||
|
# We currently need to use the [allow_empty?: true, trim?: false] constraints here.
|
||||||
|
# As it's an empty string, the separator would otherwise be trimmed and set to `nil`.
|
||||||
|
argument :separator, :string,
|
||||||
|
default: " ",
|
||||||
|
constraints: [allow_empty?: true, trim?: false]
|
||||||
|
end
|
||||||
|
|
||||||
calculate :best_friends_best_friends_first_name, :string, BestFriendsBestFriendsFirstName
|
calculate :best_friends_best_friends_first_name, :string, BestFriendsBestFriendsFirstName
|
||||||
|
|
||||||
calculate :best_friends_first_name_plus_stuff,
|
calculate :best_friends_first_name_plus_stuff,
|
||||||
|
@ -719,15 +741,14 @@ defmodule Ash.Test.CalculationTest do
|
||||||
end
|
end
|
||||||
|
|
||||||
test "loading a calculation with selects that loads a calculation with selects works" do
|
test "loading a calculation with selects that loads a calculation with selects works" do
|
||||||
full_names_plus_first_names =
|
assert ["brian brian", "zach zach"] ==
|
||||||
User
|
User
|
||||||
|> Ash.Query.select([])
|
|> Ash.Query.select([])
|
||||||
|> Ash.Query.load([
|
|> Ash.Query.load([
|
||||||
:full_names_plus_first_names
|
:full_name_plus_first_name
|
||||||
])
|
])
|
||||||
|> Api.read!()
|
|> Api.read!()
|
||||||
|> Enum.map(& &1.full_names_plus_first_names)
|
|> Enum.map(& &1.full_name_plus_first_name)
|
||||||
|> Enum.sort()
|
|> Enum.sort()
|
||||||
|> IO.inspect()
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue