Last active
August 29, 2015 14:04
-
-
Save emarthinsen/2e1c251d929511551529 to your computer and use it in GitHub Desktop.
Trouble adding request headers in controller spec
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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