2020-09-24 13:26:16 +12:00
|
|
|
defmodule Ash.Test.Resource.IdentitiesTest 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
|
2021-01-13 09:40:55 +13:00
|
|
|
uuid_primary_key :id
|
2020-09-24 13:26:16 +12:00
|
|
|
|
|
|
|
attribute :name, :string
|
|
|
|
attribute :contents, :string
|
|
|
|
end
|
|
|
|
|
|
|
|
unquote(body)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "representation" do
|
|
|
|
test "identities are persisted on the resource properly" do
|
|
|
|
defposts do
|
2021-01-22 09:21:58 +13:00
|
|
|
identities do
|
|
|
|
identity :foobar, [:name, :contents]
|
2020-09-24 13:26:16 +12:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
assert [%Ash.Resource.Identity{name: :foobar, keys: [:name, :contents]}] =
|
2021-02-23 14:29:31 +13:00
|
|
|
Ash.Resource.Info.identities(Post)
|
2020-09-24 13:26:16 +12:00
|
|
|
end
|
2020-09-26 00:20:58 +12:00
|
|
|
|
|
|
|
test "Identity descriptions are allowed" do
|
|
|
|
defposts do
|
2021-01-22 09:21:58 +13:00
|
|
|
identities do
|
|
|
|
identity :foobar, [:name, :contents], description: "require one of name/contents"
|
2020-09-26 00:20:58 +12:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
assert [
|
|
|
|
%Ash.Resource.Identity{description: "require one of name/contents"}
|
2021-02-23 14:29:31 +13:00
|
|
|
] = Ash.Resource.Info.identities(Post)
|
2020-09-26 00:20:58 +12:00
|
|
|
end
|
2020-09-24 13:26:16 +12:00
|
|
|
end
|
|
|
|
end
|