module Warden::Test::Helpers

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!

Public Class Methods

included(base) click to toggle source
# File lib/warden/test/helpers.rb, line 8
def self.included(base)
  ::Warden.test_mode!
end

Public Instance Methods

login_as(user, opts = {}) click to toggle source

A helper method that will peform 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 Warden::Proxy#set_user @api public

# File lib/warden/test/helpers.rb, line 16
def login_as(user, opts = {})
  Warden.on_next_request do |proxy|
    opts[:event] ||= :authentication
    proxy.set_user(user, opts)
  end
end
logout(*scopes) click to toggle source

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 Warden::Proxy#logout @api public

# File lib/warden/test/helpers.rb, line 28
def logout(*scopes)
  Warden.on_next_request do |proxy|
    proxy.logout(*scopes)
  end
end