title: Ruby on Rails Tutorial 9.2.3 Friendly Forwarding Error
body: <p>I am very new to programming and I am trying to go over this tutorial. I have followed the codes given with the exception of writing my own code for the exercises at the end of the chapter. I am now stuck on this error.</p>
  
  <pre><code>Failures:
  
    1) Authentication authorization for non-signed-in users when attempting to visit a protected page after signing in should render the desired protected page
   Failure/Error: page.should have_selector('title', text: 'Edit user')
     expected css "title" with text "Edit user" to return something
   # ./spec/requests/authentication_pages_spec.rb:63:in `block (6 levels) in &lt;top (required)&gt;'
  
  Finished in 3.12 seconds
  73 examples, 1 failure
  
  Failed examples:
  
  rspec ./spec/requests/authentication_pages_spec.rb:62 # Authentication authorization for non-signed-in users when attempting to visit a protected page after signing in should render the desired protected page
  </code></pre>
  
  <p>Here are the code that I added.</p>
  
  <p>spec/requests/authentication_pages_spec.rb</p>
  
  <pre><code>require 'spec_helper'
  
  describe "Authentication" do
  
    subject { page }
  
    describe "signin page" do
      before { visit signin_path }
  
      it { should have_selector('h1',    text: 'Sign in') }
      it { should have_selector('title', text: 'Sign in') }
    end
  
    describe "signin" do
  
      before { visit signin_path }
  
      describe "with invalid information" do
        before { click_button "Sign in" }
  
        it { should have_selector('title', text: 'Sign in') }
        it { should have_selector('div.alert.alert-error', text: 'Invalid') }
  
        describe "after visiting another page" do
          before { click_link "Home" }
          it { should_not have_selector('div.alert.alert-error') }
        end
      end
  
      describe "with valid information" do
        let(:user) { FactoryGirl.create(:user) }
        before { sign_in user }
  
        it { should have_selector('title', text: user.name) }
        it { should have_link('Profile',  href: user_path(user)) }
        it { should have_link('Settings', href: edit_user_path(user)) }
        it { should have_link('Sign out', href: signout_path) }
        it { should_not have_link('Sign in', href: signin_path) }
  
        describe "followed by signout" do
          before { click_link "Sign out" }
          it { should have_link('Sign in') }
        end
      end
    end
  
    describe "authorization" do
  
      describe "for non-signed-in users" do
        let(:user) { FactoryGirl.create(:user) }
  
        describe "when attempting to visit a protected page" do
          before do
            visit edit_user_path(user)
            fill_in "Email",    with: user.email
            fill_in "Password", with: user.password
            click_button "Sign in"
          end
  
          describe "after signing in" do
  
            it "should render the desired protected page" do
              page.should have_selector('title', text: 'Edit user')
            end
          end
        end
  
        describe "in the Users controller" do
  
          describe "visiting the edit page" do
            before { visit edit_user_path(user) }
            it { should have_selector('title', text: 'Sign in') }
          end
  
          describe "submitting to the update action" do
            before { put user_path(user) }
            specify { response.should redirect_to(signin_path) }
          end
        end
      end
  
      describe "as wrong user" do
        let(:user) { FactoryGirl.create(:user) }
        let(:wrong_user) { FactoryGirl.create(:user, email: "wrong@example.com") }
        before { sign_in user }
  
        describe "visiting Users#edit page" do
          before { visit edit_user_path(wrong_user) }
          it { should_not have_selector('title', text: full_title('Edit user')) }
        end
  
        describe "submitting a PUT request to the Users#update action" do
          before { put user_path(wrong_user) }
          specify { response.should redirect_to(root_path) }
        end
      end
    end
  end
  </code></pre>
  
  <p>app/helpers/sessions_helper.rb</p>
  
  <pre><code>module SessionsHelper
  
    def sign_in(user)
      cookies.permanent[:remember_token] = user.remember_token
      self.current_user = user
    end
  
    def signed_in?
      !current_user.nil?
    end
  
    def current_user=(user)
      @current_user = user
    end
  
    def current_user
      @current_user ||= User.find_by_remember_token(cookies[:remember_token])
    end
  
    def current_user?(user)
      user == current_user
    end
  
    def sign_out
      self.current_user = nil
      cookies.delete(:remember_token)
    end
  
    def redirect_back_or(default)
      redirect_to(session[:return_to] || default)
      session.delete(:return_to)
    end
  
    def store_location
      session[:return_to] = request.url
    end
  end
  </code></pre>
  
  <p>app/controllers/users_controller.rb</p>
  
  <pre><code>class UsersController &lt; ApplicationController
    before_filter :signed_in_user, only: [:edit, :update]
    before_filter :correct_user,   only: [:edit, :update]
  
    def show
      @user = User.find(params[:id])
    end
  
    def new
      @user = User.new
    end
  
    def create
      @user = User.new(params[:user])
      if @user.save
        sign_in @user
        flash[:success] = "Welcome to the Sample App!"
        redirect_to @user
      else
        render 'new'
      end
    end
  
    def edit
    end
  
    def update
      if @user.update_attributes(params[:user])
        flash[:success] = "Profile updated"
        sign_in @user
        redirect_to @user
      else
        render 'edit'
      end
    end
  
    private
  
      def signed_in_user
        unless signed_in?
          store_location
          redirect_to signin_url, notice: "Please sign in."
        end
      end
  
      def correct_user
        @user = User.find(params[:id])
        redirect_to(root_path) unless current_user?(@user)
      end
  end
  </code></pre>
  
  <p>This is my code after doing the 1st exercise on Chapter 8.
  app/controllers/sessions_controller.rb</p>
  
  <pre><code>class SessionsController &lt; ApplicationController
  
    def new
    end
  
    def create
      user = User.find_by_email(params[:email])
      if user &amp;&amp; user.authenticate(params[:password])
          session[:user] = user.id
          sign_in user
          redirect_to user
      else
          flash.now[:error] = 'Invalid email/password combination'
          render 'new'
      end 
    end
  
    def destroy
      sign_out
       redirect_to root_path
    end
  end
  </code></pre>