2019-12-07 20:42:14 +13:00
|
|
|
defmodule Ash.Test.Dsl.Resource.Actions.ActionsTest do
|
2020-06-02 17:47:25 +12:00
|
|
|
@moduledoc false
|
2019-12-07 20:42:14 +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-06-01 17:14:23 +12:00
|
|
|
use Ash.Resource, name: "posts", type: "post"
|
2019-12-07 20:42:14 +13:00
|
|
|
|
|
|
|
unquote(body)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "validations" do
|
|
|
|
test "raises if you have multiple primary actions for a type" do
|
|
|
|
assert_raise(
|
|
|
|
Ash.Error.ResourceDslError,
|
2020-06-01 17:14:23 +12:00
|
|
|
"actions -> create:\n Multiple actions of type create configured as `primary?: true`, but only one action per type can be the primary",
|
2019-12-07 20:42:14 +13:00
|
|
|
fn ->
|
|
|
|
defposts do
|
|
|
|
actions do
|
|
|
|
create :default, 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.ResourceDslError,
|
2020-06-01 17:14:23 +12:00
|
|
|
"actions -> create:\n Multiple actions of type create defined, one must be designated as `primary?: true`",
|
2019-12-07 20:42:14 +13:00
|
|
|
fn ->
|
|
|
|
defposts do
|
|
|
|
actions do
|
|
|
|
create :default
|
|
|
|
create :special
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|