Class: Monban::BackDoor

Inherits:
Object
  • Object
show all
Defined in:
lib/monban/back_door.rb

Overview

Note:

This should only be used for testing purposes

Middleware used in tests to allow users to be signed in directly, without having to load and submit the sign in form. The user should be provided by using the key :as in a hash passed to the path.

Examples:

Using the backdoor in an rspec feature spec

feature "User dashboard" do
  scenario "user visits dashboard" do
    user = create(:user)
    visit dashboard_path(as: user)
    expect(page).to have_css("#dashboard")
  end
end

Since:

  • 0.0.15

Instance Method Summary collapse

Constructor Details

#initialize(app, &block) ⇒ BackDoor

Create the a new BackDoor middleware for test purposes

Since:

  • 0.0.15



19
20
21
22
23
24
25
# File 'lib/monban/back_door.rb', line 19

def initialize(app, &block)
  @app = app

  if block
    @sign_in_block = block
  end
end

Instance Method Details

#call(env) ⇒ Object

Execute the BackDoor middleware signing in the user specified with :as

Since:

  • 0.0.15



28
29
30
31
# File 'lib/monban/back_door.rb', line 28

def call(env)
  (env)
  @app.call(env)
end