Protocol Enumerable not implemented for %Pindex.Auth.User

Hi.

This is completely a noob question. I am trying to implement a user auth controller, and would have a test to test the user renders on update. And I end up with this error.

 1) test update user renders user when data is valid (PindexWeb.UserControllerTest)
     test/pindex_web/controllers/user_controller_test.exs:38
     ** (Protocol.UndefinedError) protocol Enumerable not implemented for %Pindex.Auth.User{__meta__: #Ecto.Schema.Metadata<:loaded, "users">, avatar: "https://robohash.org/laudantiumconsequaturfacilis.bmp?size=50x50&set=set1", bio: "some bio", created_at: ~N[2019-11-21 17:49:34], email: "some@email.com", id: 71, is_active: true, is_verified: false, mobile: "+91-9999999999", password: "some password", password_hash: "$2b$04$G6atusZq4a88Asct.AsQReuELZN4iJrz9/anFNxoMFw1xJ8Cff4I.", updated_at: ~N[2019-11-21 17:49:34], verification_code: "589A69F8FF6E34AC94C5CA2CA2BE11CD685C655E98DE8ADB92B2807E76A8253B"}. This protocol is implemented for: Ecto.Adapters.SQL.Stream, Postgrex.Stream, DBConnection.PrepareStream, DBConnection.Stream, Date.Range, File.Stream, Function, GenEvent.Stream, HashDict, HashSet, IO.Stream, List, Map, MapSet, Range, Stream
     code: conn = put(conn, Routes.user_path(conn, :update, user), user: @update_attrs)
     stacktrace:
       (elixir) /home/build/elixir/lib/elixir/lib/enum.ex:1: Enumerable.impl_for!/1
       (elixir) /home/build/elixir/lib/elixir/lib/enum.ex:141: Enumerable.reduce/3
       (elixir) lib/enum.ex:3015: Enum.reduce/3
       (pindex) lib/pindex_web/router.ex:1: PindexWeb.Router.Helpers.segments/4
       (pindex) lib/pindex_web/router.ex:1: PindexWeb.Router.Helpers.user_path/3
       test/pindex_web/controllers/user_controller_test.exs:43: (test)

What does this error actually mean? And what to keep in mind to avoid it?

Hi!

This error means that Elixir tries to interpret user as something that can be iterated over (enumerable). My guess here is that maybe you’re passing the whole user struct to user_path when you should be passing just the user name?

Show us the route inside your router.ex file. Maybe the parameter to the path helper shouldn’t be the user object itself, but a keyword list.