mirror of
https://github.com/ash-project/ash.git
synced 2024-09-20 05:23:03 +12:00
1ab5a35d7f
* improvement: support an `api` option to `use Ash.Resource` improvement: add functions to `Ash` for resources w/ configured apis improvement: default code_interface.define_for to resource's ash api
47 lines
945 B
Elixir
47 lines
945 B
Elixir
defmodule Ash.Test.Resource.ApiTest do
|
|
@moduledoc false
|
|
use ExUnit.Case, async: true
|
|
|
|
defmodule Api do
|
|
use Ash.Api
|
|
|
|
resources do
|
|
allow_unregistered? true
|
|
end
|
|
end
|
|
|
|
defmodule Foo do
|
|
use Ash.Resource, api: Api
|
|
|
|
actions do
|
|
defaults [:create, :read]
|
|
end
|
|
|
|
attributes do
|
|
uuid_primary_key :id
|
|
end
|
|
end
|
|
|
|
test "cannot define a resource that points to an api that doesn't accept it" do
|
|
assert_raise RuntimeError, ~r/api does not accept this resource/, fn ->
|
|
defmodule NoResourcesApi do
|
|
use Ash.Api
|
|
end
|
|
|
|
defmodule Bar do
|
|
use Ash.Resource, api: NoResourcesApi
|
|
|
|
attributes do
|
|
uuid_primary_key :id
|
|
end
|
|
end
|
|
end
|
|
end
|
|
|
|
test "a resource defined with an api can be used with functions in `Ash`" do
|
|
assert %Foo{} =
|
|
Foo
|
|
|> Ash.Changeset.for_create(:create)
|
|
|> Ash.create!()
|
|
end
|
|
end
|