(Protocol.UndefinedError) protocol Enumerable not implemented for MyApp.MyContext.MySchema{__meta__: #Ecto.Schema.Metadata

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"]

These are the other functions that the unit test uses:

def fixture(:person) do
{:ok, person} = Accounts.create_person(@create_attrs)

setup %{conn: conn} do
{:ok, conn: put_req_header(conn, “accept”, “application/json”)}

defp create_person(_) do
person = fixture(:person)
{:ok, person: person}

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?

The message you’re seeing is usually a sign you’re passing a single struct to something that’s expecting a list of structs, but I don’t see any immediately obvious instances of that in the code you posted.

General note: for readability, consistently use triple-backticks (```) before and after to display code in blocks:

defmodule Foo do
   def wat(), do: IO.puts("wat")
1 Like