From ff62be04f0c43d0f6f1d4376816d62251ef86cc7 Mon Sep 17 00:00:00 2001 From: baarkerlounger Date: Fri, 20 May 2022 14:54:47 +0100 Subject: [PATCH] Redirect confirmed users to sign in --- .../auth/confirmations_controller.rb | 2 ++ .../auth/confirmations_controller_spec.rb | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/app/controllers/auth/confirmations_controller.rb b/app/controllers/auth/confirmations_controller.rb index 4c8a4746c..c3be85f51 100644 --- a/app/controllers/auth/confirmations_controller.rb +++ b/app/controllers/auth/confirmations_controller.rb @@ -13,6 +13,8 @@ class Auth::ConfirmationsController < Devise::ConfirmationsController end elsif resource.errors.map(&:type).include?(:confirmation_period_expired) render "devise/confirmations/expired" + elsif resource.errors.map(&:type).include?(:already_confirmed) + redirect_to user_session_path else respond_with_navigational(resource.errors, status: :unprocessable_entity) { render :new } end diff --git a/spec/requests/auth/confirmations_controller_spec.rb b/spec/requests/auth/confirmations_controller_spec.rb index 1cecf0447..fe27925b1 100644 --- a/spec/requests/auth/confirmations_controller_spec.rb +++ b/spec/requests/auth/confirmations_controller_spec.rb @@ -43,4 +43,23 @@ RSpec.describe Auth::ConfirmationsController, type: :request do expect(page).to have_content("Your invitation link has expired") end end + + context "when the user has already been confirmed" do + let(:user) { FactoryBot.create(:user, :data_provider, sign_in_count: 0, confirmed_at: Time.zone.now) } + + before do + user.send_confirmation_instructions + get "/account/confirmation?confirmation_token=#{user.confirmation_token}" + end + + it "redirects to the login page" do + follow_redirect! + expect(page).to have_content("Sign in to your account to submit CORE data") + end + + it "does not show an error message" do + follow_redirect! + expect(page).not_to have_selector("#error-summary-title") + end + end end