class Rack::BackDoor

Force a User to be authenticated ala robots.thoughtbot.com/post/37907699673/faster-tests-sign-in-through-the-back-door

Attributes

app[R]
env[R]
session_key[R]
sign_in[R]
url_parameter[R]

Public Class Methods

new(app, options = {}, &block) click to toggle source
# File lib/rack/back_door.rb, line 6
def initialize(app, options = {}, &block)
  @app = app
  @url_parameter = options.fetch(:url_parameter, "as")
  @session_key = options.fetch(:session_key, "user_id")

  if block
    @sign_in = Proc.new(&block)
  end
end

Public Instance Methods

call(env) click to toggle source
# File lib/rack/back_door.rb, line 16
def call(env)
  @env = env

  sign_in_through_the_back_door

  app.call(env)
end

Private Instance Methods

query_params() click to toggle source
# File lib/rack/back_door.rb, line 44
def query_params
  Rack::Utils.parse_query(env['QUERY_STRING'])
end
session() click to toggle source
# File lib/rack/back_door.rb, line 40
def session
  env['rack.session'] ||= {}
end
sign_in_through_the_back_door() click to toggle source
# File lib/rack/back_door.rb, line 28
def sign_in_through_the_back_door
  if sign_in
    sign_in.call(env, user_id)
  elsif ! user_id.to_s.empty?
    session[session_key] = user_id
  end
end
user_id() click to toggle source
# File lib/rack/back_door.rb, line 36
def user_id
  query_params[url_parameter]
end