title: Test in Michael Hartl's Tutorial Chapter 8 Fails
body: <p>I am working on Michael Hartl's Rails Tutorial and I am stuck at Chapter 8.4.6 with the Remember Test failing.
  I am confused on what to do next.</p>
  
  <p>Here is the test result</p>
  
  <pre><code> FAIL["test_login_with_remembering", UsersLoginTest, 2015-08-25 15:26:59 +0100]
   test_login_with_remembering#UsersLoginTest (1440512819.22s)
      Expected nil to not be nil.
      test/integration/users_login_test.rb:52:in `block in &lt;class:UsersLoginTest&gt;'
  </code></pre>
  
  <p>Here is my user_login_test.rb</p>
  
  <pre><code>require 'test_helper'
  
      class UsersLoginTest &lt; ActionDispatch::IntegrationTest
  
        def setup
          @user = users(:microte)
        end
  
        test "login with invalid information" do
          get login_path
          assert_template "sessions/new"
          post login_path, session: { email: "", password: "" }
          assert_template "sessions/new"
          assert_not flash.empty?
          get root_path
          assert flash.empty?
        end
  
        test "login with valid information" do
          get login_path
          post login_path, session: { email: @user.email, password: 'microte' }
          assert_redirected_to @user
          follow_redirect!
          assert_template "users/show"
          assert_select "a[href=?]", login_path, count: 0
          assert_select "a[href=?]", logout_path
          assert_select "a[href=?]", user_path(@user)
        end
  
        test "login with valid information followed by logout" do
          get login_path
          post login_path, session: { email: @user.email, password: 'microte' }
          assert_redirected_to @user
          follow_redirect!
          assert_template "users/show"
          assert_select "a[href=?]", login_path, count: 0
          assert_select "a[href=?]", logout_path
          assert_select "a[href=?]", user_path(@user)
          delete logout_path
          assert_not is_logged_in?
          assert_redirected_to root_url
          # simulate a user clicking logout in a second window.
          delete logout_path
          follow_redirect!
          assert_select "a[href=?]", login_path
          assert_select "a[href=?]", logout_path, count: 0
          assert_select "a[href=?]", user_path(@user), count: 0
        end
  
          test "login with remembering" do
          log_in_as(@user, remember_me: '1')
          assert_not_nil cookies['remember_token'] #line 52
        end
  
        test "login without remembering" do
          log_in_as(@user, remember_me: '0')
          assert_nil cookies['remember_token']
        end
      end
  </code></pre>
  
  <p>My session_controller.rb</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_to user
          else
            flash.now[:danger] = "Invalid e-mail/password combination"
            render "new"
          end
        end
  
        def destroy
          log_out if logged_in?
          redirect_to root_url
        end
      end
  </code></pre>
  
  <p>My test_helper.rb</p>
  
  <pre><code>ENV['RAILS_ENV'] ||= 'test'
      require File.expand_path('../../config/environment', __FILE__)
      require 'rails/test_help'
      require "minitest/reporters"
      Minitest::Reporters.use!
  
      class ActiveSupport::TestCase
        # Setup all fixtures in test/fixtures/*.yml for all tests in alphabetical order.
        fixtures :all
  
        # Add more helper methods to be used by all tests here...
  
        # Returns true if a test user is logged in.
        def is_logged_in?
          !session[:user_id].nil?
        end
  
        # Log in a test user.
        def log_in_as(user, options = {})
          password = options[:password]     || 'password'
          remember_me = options[:remember_me]  || '1'
          if integration_test?
            post login_path, session: { email:        user.email, 
                                        password:     password,
                                        remember_me:  remember_me }
          else
            session[:user_id] = user.id
          end
        end
  
          private
  
          # Returns true inside an integration test.
          def integration_test?
            defined?(post_via_redirect)
          end
      end
  </code></pre>
  
  <p>Users.yml</p>
  
  <pre><code>microte:
        name: Lord Microte
        email: lord@microte.com
        password_digest: &lt;%= User.digest('password') %&gt;
  </code></pre>
  
  <p>I really would appreciate if someone could help out.</p>