ash/test/resource/actions/destroy_test.exs

68 lines
1.5 KiB
Elixir
Raw Normal View History

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
use Ash.Resource
2019-12-06 20:00:26 +13:00
attributes do
attribute :id, :uuid, primary_key?: true, default: &Ecto.UUID.generate/0
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
destroy :default
end
end
assert [
%Ash.Resource.Actions.Destroy{
name: :default,
primary?: true,
type: :destroy
}
] = Ash.actions(Post)
end
end
describe "validation" do
test "it fails if `name` is not an atom" do
assert_raise(
Ash.Error.ResourceDslError,
"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(
Ash.Error.ResourceDslError,
"actions -> destroy -> default:\n expected :primary? to be an boolean, got: 10",
2019-12-06 20:00:26 +13:00
fn ->
defposts do
actions do
destroy :default, primary?: 10
end
end
end
)
end
end
end