So I’m working through some tests from a generated chunk of Phoenix bits, and oddly enough the route helper functions are not behaving consistently.
The generated tests worked fine until I forced auth on certain endpoints, which I was able to work through for most things, but in this particular test I’m getting stuck with the following error:
** (ArgumentError) PxblogWeb.Router.Helpers.post_path/3 called with invalid params.
The last argument to this function should be a keyword list or a map.
For example:
post_path(conn, :index, page: 5, per_page: 10)
It is possible you have called this function without defining the proper
number of path segments in your router.
code: conn = get(conn, Routes.post_path(conn, :show, my_post))
The confusing part is that the code looks like this:
my_post = Content.get_post!(id)
assert redirected_to(conn) == Routes.post_path(conn, :show, my_post)
conn = get(conn, Routes.post_path(conn, :show, my_post))
assert html_response(conn, 200) =~ "Show Post"
You can see that I get a %Post{} struct, then call Routes.post_path/3
to generate a string like /posts/71
. This works just fine. But then very next line makes the very same call to the same function, and it throws the above error.
The error message is… odd, at best. It says that the final argument must be a map or keyword list, which I am indeed passing. But then if I try any sort of keyword list, it bails with the same error, which is extra weird.
Any pointers? I know I can just build the path I want, but it seems silly to need to do so when it worked one line above.
Thanks!