2019-12-06 20:00:26 +13:00
|
|
|
defmodule Ash.Test.Dsl.Resource.Actions.CreateTest 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
|
|
|
create :create
|
2019-12-06 20:00:26 +13:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
assert [
|
|
|
|
%Ash.Resource.Actions.Create{
|
2021-03-08 18:59:32 +13:00
|
|
|
name: :create,
|
2019-12-06 20:00:26 +13:00
|
|
|
primary?: true,
|
|
|
|
type: :create
|
|
|
|
}
|
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(
|
2020-07-16 09:06:27 +12:00
|
|
|
Ash.Error.Dsl.DslError,
|
2022-03-16 10:41:25 +13:00
|
|
|
"[Ash.Test.Dsl.Resource.Actions.CreateTest.Post]\n actions -> create -> default:\n expected :name to be an atom, got: \"default\"",
|
2019-12-06 20:00:26 +13:00
|
|
|
fn ->
|
|
|
|
defposts do
|
|
|
|
actions do
|
|
|
|
create "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,
|
2022-03-16 10:41:25 +13:00
|
|
|
"[Ash.Test.Dsl.Resource.Actions.CreateTest.Post]\n actions -> create -> create:\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
|
|
|
create :create, primary?: 10
|
2019-12-06 20:00:26 +13:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|