Class: Clearance::BackDoor
- Inherits:
-
Object
- Object
- Clearance::BackDoor
- Defined in:
- lib/clearance/back_door.rb
Overview
Middleware which allows signing in by passing as=USER_ID in a query
parameter. If User#to_param
is overriden you may pass a block to
override the default user lookup behaviour
Designed to eliminate time in integration tests wasted by visiting and submitting the sign in form.
Configuration:
# config/environments/test.rb MyRailsApp::Application.configure do # ... config.middleware.use Clearance::BackDoor # ... end
# or if User#to_param
is overridden (to username
for example):
# config/environments/test.rb MyRailsApp::Application.configure do # ... config.middleware.use Clearance::BackDoor do |username| User.find_by(username: username) end # ... end
Usage:
visit new_feedback_path(as: user)
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, &block) ⇒ BackDoor
constructor
A new instance of BackDoor.
Constructor Details
#initialize(app, &block) ⇒ BackDoor
Returns a new instance of BackDoor.
33 34 35 36 37 38 39 40 |
# File 'lib/clearance/back_door.rb', line 33 def initialize(app, &block) unless environment_is_allowed? raise end @app = app @block = block end |
Instance Method Details
#call(env) ⇒ Object
42 43 44 45 |
# File 'lib/clearance/back_door.rb', line 42 def call(env) sign_in_through_the_back_door(env) @app.call(env) end |