From 36317f5270651b569b6130ce20ea9b12fdc96c92 Mon Sep 17 00:00:00 2001 From: Joel Kociolek Date: Wed, 10 Jul 2024 19:33:43 +0300 Subject: [PATCH] fix: custom message of identities wasn't used --- lib/data_layer.ex | 2 +- test/support/resources/post.ex | 2 +- test/unique_identity_test.exs | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/data_layer.ex b/lib/data_layer.ex index 280d191..8a7b8c4 100644 --- a/lib/data_layer.ex +++ b/lib/data_layer.ex @@ -1046,7 +1046,7 @@ defmodule AshMysql.DataLayer do identity.name == searched_identity_name end) - %{fields: identity.keys, message: nil} + %{fields: identity.keys, message: identity.message} end defp set_table(record, changeset, operation, table_error?) do diff --git a/test/support/resources/post.ex b/test/support/resources/post.ex index feeecf9..39560bc 100644 --- a/test/support/resources/post.ex +++ b/test/support/resources/post.ex @@ -63,7 +63,7 @@ defmodule AshMysql.Test.Post do end identities do - identity(:uniq_one_and_two, [:uniq_one, :uniq_two]) + identity(:uniq_one_and_two, [:uniq_one, :uniq_two] , message: "uniq_one_and_two message") end attributes do diff --git a/test/unique_identity_test.exs b/test/unique_identity_test.exs index fb1bef0..a63a7a6 100644 --- a/test/unique_identity_test.exs +++ b/test/unique_identity_test.exs @@ -19,7 +19,7 @@ defmodule AshMysql.Test.UniqueIdentityTest do end end - test "unique constraint errors for identities are properly caught" do + test "unique constraint errors for identities are properly caught and custom message is used" do attrs = %{title: "title", uniq_one: "one", uniq_two: "two"} Post @@ -27,7 +27,7 @@ defmodule AshMysql.Test.UniqueIdentityTest do |> Ash.create!() assert_raise Ash.Error.Invalid, - ~r/Invalid value provided for uniq_one: has already been taken/, + ~r/Invalid value provided for uniq_one: uniq_one_and_two message/, fn -> Post |> Ash.Changeset.for_create(:create, attrs)