mirror of
https://github.com/ash-project/ash.git
synced 2024-09-20 21:43:02 +12:00
66 lines
1 KiB
Elixir
66 lines
1 KiB
Elixir
|
defmodule Ash.Test.Actions.BulkCreateTest do
|
||
|
@moduledoc false
|
||
|
use ExUnit.Case, async: true
|
||
|
|
||
|
defmodule Post do
|
||
|
@moduledoc false
|
||
|
use Ash.Resource, data_layer: Ash.DataLayer.Ets
|
||
|
|
||
|
ets do
|
||
|
private? true
|
||
|
end
|
||
|
|
||
|
actions do
|
||
|
defaults [:create, :update, :destroy]
|
||
|
|
||
|
read :read do
|
||
|
primary? true
|
||
|
pagination keyset?: true
|
||
|
end
|
||
|
|
||
|
read :read_with_no_pagination
|
||
|
end
|
||
|
|
||
|
attributes do
|
||
|
uuid_primary_key :id
|
||
|
attribute :title, :string, allow_nil?: false
|
||
|
|
||
|
timestamps()
|
||
|
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
|
||
|
|
||
|
test "records can be streamed" do
|
||
|
1..10
|
||
|
|> Enum.each(fn i ->
|
||
|
Post
|
||
|
|> Ash.Changeset.for_create(:create, %{title: "title#{i}"})
|
||
|
|> Api.create!()
|
||
|
end)
|
||
|
|
||
|
count =
|
||
|
Post
|
||
|
|> Api.stream!(batch_size: 5)
|
||
|
|> Enum.count()
|
||
|
|
||
|
assert count == 10
|
||
|
end
|
||
|
end
|