Skip to content

Instantly share code, notes, and snippets.

@markedmondson
Last active August 10, 2023 07:53
Show Gist options
  • Save markedmondson/84ccaf8fe569d94702bdb0fd95f67856 to your computer and use it in GitHub Desktop.
Save markedmondson/84ccaf8fe569d94702bdb0fd95f67856 to your computer and use it in GitHub Desktop.
Faster system test sign in
module SessionHelper
extend ActiveSupport::Concern
class ::SessionsBypassController < ActionController::Base
def show
session[:user_id] = params[:user_id]
session[:team_id] = params[:team_id]
session[:tenant] = Apartment::Tenant.current
render plain: 'ok'
end
end
included do
Rails.application.routes.disable_clear_and_finalize = true
Rails.application.routes.draw do
get '/bypass-sessions' => 'sessions_bypass#show'
end
end
end
module LoginTestHelper
include SessionHelper
def login(user)
visit bypass_sessions_path(user_id: user.id)
end
end
class SomeTest < ActionDispatch::SystemTestCase
include LoginTestHelper
test 'login' do
login(users(:admin))
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment