Class: Devise::TestHelpers::TestWarden

Inherits:
Warden::Proxy
  • Object
show all
Defined in:
lib/devise/test_helpers.rb

Overview

This is a Warden::Proxy customized for functional tests. It’s meant to some of Warden::Manager responsibilities, as retrieving configuration options and calling the FailureApp.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(controller) ⇒ TestWarden

Returns a new instance of TestWarden.



15
16
17
18
19
20
21
# File 'lib/devise/test_helpers.rb', line 15

def initialize(controller)
  @controller = controller
  manager = Warden::Manager.new(nil) do |config|
    config.merge! Devise.warden_config
  end
  super(controller.request.env, manager)
end

Instance Attribute Details

#controllerObject (readonly)

:nodoc:



13
14
15
# File 'lib/devise/test_helpers.rb', line 13

def controller
  @controller
end

Instance Method Details

#authenticate!(*args) ⇒ Object



23
24
25
# File 'lib/devise/test_helpers.rb', line 23

def authenticate!(*args)
  catch_with_redirect { super }
end

#catch_with_redirect(&block) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/devise/test_helpers.rb', line 31

def catch_with_redirect(&block)
  result = catch(:warden, &block)

  if result.is_a?(Hash) && !custom_failure? && !@controller.send(:performed?)
    result[:action] ||= :unauthenticated

    env = @controller.request.env
    env["PATH_INFO"] = "/#{result[:action]}"
    env["warden.options"] = result
    Warden::Manager._before_failure.each{ |hook| hook.call(env, result) }

    status, headers, body = Devise::FailureApp.call(env).to_a
    @controller.send :render, :status => status, :text => body,
      :content_type => headers["Content-Type"], :location => headers["Location"]

    nil
  else
    result
  end
end

#user(*args) ⇒ Object



27
28
29
# File 'lib/devise/test_helpers.rb', line 27

def user(*args)
  catch_with_redirect { super }
end