Phoenix-Elixir assigns not available in eex template during test -
i'm in middle of learning elixir using phoenix web framework. i've gotten pretty far on own, i'm running error during test has me stumped. error occurs during testing, not when running app.
error:
1) test not create resource , renders errors when data invalid (potion.commentcontrollertest) test/controllers/comment_controller_test.exs:25 ** (argumenterror) assign @num_approved_comments not available in eex template.
source code here:
test
https://github.com/wsharp07/potion/blob/ui-improvements/test/controllers/comment_controller_test.exs
controller
https://github.com/wsharp07/potion/blob/ui-improvements/web/controllers/post_controller.ex#l52
page
https://github.com/wsharp07/potion/blob/ui-improvements/web/templates/post/show.html.eex#l48
i've read documentation numerous times, it's seems i'm still missing implementation detail. appreciated.
the test failing testing create action of commentcontroller, not show action of postcontroller.
your create action not include @num_approved_comments
in assigns:
def create(conn, %{"comment" => comment_params, "post_id" => post_id}) # find post , preload nav props post = repo.get!(post, post_id) |> repo.preload([:user, :comments]) # build changeset changeset = post |> build_assoc(:comments) |> comment.changeset(comment_params) case repo.insert(changeset) # inserted {:ok, _comment} -> conn |> put_flash(:info, "comment created successfully!") |> redirect(to: user_post_path(conn, :show, post.user, post)) # error on insert {:error, changeset} -> render(conn, potion.postview, "show.html", post: post, user: post.user, comment_changeset: changeset) end end