From ec91e2ee9b6340c35c76f8ab6d99a2246703a0a3 Mon Sep 17 00:00:00 2001 From: Zach Daniel Date: Mon, 22 Apr 2024 18:58:57 -0400 Subject: [PATCH] fix: reproduce issue around atomic updates & validations --- test/atomics_test.exs | 12 ++++++++++++ test/support/resources/post.ex | 5 +++++ 2 files changed, 17 insertions(+) diff --git a/test/atomics_test.exs b/test/atomics_test.exs index 7f03507..62828fa 100644 --- a/test/atomics_test.exs +++ b/test/atomics_test.exs @@ -33,6 +33,18 @@ defmodule AshPostgres.AtomicsTest do |> Ash.update!() end + test "an atomic validation is based on where it appears in the action" do + post = + Post + |> Ash.Changeset.for_create(:create, %{title: "bar"}) + |> Ash.create!() + + # just asserting that there is no exception here + post + |> Ash.Changeset.for_update(:change_title_to_foo_unless_its_already_foo) + |> Ash.update!() + end + test "an atomic works with a datetime" do post = Post diff --git a/test/support/resources/post.ex b/test/support/resources/post.ex index d1b5693..5184edf 100644 --- a/test/support/resources/post.ex +++ b/test/support/resources/post.ex @@ -113,6 +113,11 @@ defmodule AshPostgres.Test.Post do require_atomic?(false) end + update :change_title_to_foo_unless_its_already_foo do + validate attribute_does_not_equal(:title, "foo") + change set_attribute(:title, "foo") + end + read :title_is_foo do filter(expr(title == "foo")) end