From cff393f014dff72beaa8125e8cd8153dd2f841c3 Mon Sep 17 00:00:00 2001 From: Matchu Date: Sat, 29 Jul 2023 10:39:07 -0700 Subject: [PATCH] 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! --- app/controllers/application_controller.rb | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 7484284b..a10967f4 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -8,6 +8,7 @@ class ApplicationController < ActionController::Base helper_method :can_use_image_mode?, :user_is? 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 redirect_to(login_path) unless user_signed_in? @@ -66,5 +67,10 @@ class ApplicationController < ActionController::Base def valid_locale?(locale) locale && I18n.usable_locales.include?(locale.to_sym) end + + def login_as_test_user + test_user = User.find_by_name('test') + sign_in(:user, test_user, bypass: true) + end end