From 6062c92929a7f9e1989d38f9b290bd0527ba68c1 Mon Sep 17 00:00:00 2001 From: Jechol Lee Date: Mon, 29 Apr 2024 13:27:17 +0900 Subject: [PATCH] Fix Splode.Error.message/1 --- lib/splode/error.ex | 2 +- test/splode/error_test.exs | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 test/splode/error_test.exs diff --git a/lib/splode/error.ex b/lib/splode/error.ex index 2160496..4c8567c 100644 --- a/lib/splode/error.ex +++ b/lib/splode/error.ex @@ -123,7 +123,7 @@ defmodule Splode.Error do Enum.reduce(List.wrap(vars), string, fn {key, value}, acc -> if String.contains?(acc, "%{#{key}}") do - String.replace(acc, "%{#{key}}", to_string(value)) + String.replace(acc, "%{#{key}}", inspect(value)) else acc end diff --git a/test/splode/error_test.exs b/test/splode/error_test.exs new file mode 100644 index 0000000..26965f7 --- /dev/null +++ b/test/splode/error_test.exs @@ -0,0 +1,12 @@ +defmodule Splode.ErrorTest do + use ExUnit.Case + + defmodule InvalidAttribute do + use Splode.Error, fields: [:message], class: :invalid + end + + test "message" do + invalid = %InvalidAttribute{message: "must be in %{list}", vars: [list: [:foo, :bar]]} + assert "must be in [:foo, :bar]" == invalid |> Exception.message() + end +end