ash/test/resource/changes/load_test.exs
Zach Daniel e353ea49c3 fix: allow api.load/2 to load calculations
improvement: add `allow_nil_input` to create actions for api layers
improvement: add `load/1` builtin change
feat: change `get?: true` interface functions to raise on `nil`
2021-04-13 15:49:42 -04:00

38 lines
768 B
Elixir

defmodule Ash.Test.Resource.Changes.LoadTest do
@moduledoc false
use ExUnit.Case, async: true
defmodule Post do
use Ash.Resource,
data_layer: Ash.DataLayer.Ets
attributes do
uuid_primary_key :id
attribute :text, :string
attribute :second_text, :string
end
actions do
create :create do
change load(:full_text)
end
end
calculations do
calculate :full_text, :string, concat([:text, :second_text])
end
end
defmodule Api do
use Ash.Api
resources do
resource Post
end
end
test "you can use it to load on create" do
assert Api.create!(Ash.Changeset.for_create(Post, :create, text: "foo", second_text: "bar")).full_text ==
"foobar"
end
end