mirror of
https://github.com/ash-project/ash.git
synced 2024-09-21 05:53:06 +12:00
ff756b72a7
A deprecation warning will be shown at compile time to illustrate a change from listing all of your resources in an api to listing them in a registry and connecting that registry to the api
74 lines
1.6 KiB
Elixir
74 lines
1.6 KiB
Elixir
defmodule Ash.Test.Sort.SortTest do
|
|
@moduledoc false
|
|
use ExUnit.Case, async: true
|
|
|
|
require Ash.Query
|
|
|
|
defmodule Post do
|
|
@moduledoc false
|
|
use Ash.Resource, data_layer: Ash.DataLayer.Ets
|
|
|
|
ets do
|
|
private?(true)
|
|
end
|
|
|
|
actions do
|
|
read :read
|
|
|
|
create :create
|
|
|
|
update :update
|
|
end
|
|
|
|
attributes do
|
|
uuid_primary_key :id
|
|
attribute :title, :string
|
|
attribute :contents, :string
|
|
attribute :points, :integer, private?: true
|
|
end
|
|
end
|
|
|
|
defmodule Registry do
|
|
@moduledoc false
|
|
use Ash.Registry
|
|
|
|
entries do
|
|
entry Post
|
|
end
|
|
end
|
|
|
|
defmodule Api do
|
|
@moduledoc false
|
|
use Ash.Api
|
|
|
|
resources do
|
|
registry Registry
|
|
end
|
|
end
|
|
|
|
describe "parse_input/2" do
|
|
test "simple string sort parses properly" do
|
|
assert {:ok, [title: :asc, contents: :desc]} =
|
|
Ash.Sort.parse_input(Post, "+title,-contents")
|
|
end
|
|
|
|
test "public attributes cannot be used" do
|
|
assert {:error, %Ash.Error.Query.NoSuchAttribute{}} = Ash.Sort.parse_input(Post, "points")
|
|
end
|
|
|
|
test "a list sort parses properly" do
|
|
assert {:ok, [title: :asc, contents: :desc]} =
|
|
Ash.Sort.parse_input(Post, ["title", "-contents"])
|
|
end
|
|
|
|
test "a regular sort parses properly" do
|
|
assert {:ok, [title: :asc, contents: :desc]} =
|
|
Ash.Sort.parse_input(Post, title: :asc, contents: :desc)
|
|
end
|
|
|
|
test "++ and -- modifiers work properly" do
|
|
assert {:ok, [title: :asc_nils_first, contents: :desc_nils_last]} =
|
|
Ash.Sort.parse_input(Post, "++title,--contents")
|
|
end
|
|
end
|
|
end
|