Skip to content

Commit

Permalink
fix: Splode.Error.message/1 (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
jechol authored Apr 29, 2024
1 parent 4008406 commit 61d76e5
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/splode/error.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 12 additions & 0 deletions test/splode/error_test.exs
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 61d76e5

Please sign in to comment.