title: Setting token and header in rspec test for JSON API
body: <p>I'm trying to test a json written in rails in rspec. I'm not sure about the syntax. This is what I have so far:</p>
  
  <pre><code>require 'rails_helper'
  
  RSpec.describe V1::VersionsController, :type =&gt; :controller do
  
    before do
      @token = "0"
      request.env["Content-Type"] = 'application/vnd.api+json; charset=utf-8'
    end
  
    describe "GET index" do
      it "renders the index JSON" do
        @request.headers['Content-Type'] = 'application/vnd.api+json; charset=utf-8'
        request.env['Content-Type'] = 'application/vnd.api+json; charset=utf-8'
        params = { token: @token }
        get :index, :format =&gt; :json, token: @token
        #response.should be_success
        body = JSON.parse(response.body)
        ap body
      end
    end
  end
  </code></pre>
  
  <p>I tried it in a bunch of different ways as you can see. But I'm getting a 403 error.</p>
  
  <p>I'm using <code>Rails 5.0.0.beta3</code>, <code>ruby 2.3.0p0 (2015-12-25 revision 53290) [x86_64-linux]</code> and <code>rspec-3.1</code>.</p>