small medium large xlarge

Generic-user-small
06 May 2016, 12:59
Hugo (2 posts)

Hello, im stuck with the first integration test for logged out users (video_controller_test.ex) showing this error message:

  1) test requires user authentication on all actions (Rumbl.VideoControllerTest)
     test/controllers/video_controller_test.exs:4
     ** (FunctionClauseError) no function clause matching in Ecto.build_assoc/3 
     stacktrace:
       (ecto) lib/ecto.ex:467: Ecto.build_assoc(nil, :videos, %{})
       (Rumbl) web/controllers/video_controller.ex:38: Rumbl.VideoController.new/3
       (Rumbl) web/controllers/video_controller.ex:1: Rumbl.VideoController.action/2
       (Rumbl) web/controllers/video_controller.ex:1: Rumbl.VideoController.phoenix_controller_pipeline/2
       (Rumbl) lib/phoenix/router.ex:261: Rumbl.Router.dispatch/2
       (Rumbl) web/router.ex:1: Rumbl.Router.do_call/2
       (Rumbl) lib/Rumbl/endpoint.ex:1: Rumbl.Endpoint.phoenix_pipeline/1
       (Rumbl) lib/phoenix/endpoint/render_errors.ex:34: Rumbl.Endpoint.call/2
       (phoenix) lib/phoenix/test/conn_test.ex:194: Phoenix.ConnTest.dispatch/5
       test/controllers/video_controller_test.exs:6

line 4 in video_controller_test:

  test "requires user authentication on all actions", %{conn: conn} do

line 38 in video_controller.ex:

def new(conn, _params, user) do
changeset =
      user
      |> build_assoc(:videos)
      |> Video.changeset()

So far i did a diff on the code of test_helpers.ex, conn_case.ex, video_controller.ex and the test file itself, but i cant find any difference to the original files provided as download. Can you please point me in a direction where I can further look to find the problem?

Thank you in advance for your help.

Hugo

PS.: Is there any IRC channel to ask for getting help related to your book?

28aa4bd_pragsmall
07 May 2016, 08:26
José Valim (61 posts)

Both Chris and I are on #elixir-lang, feel free to hop in any time. It seems your code is missing the authentication bit, where we store the user as an assign. I would investigate if the test is being properly setup and if the route is under the proper scope.

Generic-user-small
07 May 2016, 09:58
Charles Changmin Han (5 posts)

I found and fixed my issue. This is the part that confused me. In chapter 6, the book includes an output that says,

Add the resource to your browser scope in web/router.ex:
​resources "/videos", VideoController

If you’re reading the epub version or following bit by bit, this looks like an instruction and what I’ve done is went ahead and included a route for /videos. And few pages later, the book instructed me to add another route for /manage/videos. Since /video was not using the authentication_user pipeline, this was throwing the exception when I ran the tests.

I’m not sure if you made the same mistake but I hope this helps Hugo.

Generic-user-small
07 May 2016, 10:43
Hugo (2 posts)

Thank you José for your fast reply. After looking into the scope in router.ex I noticed that “/videos” was in the “/” and “/manage” scope. And thank you Charles for your explanation, I am reading the epub as well and didnt check for duplicate entries in the routers, it seems we both ran exactly into the same situation.

The tests now complete with 0 failures and I am happy to continue the chapters of the book. This is so far the best resource for learning Phoenix that I’ve read!

See you in #elixir-lang & have a good day - Hugo

Generic-user-small
16 May 2016, 22:55
ian knauer (3 posts)

I also ran into this issue when going through the ebook.

Generic-user-small
16 Jun 2016, 14:23
Chris Freeman (1 post)

+1. Exact same thing happened to me with the e-book.

Generic-user-small
17 Jul 2016, 16:33
James Schorr (1 post)

+1 for me running into the same issue - I think that the book (I have the printed copy) should clarify that you must remove it from the / pipeline area in the router. It seems obvious later, but being new to Phoenix, I couldn’t find the issue until I googled it.

Generic-user-small
29 Jul 2016, 19:46
Joseph Abell (1 post)

I also ran into this issue. Glad the forum is here, I’ve been happily following along up until this point.

Img_0694_pragsmall
14 Aug 2016, 22:14
Mike Stok (1 post)

I too stumbled into this trap, please save others from it (though I did dig around a lot to no avail!)

Generic-user-small
17 Oct 2016, 22:45
Leroy Mason (3 posts)

I had the same issue, and was glad to find this info which fixed it.

Generic-user-small
19 Jan 2017, 03:22
Elliot Finley (15 posts)

+1 I also ran into the same issue.

You must be logged in to comment