mirror of
https://github.com/ash-project/ash.git
synced 2024-09-20 05:23:03 +12:00
1f2f9802a3
improvement: breaking change! api level code interface *removed*, contact me on discord if you want a way to avoid changing to resource-based interface, but otherwise switch to the resource based one by specifying `define_for YourApp.YourApi` in the `code_interface` block of each resource. improvement: use proper equality checking in places where we were using simple elixir equality checking
61 lines
1.1 KiB
Elixir
61 lines
1.1 KiB
Elixir
defmodule Ash.Test.CodeInterfaceTest do
|
|
@moduledoc false
|
|
use ExUnit.Case, async: true
|
|
|
|
defmodule User do
|
|
@moduledoc false
|
|
use Ash.Resource, data_layer: Ash.DataLayer.Ets
|
|
|
|
ets do
|
|
private?(true)
|
|
end
|
|
|
|
code_interface do
|
|
define_for Ash.Test.CodeInterfaceTest.Api
|
|
define :get_user, action: :read, get?: true, args: [:id]
|
|
define :read_users, action: :read
|
|
end
|
|
|
|
actions do
|
|
read :read do
|
|
primary? true
|
|
end
|
|
|
|
read :by_id do
|
|
argument :id, :uuid, allow_nil?: false
|
|
|
|
filter expr(id == ^arg(:id))
|
|
end
|
|
end
|
|
|
|
attributes do
|
|
uuid_primary_key :id
|
|
attribute :first_name, :string
|
|
attribute :last_name, :string
|
|
end
|
|
end
|
|
|
|
defmodule Registry do
|
|
@moduledoc false
|
|
use Ash.Registry
|
|
|
|
entries do
|
|
entry(User)
|
|
end
|
|
end
|
|
|
|
defmodule Api do
|
|
@moduledoc false
|
|
use Ash.Api
|
|
|
|
resources do
|
|
registry Registry
|
|
end
|
|
end
|
|
|
|
test "get! raises on not found" do
|
|
assert_raise Ash.Error.Query.NotFound, fn ->
|
|
User.get_user!(Ash.UUID.generate())
|
|
end
|
|
end
|
|
end
|