mirror of
https://github.com/ash-project/ash.git
synced 2024-09-21 05:53:06 +12:00
a53b61ddf4
feat: support recursive DSL entities. improvement: unimport to avoid name collisions in nested DSLs
58 lines
1.5 KiB
Elixir
58 lines
1.5 KiB
Elixir
defmodule Ash.Test.Dsl.Resource.Actions.ActionsTest do
|
|
@moduledoc false
|
|
use ExUnit.Case, async: true
|
|
|
|
defmacrop defposts(do: body) do
|
|
quote do
|
|
defmodule Post do
|
|
@moduledoc false
|
|
use Ash.Resource
|
|
|
|
attributes do
|
|
uuid_primary_key :id
|
|
end
|
|
|
|
unquote(body)
|
|
end
|
|
end
|
|
end
|
|
|
|
test "default actions are added" do
|
|
defposts do
|
|
end
|
|
|
|
assert Ash.Resource.Info.primary_action!(Post, :read)
|
|
end
|
|
|
|
describe "validations" do
|
|
test "raises if you have multiple primary actions for a type" do
|
|
assert_raise(
|
|
Ash.Error.Dsl.DslError,
|
|
"[Ash.Test.Dsl.Resource.Actions.ActionsTest.Post]\n actions -> create:\n Multiple actions of type create configured as `primary?: true`, but only one action per type can be the primary",
|
|
fn ->
|
|
defposts do
|
|
actions do
|
|
create :create, primary?: true
|
|
create :special, primary?: true
|
|
end
|
|
end
|
|
end
|
|
)
|
|
end
|
|
|
|
test "raises if you have multiple actions for a type, but none are primary" do
|
|
assert_raise(
|
|
Ash.Error.Dsl.DslError,
|
|
"[Ash.Test.Dsl.Resource.Actions.ActionsTest.Post]\n actions -> create:\n Multiple actions of type create defined, one must be designated as `primary?`",
|
|
fn ->
|
|
defposts do
|
|
actions do
|
|
create :create
|
|
create :special
|
|
end
|
|
end
|
|
end
|
|
)
|
|
end
|
|
end
|
|
end
|