title: Rails3: Functional tests fail with NoMethodError: undefined method `user' for nil:NilClass
body: <p>I'm using Devise (v2.1.2) with Omniauth for user verification. I'm working on a functional test for a controller that takes a JSON object as the POST body and thus using the technique from <a href="https://stackoverflow.com/questions/2103977/how-to-send-raw-post-data-in-a-rails-functional-test">this question</a> to set the raw POST body. This works fine for development, but when I run tests I get an exception on a method that's completely unauthenticated: </p>
  
  
  
  <pre class="lang-rb prettyprint-override"><code>NoMethodError: undefined method `user' for nil:NilClass
  </code></pre>
  
  <p>Example test:</p>
  
  <pre class="lang-rb prettyprint-override"><code>test "should be able to create an item" do    
    m = FactoryGirl.attributes_for(:item)
    raw_post :create, {}, m.to_json 
    assert_response :success   
  end
  </code></pre>
  
  <p>None of my models have a <code>user</code> method, and nothing in this controller uses authentication,  so I was pretty confused. A full stack trace shows that the error comes from the first line of this function in Devise:</p>
  
  <pre class="lang-rb prettyprint-override"><code>def sign_out_all_scopes(lock=true)
    users = Devise.mappings.keys.map { |s| warden.user(:scope =&gt; s, :run_callbacks =&gt; false) }
  
    warden.raw_session.inspect
    warden.logout
    expire_devise_cached_variables!
    warden.clear_strategies_cache!
    warden.lock! if lock
  
    users.any?
  end
  </code></pre>
  
  <p>So it looks like in my functional tests (and only in my functional tests) the <code>warden</code> object is nil. </p>
  
  <ol>
  <li>Why is this function being called on an unauthenticated request?</li>
  <li>Why doesn't the <code>warden</code> object exist here?</li>
  <li>What can I do to fix it? </li>
  </ol>