test: add test reproducing related aggregate reference

This commit is contained in:
Zach Daniel 2024-05-30 00:27:20 -05:00
parent 93a536043c
commit bc46d9d9c4
2 changed files with 21 additions and 0 deletions

View file

@ -95,6 +95,23 @@ defmodule AshPostgres.AtomicsTest do
|> Ash.update!() |> Ash.update!()
end 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 test "an atomic validation is based on where it appears in the action" do
post = post =
Post Post

View file

@ -100,6 +100,10 @@ defmodule AshPostgres.Test.Post do
change(atomic_update(:title, expr("#{sum_of_author_count_of_posts}"))) change(atomic_update(:title, expr("#{sum_of_author_count_of_posts}")))
end end
update :set_title_to_author_profile_description do
change(atomic_update(:title, expr(author.profile_description)))
end
destroy :destroy_with_confirm do destroy :destroy_with_confirm do
require_atomic?(false) require_atomic?(false)
argument(:confirm, :string, allow_nil?: false) argument(:confirm, :string, allow_nil?: false)