Skip to content

Commit

Permalink
chore:test(ex/data_case): update errors_on helper to phx.new temp…
Browse files Browse the repository at this point in the history
…late
  • Loading branch information
firestack committed Oct 23, 2024
1 parent c6fb4a6 commit 40edf59
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions test/support/data_case.ex
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ defmodule Skate.DataCase do
end

@doc """
A helper that transform changeset errors to a map of messages.
A helper that transforms changeset errors into a map of messages.
assert {:error, changeset} = Accounts.create_user(%{password: "short"})
assert "password is too short" in errors_on(changeset).password
Expand All @@ -49,8 +49,8 @@ defmodule Skate.DataCase do
"""
def errors_on(changeset) do
Ecto.Changeset.traverse_errors(changeset, fn {message, opts} ->
Enum.reduce(opts, message, fn {key, value}, acc ->
String.replace(acc, "%{#{key}}", to_string(value))
Regex.replace(~r"%{(\w+)}", message, fn _, key ->
opts |> Keyword.get(String.to_existing_atom(key), key) |> to_string()
end)
end)
end
Expand Down

0 comments on commit 40edf59

Please sign in to comment.