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