In chapter 8 of Programming Phoenix, the user_test.exs failed, located in testing_mvc/listings/rumbl/test/models/user_test.exs, and it’s not clear what the problem is. (context)
test changeset does not accept long usernames (Rumbl.UserTest)
test/models/user_test.exs:26
Assertion with in failed
code: {:username, {"should be at most %{count} character(s)", [count: 20]}} in errors_on(%User{}, attrs)
lhs: {:username, {"should be at most %{count} character(s)", [count: 20]}}
rhs: [username: "should be at most 20 character(s)"]
stacktrace:
test/models/user_test.exs:28: (test)
Can someone please help with the debugging thought process for the following error message? When manually checking the UI for the character limit, my changeset/2 function in web/model/user.ex correctly handles the username constraint. Here’s that function (the only difference with the original from the book is that I set the default params value to an empty map instead of an :empty atom.
# see https://github.com/elixir-ecto/ecto/blob/master/CHANGELOG.md
# def changeset(model, params \\ :empty) do
def changeset(model, params \\ %{}) do
model
|> cast(params, ~w(name username), [])
|> validate_length(:username, min: 1, max: 20)
|> unique_constraint(:username)
end