Hey I’m trying to make a unit test of update function, but it appears this error:
** (Protocol.UndefinedError) protocol Enumerable not implemented for %LoginBe.Accounts.Person{meta: #Ecto.Schema.Metadata<:loaded, “persons”>, apellidos: “some apellidos”, email: “some_email@gmail.com”, id: 988, inserted_at: ~N[2020-08-05 16:02:17], nombre: “some nombre”, password: “Some#password1”, password_confirmation: “Some#password1”, password_hash: “$2b$12$lCxDDSTGyYRAvpjTjbRbhuVeFU49CF4MJ/PPJAIXiqgbzBeVmgwTu”, tipo_usuario: “some tipo_usuario”, updated_at: ~N[2020-08-05 16:02:17]} of type LoginBe.Accounts.Person (a struct). This protocol is implemented for the following type(s): Ecto.Adapters.SQL.Stream, Postgrex.Stream, DBConnection.Stream, DBConnection.PrepareStream, Range, MapSet, Function, Date.Range, Map, HashDict, IO.Stream, File.Stream, List, GenEvent.Stream, HashSet, Stream
This is the unit test:
describe “update person” do
setup [:create_person]
test "renders person when data is valid", %{conn: conn, person: %Person{id: id} = person} do
conn = put(conn, Routes.person_path(conn, :update, person), person: @update_attrs)
assert %{"id" => ^id} = json_response(conn, 200)["data"]
conn = get(conn, Routes.person_path(conn, :show, id))
assert %{
"id" => id,
"apellidos" => "some updated apellidos",
"email" => "some_updated_email@gmail.com",
"nombre" => "some updated nombre",
"password" => "Someupdated$password1",
"password_confirmation" => "Someupdated$password1",
"tipo_usuario" => "some updated tipo_usuario"
} = json_response(conn, 200)["data"]
end
These are the other functions that the unit test uses:
def fixture(:person) do
{:ok, person} = Accounts.create_person(@create_attrs)
person
end
setup %{conn: conn} do
{:ok, conn: put_req_header(conn, “accept”, “application/json”)}
end
defp create_person(_) do
person = fixture(:person)
{:ok, person: person}
end
And the data used:
@create_attrs %{
apellidos: “some apellidos”,
email: “some_email@gmail.com”,
nombre: “some nombre”,
password: “Some#password1”,
password_confirmation: “Some#password1”,
tipo_usuario: “some tipo_usuario”
}
@update_attrs %{
apellidos: “some updated apellidos”,
email: “some_updated_email@gmail.com”,
nombre: “some updated nombre”,
password: “Someupdated$password1”,
password_confirmation: “Someupdated$password1”,
tipo_usuario: “some updated tipo_usuario”
}
How can I solve that?