From 2fa8792a35d34968004877554d0f1f8d17303323 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Tue, 11 Aug 2020 17:54:46 +0200 Subject: [PATCH] Redirect users in homepage to homepage after login For reasons I'm not sure about, the homepage (and the welcome pages) were an exception in our "redirect users to the same page they were" policy. I'm not sure about the welcome pages (no test was present indicating they should behave in a special way), but in the case of the home page, it was a bit annoying to be redirected to a different place after signing in. --- app/controllers/application_controller.rb | 2 +- spec/system/sessions_spec.rb | 19 +++++++++++++++++-- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 72f41abb9..60b189f92 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -107,7 +107,7 @@ class ApplicationController < ActionController::Base end def set_return_url - if !devise_controller? && controller_name != "welcome" && is_navigational_format? + if !devise_controller? && is_navigational_format? store_location_for(:user, request.fullpath) end end diff --git a/spec/system/sessions_spec.rb b/spec/system/sessions_spec.rb index 470fe358b..31713e3c4 100644 --- a/spec/system/sessions_spec.rb +++ b/spec/system/sessions_spec.rb @@ -6,8 +6,10 @@ describe "Sessions" do debate = create(:debate) visit debate_path(debate) - - login_through_form_as(user) + click_link "Sign in" + fill_in "user_login", with: user.email + fill_in "user_password", with: user.password + click_button "Enter" expect(page).to have_content("You have been signed in successfully") expect(page).to have_current_path(debate_path(debate)) @@ -30,4 +32,17 @@ describe "Sessions" do expect(page).to have_current_path budget_investments_path(heading.budget, heading_id: "outskirts") end + + scenario "Sign in redirects to the homepage if the user was there" do + user = create(:user, :level_two) + + visit debates_path + visit "/" + click_link "Sign in" + fill_in "user_login", with: user.email + fill_in "user_password", with: user.password + click_button "Enter" + + expect(page).to have_current_path "/" + end end