Module: Warden::Test::Helpers

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

Overview

A collection of test helpers for testing full stack rack applications using Warden These provide the ability to login and logout on any given request Note: During the teardown phase of your specs you should include: Warden.test_reset!

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(_base) ⇒ Object



10
11
12
# File 'lib/warden/test/helpers.rb', line 10

def self.included(_base)
  ::Warden.test_mode!
end

Instance Method Details

#login_as(user, opts = {}) ⇒ Object

A helper method that will perform a login of a user in warden for the next request. Provide it the same options as you would to Warden::Proxy#set_user

See Also:



18
19
20
21
22
23
# File 'lib/warden/test/helpers.rb', line 18

def (user, opts = {})
  Warden.on_next_request do |proxy|
    opts[:event] ||= :authentication
    proxy.set_user(user, opts)
  end
end

#logout(*scopes) ⇒ Object

Logs out a user from the session. Without arguments, all users will be logged out Provide a list of scopes to only log out users with that scope.

See Also:



30
31
32
33
34
# File 'lib/warden/test/helpers.rb', line 30

def logout(*scopes)
  Warden.on_next_request do |proxy|
    proxy.logout(*scopes)
  end
end