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
-
#login_as(user, opts = {}) ⇒ Object
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.
-
#logout(*scopes) ⇒ Object
Logs out a user from the session.
Class Method Details
.included(base) ⇒ Object
9 10 11 |
# File 'lib/warden/test/helpers.rb', line 9 def self.included(base) ::Warden.test_mode! end |
Instance Method Details
#login_as(user, opts = {}) ⇒ Object
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
17 18 19 20 21 22 |
# File 'lib/warden/test/helpers.rb', line 17 def login_as(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.
29 30 31 32 33 |
# File 'lib/warden/test/helpers.rb', line 29 def logout(*scopes) Warden.on_next_request do |proxy| proxy.logout(*scopes) end end |