Skip to content

Instantly share code, notes, and snippets.

@ianchesal
Forked from mattconnolly/gist:4158961
Last active August 29, 2015 14:13
Show Gist options
  • Save ianchesal/68fd7f9d5c7f1c5ff2e2 to your computer and use it in GitHub Desktop.
Save ianchesal/68fd7f9d5c7f1c5ff2e2 to your computer and use it in GitHub Desktop.
module AuthHelper
def http_login
user = 'username'
pw = 'password'
request.env['HTTP_AUTHORIZATION'] = ActionController::HttpAuthentication::Basic.encode_credentials(user,pw)
end
end
module AuthRequestHelper
#
# pass the @env along with your request, eg:
#
# GET '/labels', {}, @env
#
def http_login
@env ||= {}
user = 'username'
pw = 'password'
@env['HTTP_AUTHORIZATION'] = ActionController::HttpAuthentication::Basic.encode_credentials(user,pw)
end
end
# then in Rspec support:
RSpec.configure do |config|
config.include AuthRequestHelper, :type => :request
config.include AuthHelper, :type => :controller
end
# request specs need to explicitly pass the @env parameter along, eg:
describe "some request" do
http_login # or put this in a before :all
GET '/path', {}, @env
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment