title: How do I check to see if a user will be redirected to his/her profile after login (Rails Tutorial Ch. 9)?
body: <p>I'm working on <a href="https://www.railstutorial.org/book/updating_and_deleting_users#sec-updating_deleting_exercises" rel="nofollow">chapter 9, exercise 1 of the Rails Tutorial</a>. I'm unsure of what to do in order to test that, after a normal login, the user will be redirected to his/her profile. The exercise's hint implies that I should modify the "successful edit with friendly forwarding" test in users_edit_test.rb in order to compare the value of session[:forwarding_url] with that of the user profile path. To do that, I added</p>
  
  <pre><code>assert_equal session[:forwarding_url], user_path
  </code></pre>
  
  <p>to the end of the function. However, when I do <strong>rake test</strong>, I get this error:</p>
  
  <pre><code>Expected: nil
  Actual: "/users/762146111"
  </code></pre>
  
  <p>Can anyone assist me with this problem?</p>
  
  <p><strong>Update</strong>: Here are the controller and helper that are being tested:</p>
  
  <pre><code>class SessionsController &lt; ApplicationController
    def new
    end
  
    def create
      user = User.find_by(email: params[:session][:email].downcase)
      if user &amp;&amp; user.authenticate(params[:session][:password])
        log_in user
        params[:session][:remember_me] == '1' ? remember(user) : forget(user)
        redirect_back_or user
      else
        flash.now[:danger] = 'Invalid email/password combination'
        render 'new'
      end
    end
  
    def destroy
      log_out if logged_in?
      redirect_to root_url
    end
  end
  
  module SessionsHelper
    # Logs in the given user.
    def log_in(user)
      session[:user_id] = user.id
    end
  
    # Remembers a user in a persistent session.
    def remember(user)
      user.remember
      cookies.permanent.signed[:user_id] = user.id
      cookies.permanent[:remember_token] = user.remember_token
    end
  
    # Returns true if the given user is the current user.
    def current_user?(user)
      user == current_user
    end
  
    # Returns the current logged-in user (if any).
    def current_user
      if (user_id = session[:user_id])
        @current_user ||= User.find_by(id: user_id)
      elsif (user_id = cookies.signed[:user_id])
        user = User.find_by(id: user_id)
        if user &amp;&amp; user.authenticated?(cookies[:remember_token])
          log_in user
          @current_user = user
        end
      end
    end
  
    # Returns true if the user is logged in, false otherwise.
    def logged_in?
      !current_user.nil?
    end
  
    # Forgets a persistent session.
    def forget(user)
      user.forget
      cookies.delete(:user_id)
      cookies.delete(:remember_token)
    end
  
    # Logs out the current user.
    def log_out
      forget(current_user)
      session.delete(:user_id)
      @current_user = nil
    end
  
    # Redirects to stored located (or to the default).
    def redirect_back_or(default)
      redirect_to(session[:forwarding_url] || default)
      session.delete(:forwarding_url)
    end
  
    # Stores the URL trying to be accessed.
    def store_location
      session[:forwarding_url] = request.url if request.get?
    end
  end
  </code></pre>