Browse Source

Redirect confirmed users to sign in

pull/619/head
baarkerlounger 3 years ago
parent
commit
19b80cdd71
  1. 2
      app/controllers/auth/confirmations_controller.rb
  2. 19
      spec/requests/auth/confirmations_controller_spec.rb

2
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

19
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

Loading…
Cancel
Save