Skip to content

Instantly share code, notes, and snippets.

@mattconnolly
Created November 28, 2012 04:04

Revisions

  1. mattconnolly revised this gist Nov 28, 2012. 1 changed file with 7 additions and 0 deletions.
    7 changes: 7 additions & 0 deletions gistfile1.rb
    Original file line number Diff line number Diff line change
    @@ -27,3 +27,10 @@ def http_login
    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
  2. mattconnolly created this gist Nov 28, 2012.
    29 changes: 29 additions & 0 deletions gistfile1.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,29 @@
    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