-
Notifications
You must be signed in to change notification settings - Fork 2.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Plug.Conn.fetch_session(conn) with conn created by lib/phoenix/test/conn_test.ex conn/0 returns error #1008
Comments
This is not a bug. The preferred approach is to test through your endpoint, which fetches the session for you and applies all your plug transformations. My guess is you are fetching the session because you want to |
thanks @chrismccord! I'll go with the recycle method. As a side note, I'm wondering if this restriction would make feature tests prohibitively slow. Thoughtbot's https://github.com/thoughtbot/clearance runs blazing fast because it has a backdoor for user signin. It seems terribly inefficient to so a user login test before every other test that requires login. Personally, one of the biggest draws to elixir is fast / asyc tests, so hopefully it doesn't make a perceptible difference. |
In other languages yes. In Phoenix, no!!! Still blazing fast, no hacks/dependenices required :) If you want to backdoor the user, use the private assigns like I said, but honestly tests are going to be fast when going through the endpoint. |
@chrismccord Cool! Can you point me to an article or spot where private assigns are used? |
Hello @chrismccord , But
is throwing |
Yes, you need to recycle. If you call get right after post it will try to send the response twice. |
- Add session_user to root assigns - Conditionally display email with the appropriate button - to set the authenticated user on the connection in the controller tests, we visit the /auth/google/endpoint, per Chris McCord's comment: phoenixframework/phoenix#1008 (comment)
When I call Plug.Conn.fetch_session with a conn created by the conn_test file, I get the error:
Not 100% sure, but it seems like a bug since fetch_cookies works perfectly fine. It seems like phoenix should configure the session plug for me?
The text was updated successfully, but these errors were encountered: