2019-12-06 20:00:26 +13:00
|
|
|
defmodule Ash.Test.Dsl.Resource.Actions.DestroyTest do
|
2020-06-02 17:47:25 +12:00
|
|
|
@moduledoc false
|
2019-12-06 20:00:26 +13:00
|
|
|
use ExUnit.Case, async: true
|
|
|
|
|
|
|
|
defmacrop defposts(do: body) do
|
|
|
|
quote do
|
|
|
|
defmodule Post do
|
2020-06-02 17:47:25 +12:00
|
|
|
@moduledoc false
|
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
|
2021-03-08 18:59:32 +13:00
|
|
|
destroy :destroy
|
2019-12-06 20:00:26 +13:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
assert [
|
|
|
|
%Ash.Resource.Actions.Destroy{
|
2021-03-08 18:59:32 +13:00
|
|
|
name: :destroy,
|
2022-04-29 10:07:06 +12:00
|
|
|
primary?: false,
|
2019-12-06 20:00:26 +13:00
|
|
|
type: :destroy
|
|
|
|
}
|
2021-02-23 14:29:31 +13:00
|
|
|
] = Ash.Resource.Info.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(
|
2022-08-15 06:06:58 +12:00
|
|
|
Spark.Error.DslError,
|
2022-03-16 10:41:25 +13:00
|
|
|
"[Ash.Test.Dsl.Resource.Actions.DestroyTest.Post]\n actions -> destroy -> default:\n expected :name to be an atom, got: \"default\"",
|
2019-12-06 20:00:26 +13:00
|
|
|
fn ->
|
|
|
|
defposts do
|
|
|
|
actions do
|
|
|
|
destroy "default"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
test "it fails if `primary?` is not a boolean" do
|
|
|
|
assert_raise(
|
2022-08-15 06:06:58 +12:00
|
|
|
Spark.Error.DslError,
|
2022-03-16 10:41:25 +13:00
|
|
|
"[Ash.Test.Dsl.Resource.Actions.DestroyTest.Post]\n actions -> destroy -> destroy:\n expected :primary? to be a boolean, got: 10",
|
2019-12-06 20:00:26 +13:00
|
|
|
fn ->
|
|
|
|
defposts do
|
|
|
|
actions do
|
2021-03-08 18:59:32 +13:00
|
|
|
destroy :destroy, primary?: 10
|
2019-12-06 20:00:26 +13:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|