Skip to content

Instantly share code, notes, and snippets.

@emarthinsen
Last active August 29, 2015 14:04
Show Gist options
  • Save emarthinsen/2e1c251d929511551529 to your computer and use it in GitHub Desktop.
Save emarthinsen/2e1c251d929511551529 to your computer and use it in GitHub Desktop.
Trouble adding request headers in controller spec
class ApiController < ApplicationController
def index
# request.headers always equals {}
if request.headers['Authorization'] == 'HELLO'
render text: 'SUCCESS', status: :ok
else
render text: 'FAILURE', status: :unauthorized
end
end
require 'spec_helper'
describe ApiController do
render_views
it 'should pass the authorization header' do
request.headers['Authorization'] = 'HELLO'
get :index, { format: :json }
expect(response.status).to eq(200)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment