Auto log in as test user in development mode

I want to test some logged-in stuff, but the whole openneo_id app is a mess to integrate with (and I want to eliminate it down the line anyway), so here's a simple hacky thing that just gets you into a test user for development!
This commit is contained in:
Matchu 2023-07-29 10:39:07 -07:00
parent 39a722600c
commit 1ffcb59f4a

View file

@ -8,6 +8,7 @@ class ApplicationController < ActionController::Base
helper_method :can_use_image_mode?, :user_is? helper_method :can_use_image_mode?, :user_is?
before_filter :set_locale before_filter :set_locale
before_filter :login_as_test_user if Rails.env.development?
def authenticate_user! # too lazy to change references to login_path def authenticate_user! # too lazy to change references to login_path
redirect_to(login_path) unless user_signed_in? redirect_to(login_path) unless user_signed_in?
@ -66,5 +67,10 @@ class ApplicationController < ActionController::Base
def valid_locale?(locale) def valid_locale?(locale)
locale && I18n.usable_locales.include?(locale.to_sym) locale && I18n.usable_locales.include?(locale.to_sym)
end end
def login_as_test_user
test_user = User.find_by_name('test')
sign_in(:user, test_user, bypass: true)
end
end end