Last active
August 10, 2023 07:53
-
-
Save markedmondson/84ccaf8fe569d94702bdb0fd95f67856 to your computer and use it in GitHub Desktop.
Faster system test sign in
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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