title: Undefined local variable or method 'session' in model test
body: <p>I'm creating a Ruby on Rails application, and am trying to run a test involving my User model to see if the "Remember me" feature works. I'm using Rails' inbuilt <code>cookies</code> hash to store the cookies, and the <code>session</code> hash to store the current session. I've run various tests (integration, model, and controller) where I use the <code>session</code> variable, but for some reason in this particular case it isn't being recognized.</p>
  
  <pre><code>NameError: undefined local variable or method `session' for #&lt;UserTest:0x0000000658b5c8&gt;
  </code></pre>
  
  <p>The error happens in the <code>else</code> block in the <code>log_in_as</code> method below:</p>
  
  <p><code>test_helper.rb</code></p>
  
  <pre><code>...
  
  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
  </code></pre>
  
  <p>I call <code>log_in_as</code> in my User test; both of these tests fail.</p>
  
  <p><code>user_test.rb</code></p>
  
  <pre><code>require 'test_helper'
  ...
  test "login with remembering" do
    log_in_as(@user, remember_me: '1')
    assert_not_nil cookies['remember_token']
  end
  
  test "login without remembering" do
    log_in_as(@user, remember_me: '0')
    assert_nil cookies['remember_token']
  end
  ...
  </code></pre>
  
  <p>And when I remove that line of code from the helper, an error is thrown saying that <code>cookies</code> isn't recognized. What is the issue here?</p>