polypush135
Say I have a controller like so.
def create_pass_reset(conn, %{"user" => %{"email" => email}}) do
case Accounts.reset_pass(email) do
{:ok, user} ->
conn
|> put_flash(:info, "Password Reset Sent to #{user.email}")
|> redirect(to: session_path(conn, :new))
...
end
end
Note that I am setting a flash on a conn that is due to be redirected.
And say I have a test like so.
test "POST /password-reset", %{conn: conn, user: user} do
conn = post conn, user_path(conn, :create_pass_reset, %{"user" => %{"email" => user.email}})
assert redirected_to(conn, 302) =~ "/login"
assert html_response(conn, 302) == "Password Reset Sent to #{user.email}"
end
Well clearly the issue with this test is that the conn does not contain the state after the redirection occurred and thus does not have the content we are looking for
IE:
Assertion with == failed
code: assert html_response(conn, 302) == "Password Reset Sent to #{user.email()}"
left: "<html><body>You are being <a href=\"/login\">redirected</a>.</body></html>"
right: "Password Reset Sent to email-11@example.com"
So my question is, how do I perform the redirect so that I can see the state after the redirection has occurred?
Trending in Questions
Hey guys,
I’ve got a huge CSV ( around 10 GB ) that needs to be processed hourly
Do you guys have any suggestions what is the best prac...
New
Hello!
Could someone please give me a help/sample code, how to delete a file from s3 using waffle/waffle_ecto from Phoenix app.
I creat...
New
I have what I’ve heard referred to as a “lookup table” in my database. This is a way of assigning codes to common values. One common lo...
New
What approach to take when sending live updates to “random” users Hi! I have a question, I have a little chat app, and when I create a DM...
New
Anyone here using Honeybadger?
My Honeybadger account is being overwhelmed with noise from some bots. Seeing a lot of
Bandit.HTTPError...
New
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
Other Trending Topics
I am happy to introduce the very α version of the new programming language compiled to BEAM.
Welcome Cure.
It has literally three kille...
New
Hobbes is a low-level distributed database for the Elixir programming language.
Hobbes provides a simple, safe, and scalable storage lay...
New
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve.
They are GUI (Emerge) and State management (S...
New
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
There are three potential reasons for members of this forum to have a look at https://vutuv.de
You are tired or annoyed of LinkedIn.
Yo...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #blog-post
- #elixir-ls
- #ai
- #elixirconf-us
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #hex
- #security
- #metaprogramming










Showing Posts 1 to 10- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
chrismccord
Something like this should work:
polypush135
Gonna have to use that assert / assignment again,
assert "/login" = redir_path = redirected_to(conn, 302)Thank you yet again @chrismccord
polypush135
Also what are your thoughts about this pattern of following the redirect?
This is something I’ve yet to see in the community.
chrismccord
It’s just fine pattern wise. It’s not exactly the same, but our context generators make use of
redirected_paramsto construct a path and thengetthe show page of a created resource:https://github.com/phoenixframework/phoenix/blob/444569fb99a599d67ec16fd492c3681412dd5759/priv/templates/phx.gen.html/controller_test.exs#L33-L35
Jono
Sorry to bug you again on this. I’m struggling with something when maintaining state.
I get the principle of saving
conn.assignsto save authentication to reuse with different calls. I’m probably misunderstanding, but how do I make sure the validation errors don’t get tossed. Or the 302 is follow without recycling (I think this would solve it)?The below is the code in question, there is a
setup [:create_user]for thedescribeblock.This gets a
302and “you are being redirected”.thiago
Getting the same thing.
302<html><body>You are being <a href="/auth?redirect_to=...">redirected</a>.</body></html>polypush135
I’m having a hard time understanding the question. From what I can understand from the code is that you want to assert that if you are passing in invalid_attrs to the update function than the html response should be a 200 and include the text
edit client.I assume that to be a correct assertion of what you are expecting from that controller function. Sadly without seeing that functions definition I can’t say as to why its returning a 302 with the text your are being redirected.
I’m also not sure why you are referring to the
recyclefunction . In my case I was prescribe that method because it allowed me to make a follow up request on that sameconnin my test which was to follow the redirection so that I could see the follow up page and assert on the flash message of that completed redirection.Though if I assume you are passing in bad attrs into a update action you would not want a 302 redirection on that post.
polypush135
Is it possible you are in a redirection loop?
Edit: Don’t laugh it happens.
thiago
I think you’re right. That redirect is to
/authpath, so my test was probably lacking a current_user. My badthiago
Actually, I just tried it on another endpoint of mine and had the same issue.
Is it possible that by calling
recycle(conn)we lose the previously assignedcurrent_user?