title: Stubbing current_user in Rails functional test using Minitest
body: <p>I'm having some trouble stubbing current_user in a Rails functional test for a controller.  I'm using Rails 4 and Minitest.  Currently, in the setup block I have this line.</p>
  
  <pre><code>ApplicationController.any_instance.stubs(:current_user).returns(users(:admin))
  </code></pre>
  
  <p>That's kind of working; however, I'm getting the following error from my view where current_user is referenced into a routing/url helper (edit_user_path(current_user)).</p>
  
  <pre><code>ActionView::Template::Error: No route matches {:action=&gt;"edit", :controller=&gt;"users", :id=&gt;nil} missing required keys: [:id]
  </code></pre>
  
  <p>What is the recommended way of stubbing current_user in controller/functional test?  Here's my full test.</p>
  
  <pre><code>require 'test_helper'
  
  class Admin::SitesControllerTest &lt; ActionController::TestCase
    setup do
      @site = sites(:test)
      @request.env['HTTP_HOST'] = "#{@site.ssl_prefix}.testing.com"
      ApplicationController.any_instance.stubs(:current_user).returns(users(:admin))
    end
  
    test "should show edit form" do
      get :edit, id: @site.id
      assert_response :success
      assert_template layout: "layouts/admin/layout"
    end
  end
  </code></pre>