mirror of
https://github.com/ash-project/ash.git
synced 2024-09-20 13:33:20 +12:00
61 lines
1.3 KiB
Elixir
61 lines
1.3 KiB
Elixir
defmodule Ash.Test.Dsl.Resource.Actions.CreateTest do
|
|
use ExUnit.Case, async: true
|
|
|
|
defmacrop defposts(do: body) do
|
|
quote do
|
|
defmodule Post do
|
|
use Ash.Resource, name: "posts", type: "post"
|
|
|
|
unquote(body)
|
|
end
|
|
end
|
|
end
|
|
|
|
describe "representation" do
|
|
test "it creates an action" do
|
|
defposts do
|
|
actions do
|
|
create :default
|
|
end
|
|
end
|
|
|
|
assert [
|
|
%Ash.Resource.Actions.Create{
|
|
name: :default,
|
|
primary?: true,
|
|
type: :create
|
|
}
|
|
] = Ash.actions(Post)
|
|
end
|
|
end
|
|
|
|
describe "validation" do
|
|
test "it fails if `name` is not an atom" do
|
|
assert_raise(
|
|
Ash.Error.ResourceDslError,
|
|
"actions -> create:\n action name must be an atom",
|
|
fn ->
|
|
defposts do
|
|
actions do
|
|
create "default"
|
|
end
|
|
end
|
|
end
|
|
)
|
|
end
|
|
|
|
test "it fails if `primary?` is not a boolean" do
|
|
assert_raise(
|
|
Ash.Error.ResourceDslError,
|
|
"actions -> create -> default:\n expected :primary? to be an boolean, got: 10",
|
|
fn ->
|
|
defposts do
|
|
actions do
|
|
create :default, primary?: 10
|
|
end
|
|
end
|
|
end
|
|
)
|
|
end
|
|
end
|
|
end
|