mirror of
https://github.com/ash-project/ash.git
synced 2024-09-20 05:23:03 +12:00
fix: ensure that all notifications are sent for bulk destroy/update
closes #1186
This commit is contained in:
parent
e01e95235f
commit
67c6e5e22a
3 changed files with 26 additions and 5 deletions
|
@ -285,7 +285,7 @@ defmodule Ash.Actions.Destroy.Bulk do
|
|||
List.wrap(bulk_result.notifications) ++
|
||||
List.wrap(Process.delete(:ash_notifications))
|
||||
else
|
||||
[]
|
||||
List.wrap(bulk_result.notifications)
|
||||
end
|
||||
|
||||
if opts[:return_notifications?] do
|
||||
|
@ -304,9 +304,11 @@ defmodule Ash.Actions.Destroy.Bulk do
|
|||
|
||||
%{bulk_result | notifications: notifications}
|
||||
else
|
||||
if opts[:notify?] do
|
||||
Ash.Actions.Helpers.warn_missed!(atomic_changeset.resource, action, %{
|
||||
resource_notifications: notifications
|
||||
})
|
||||
end
|
||||
|
||||
%{bulk_result | notifications: []}
|
||||
end
|
||||
|
|
|
@ -237,7 +237,7 @@ defmodule Ash.Actions.Update.Bulk do
|
|||
List.wrap(bulk_result.notifications) ++
|
||||
List.wrap(Process.delete(:ash_notifications))
|
||||
else
|
||||
[]
|
||||
List.wrap(bulk_result.notifications)
|
||||
end
|
||||
|
||||
if opts[:return_notifications?] do
|
||||
|
|
|
@ -193,6 +193,25 @@ defmodule Ash.Test.Actions.BulkDestroyTest do
|
|||
assert_received {:notification, %{data: %{title: "title2"}}}
|
||||
end
|
||||
|
||||
test "doesn't send notifications if not asked to" do
|
||||
assert %Ash.BulkResult{records: [%{}, %{}]} =
|
||||
Ash.bulk_create!([%{title: "title1"}, %{title: "title2"}], Post, :create,
|
||||
return_stream?: true,
|
||||
return_records?: true
|
||||
)
|
||||
|> Stream.map(fn {:ok, result} ->
|
||||
result
|
||||
end)
|
||||
|> Ash.bulk_destroy!(:destroy, %{},
|
||||
resource: Post,
|
||||
strategy: :stream,
|
||||
return_records?: true,
|
||||
return_errors?: true
|
||||
)
|
||||
|
||||
refute_received {:notification, _}
|
||||
end
|
||||
|
||||
test "notifications can be returned" do
|
||||
assert %Ash.BulkResult{records: [%{}, %{}], notifications: [%{}, %{}]} =
|
||||
Ash.bulk_create!([%{title: "title1"}, %{title: "title2"}], Post, :create,
|
||||
|
|
Loading…
Reference in a new issue