mirror of
https://github.com/ash-project/ash.git
synced 2024-09-20 13:33:20 +12:00
022708c6b5
improvement: make default actions and primary actions far more explicit this begins the official 2.0.0 work
49 lines
929 B
Elixir
49 lines
929 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
|
|
defaults [:read, :update, :destroy]
|
|
|
|
create :create do
|
|
change load(:full_text)
|
|
end
|
|
end
|
|
|
|
calculations do
|
|
calculate :full_text, :string, concat([:text, :second_text])
|
|
end
|
|
end
|
|
|
|
defmodule Registry do
|
|
@moduledoc false
|
|
use Ash.Registry
|
|
|
|
entries do
|
|
entry Post
|
|
end
|
|
end
|
|
|
|
defmodule Api do
|
|
use Ash.Api
|
|
|
|
resources do
|
|
registry Registry
|
|
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
|