diff options
| -rw-r--r-- | app/controllers/application_controller.rb | 11 | ||||
| -rw-r--r-- | app/controllers/sessions_controller.rb | 2 | ||||
| -rw-r--r-- | test/system/sessions_test.rb | 13 |
3 files changed, 25 insertions, 1 deletions
diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index fbe614c..80d4415 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -19,4 +19,15 @@ class ApplicationController < ActionController::Base def set_searches @searches = Search.order(:name) end + + # Redirect to the search that was last used by the current user. + def redirect_to_search! + search_id = current_user&.last_search_id + + if search_id + redirect_to search_path(search_id) + else + redirect_to root_url + end + end end diff --git a/app/controllers/sessions_controller.rb b/app/controllers/sessions_controller.rb index b79e3dd..d80e38c 100644 --- a/app/controllers/sessions_controller.rb +++ b/app/controllers/sessions_controller.rb @@ -13,7 +13,7 @@ class SessionsController < ApplicationController user = User.find_by(username: params[:username]) if user&.authenticate(params[:password]) session[:user_id] = user.id - redirect_to root_url + redirect_to_search! else redirect_to root_url, alert: t('sessions.wrong-credentials') end diff --git a/test/system/sessions_test.rb b/test/system/sessions_test.rb index 2d01eef..6722de0 100644 --- a/test/system/sessions_test.rb +++ b/test/system/sessions_test.rb @@ -24,4 +24,17 @@ class SessionsTest < ApplicationSystemTestCase assert_text I18n.t('sessions.title') end + + test 'keeps the last search on sign in' do + sign_in! + + assert_equal current_url, root_url + + click_on searches(:search1).name + click_on I18n.t('sessions.sign-out') + + sign_in! + + assert_equal current_url, search_url(searches(:search1)) + end end |
