module ProxyAuthentication::TestHelpers

Public Class Methods

included(base) click to toggle source
# File lib/proxy_authentication/test_helpers.rb, line 8
def self.included base
  base.class_eval do
    setup :setup_controller_for_warden, :warden if respond_to? :setup
  end
end

Public Instance Methods

sign_in(user) click to toggle source
# File lib/proxy_authentication/test_helpers.rb, line 14
def sign_in user
  warden.instance_variable_get(:@users).delete :default
  warden.session_serializer.store user, :default
end
sign_out() click to toggle source
# File lib/proxy_authentication/test_helpers.rb, line 19
def sign_out
  @controller.instance_variable_set :@current_user, nil
  user = warden.instance_variable_get(:@users).delete :default
  warden.session_serializer.delete :default, user
end

Private Instance Methods

new_warden_proxy() click to toggle source
# File lib/proxy_authentication/test_helpers.rb, line 37
def new_warden_proxy
  manager = Warden::Manager.new nil, &Rails.application.config.middleware.detect { |m| m.name == 'Warden::Manager'}.block
  @request.env['warden'] = Warden::Proxy.new @request.env, manager
end
setup_controller_for_warden() click to toggle source

We need to setup the environment variables and the response in the controller

# File lib/proxy_authentication/test_helpers.rb, line 28
def setup_controller_for_warden
  @request.env['action_controller.instance'] = @controller
end
warden() click to toggle source

Quick access to Warden::Proxy (memoized at setup)

# File lib/proxy_authentication/test_helpers.rb, line 33
def warden
  @warden ||= new_warden_proxy
end