From bc46d9d9c4b01cef85a553c2423ea2ddd2c5684e Mon Sep 17 00:00:00 2001 From: Zach Daniel Date: Thu, 30 May 2024 00:27:20 -0500 Subject: [PATCH] test: add test reproducing related aggregate reference --- test/atomics_test.exs | 17 +++++++++++++++++ test/support/resources/post.ex | 4 ++++ 2 files changed, 21 insertions(+) diff --git a/test/atomics_test.exs b/test/atomics_test.exs index 845c8d7..5a83521 100644 --- a/test/atomics_test.exs +++ b/test/atomics_test.exs @@ -95,6 +95,23 @@ defmodule AshPostgres.AtomicsTest do |> Ash.update!() end + test "an atomic update can be set to the value of a related aggregate" do + author = + Author + |> Ash.Changeset.for_create(:create, %{first_name: "John", last_name: "Doe"}) + |> Ash.create!() + + post = + Post + |> Ash.Changeset.for_create(:create, %{title: "bar", author_id: author.id}) + |> Ash.create!() + + # just asserting that there is no exception here + post + |> Ash.Changeset.for_update(:set_title_to_author_profile_description) + |> Ash.update!() + end + test "an atomic validation is based on where it appears in the action" do post = Post diff --git a/test/support/resources/post.ex b/test/support/resources/post.ex index 6501750..23376ab 100644 --- a/test/support/resources/post.ex +++ b/test/support/resources/post.ex @@ -100,6 +100,10 @@ defmodule AshPostgres.Test.Post do change(atomic_update(:title, expr("#{sum_of_author_count_of_posts}"))) end + update :set_title_to_author_profile_description do + change(atomic_update(:title, expr(author.profile_description))) + end + destroy :destroy_with_confirm do require_atomic?(false) argument(:confirm, :string, allow_nil?: false)