title: active_model_serializer + devise + rspec
body: <p>I was struggling with <code>undefined method 'authenticate' for nil:NilClass</code> for my requests using the serializer (Rspec).</p>
  
  <p><strong>api/users_controller_spec.rb</strong></p>
  
  <pre><code>require 'rails_helper'
  
  describe Api::V1::UsersController, type: :controller do
    describe "GET #show" do
      context "with valid credentials" do
        let!(:application) { create(:doorkeeper_application) } # OAuth application
        let!(:user)        { create(:user) }
        let!(:token)       { create(:doorkeeper_access_token, application_id: application.id, resource_owner_id: user.id) }
        before do
          allow(controller).to receive(:doorkeeper_token) {token}
        end
  
        context 'and valid request' do
          before(:each) do
            get :show, format: :json
            @json = JSON.parse(response.body)
          end
  
          it "returns the user with 'id'" do
            expect(@json["id"]).to_not be_nil
          end
        end
      end
    end
  end
  </code></pre>
  
  <p><strong>serializers/user_serializer.rb</strong></p>
  
  <pre><code>class UserSerializer &lt; ActiveModel::Serializer
    attributes :id, :uid, :name, :email
  end
  </code></pre>