Module: Warden::Test::ControllerHelpers

Defined in:
lib/warden/test/controller_helpers.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



9
10
11
12
13
# File 'lib/warden/test/controller_helpers.rb', line 9

def self.included(base)
  base.class_eval do
    setup :setup_controller_for_warden, :warden if respond_to?(:setup)
  end
end

Instance Method Details

#processObject

Override process to consider warden.



16
17
18
19
# File 'lib/warden/test/controller_helpers.rb', line 16

def process(*)
  # Make sure we always return @response, a la ActionController::TestCase::Behavior#process, even if warden interrupts
  _catch_warden {super} || @response
end

#setup_controller_for_wardenObject

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



22
23
24
# File 'lib/warden/test/controller_helpers.rb', line 22

def setup_controller_for_warden
  @request.env['action_controller.instance'] = @controller
end

#wardenObject

Quick access to Warden::Proxy.



27
28
29
30
31
32
# File 'lib/warden/test/controller_helpers.rb', line 27

def warden
  @warden ||= begin
    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
end