From a26efe03e1820f854e43d0d141790c735b743094 Mon Sep 17 00:00:00 2001 From: Zach Daniel Date: Fri, 3 May 2024 12:36:20 -0400 Subject: [PATCH] test: add test for requiring actor in atomic changes --- test/actions/bulk/bulk_update_test.exs | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/test/actions/bulk/bulk_update_test.exs b/test/actions/bulk/bulk_update_test.exs index 5a399268..b4e04aca 100644 --- a/test/actions/bulk/bulk_update_test.exs +++ b/test/actions/bulk/bulk_update_test.exs @@ -81,6 +81,26 @@ defmodule Ash.Test.Actions.BulkUpdateTest do end end + defmodule AtomicallyRequireActor do + use Ash.Resource.Change + + def change(changeset, _, context) do + if context.actor do + changeset + else + Ash.Changeset.add_error(changeset, "actor is required") + end + end + + def atomic(changeset, _, context) do + if context.actor do + {:atomic, changeset, %{}} + else + {:atomic, Ash.Changeset.add_error(changeset, "actor is required"), %{}} + end + end + end + defmodule Post do @moduledoc false use Ash.Resource, @@ -167,6 +187,7 @@ defmodule Ash.Test.Actions.BulkUpdateTest do argument :authorize?, :boolean, allow_nil?: false change set_context(%{authorize?: arg(:authorize?)}) + change AtomicallyRequireActor end update :update_with_match do @@ -584,6 +605,7 @@ defmodule Ash.Test.Actions.BulkUpdateTest do :update_with_policy, %{title2: "updated value", authorize?: true}, authorize?: true, + actor: %{foo: :bar}, resource: Post, return_records?: true, return_errors?: true @@ -616,6 +638,7 @@ defmodule Ash.Test.Actions.BulkUpdateTest do :update_with_policy, %{title2: "updated value", authorize?: true}, authorize?: true, + actor: %{foo: :bar}, resource: Post, return_records?: true, return_errors?: true, @@ -638,6 +661,7 @@ defmodule Ash.Test.Actions.BulkUpdateTest do %{title2: "updated value", authorize?: false}, strategy: :atomic, authorize?: true, + actor: %{foo: :bar}, resource: Post, return_records?: true, return_errors?: true @@ -659,6 +683,7 @@ defmodule Ash.Test.Actions.BulkUpdateTest do :update_with_policy, %{title2: "updated value", authorize?: false}, strategy: :stream, + actor: %{foo: :bar}, authorize?: true, resource: Post, return_records?: true,