mirror of
https://github.com/ash-project/ash.git
synced 2024-09-20 21:43:02 +12:00
d42c778a0d
feat: refactored manage_relationship options/behavior
67 lines
1.5 KiB
Elixir
67 lines
1.5 KiB
Elixir
defmodule Ash.Test.Dsl.Resource.Actions.UpdateTest do
|
|
use ExUnit.Case, async: true
|
|
|
|
defmacrop defposts(do: body) do
|
|
quote do
|
|
defmodule Post do
|
|
use Ash.Resource,
|
|
data_layer: Ash.DataLayer.Ets
|
|
|
|
attributes do
|
|
uuid_primary_key :id
|
|
end
|
|
|
|
unquote(body)
|
|
end
|
|
end
|
|
end
|
|
|
|
describe "representation" do
|
|
test "it creates an action" do
|
|
defposts do
|
|
actions do
|
|
defaults []
|
|
update :default
|
|
end
|
|
end
|
|
|
|
assert [
|
|
%Ash.Resource.Actions.Update{
|
|
name: :default,
|
|
primary?: true,
|
|
type: :update
|
|
}
|
|
] = Ash.Resource.Info.actions(Post)
|
|
end
|
|
end
|
|
|
|
describe "validation" do
|
|
test "it fails if `name` is not an atom" do
|
|
assert_raise(
|
|
Ash.Error.Dsl.DslError,
|
|
"[Ash.Resource.Dsl.Update]\n actions -> update -> default:\n expected :name to be an atom, got: \"default\"",
|
|
fn ->
|
|
defposts do
|
|
actions do
|
|
update "default"
|
|
end
|
|
end
|
|
end
|
|
)
|
|
end
|
|
|
|
test "it fails if `primary?` is not a boolean" do
|
|
assert_raise(
|
|
Ash.Error.Dsl.DslError,
|
|
"[Ash.Resource.Dsl.Update]\n actions -> update -> default:\n expected :primary? to be a boolean, got: 10",
|
|
fn ->
|
|
defposts do
|
|
actions do
|
|
update :default, primary?: 10
|
|
end
|
|
end
|
|
end
|
|
)
|
|
end
|
|
end
|
|
end
|