Skip to content

Commit

Permalink
test: add test reproducing related aggregate reference
Browse files Browse the repository at this point in the history
  • Loading branch information
zachdaniel committed May 30, 2024
1 parent 93a5360 commit bc46d9d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
17 changes: 17 additions & 0 deletions test/atomics_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions test/support/resources/post.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit bc46d9d

Please sign in to comment.