2019-12-06 20:00:26 +13:00
|
|
|
defmodule Ash.Test.Dsl.Resource.Actions.UpdateTest do
|
|
|
|
use ExUnit.Case, async: true
|
|
|
|
|
|
|
|
defmacrop defposts(do: body) do
|
|
|
|
quote do
|
|
|
|
defmodule Post do
|
2020-08-19 16:49:41 +12:00
|
|
|
use Ash.Resource,
|
|
|
|
data_layer: Ash.DataLayer.Ets
|
2019-12-06 20:00:26 +13:00
|
|
|
|
2020-06-30 16:31:07 +12:00
|
|
|
attributes do
|
2021-01-13 09:40:55 +13:00
|
|
|
uuid_primary_key :id
|
2020-06-30 16:31:07 +12:00
|
|
|
end
|
|
|
|
|
2019-12-06 20:00:26 +13:00
|
|
|
unquote(body)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "representation" do
|
|
|
|
test "it creates an action" do
|
|
|
|
defposts do
|
|
|
|
actions do
|
2020-12-31 06:53:24 +13:00
|
|
|
defaults []
|
2019-12-06 20:00:26 +13:00
|
|
|
update :default
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
assert [
|
|
|
|
%Ash.Resource.Actions.Update{
|
|
|
|
name: :default,
|
|
|
|
primary?: true,
|
|
|
|
type: :update
|
|
|
|
}
|
2020-07-15 17:38:42 +12:00
|
|
|
] = Ash.Resource.actions(Post)
|
2019-12-06 20:00:26 +13:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "validation" do
|
|
|
|
test "it fails if `name` is not an atom" do
|
|
|
|
assert_raise(
|
2020-07-16 09:06:27 +12:00
|
|
|
Ash.Error.Dsl.DslError,
|
2020-10-06 03:40:22 +13:00
|
|
|
"[Ash.Resource.Dsl.Update]\n actions -> update -> default:\n expected :name to be an atom, got: \"default\"",
|
2019-12-06 20:00:26 +13:00
|
|
|
fn ->
|
|
|
|
defposts do
|
|
|
|
actions do
|
|
|
|
update "default"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
test "it fails if `primary?` is not a boolean" do
|
|
|
|
assert_raise(
|
2020-07-16 09:06:27 +12:00
|
|
|
Ash.Error.Dsl.DslError,
|
2020-12-01 18:51:24 +13:00
|
|
|
"[Ash.Resource.Dsl.Update]\n actions -> update -> default:\n expected :primary? to be a boolean, got: 10",
|
2019-12-06 20:00:26 +13:00
|
|
|
fn ->
|
|
|
|
defposts do
|
|
|
|
actions do
|
|
|
|
update :default, primary?: 10
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|