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)