[fix #2067] Resend confirmation mail if the user is not confirmed
This commit is contained in:
parent
90b1887702
commit
c3610fc96e
2 changed files with 28 additions and 6 deletions
|
@ -17,7 +17,11 @@ class Users::RegistrationsController < Devise::RegistrationsController
|
|||
def create
|
||||
user = User.find_by(email: params[:user][:email])
|
||||
if user.present?
|
||||
if user.confirmed?
|
||||
UserMailer.new_account_warning(user).deliver_later
|
||||
else
|
||||
user.resend_confirmation_instructions
|
||||
end
|
||||
flash.notice = t('devise.registrations.signed_up_but_unconfirmed')
|
||||
redirect_to root_path
|
||||
else
|
||||
|
|
|
@ -34,16 +34,34 @@ describe Users::RegistrationsController, type: :controller do
|
|||
end
|
||||
|
||||
context 'when the user already exists' do
|
||||
let!(:existing_user) { create(:user, email: email, password: password) }
|
||||
let!(:existing_user) { create(:user, email: email, password: password, confirmed_at: confirmed_at) }
|
||||
|
||||
before do
|
||||
allow(UserMailer).to receive(:new_account_warning).and_return(double(deliver_later: 'deliver'))
|
||||
subject
|
||||
end
|
||||
|
||||
context 'and the user is confirmed' do
|
||||
let(:confirmed_at) { DateTime.now }
|
||||
|
||||
before { subject }
|
||||
|
||||
it { expect(response).to redirect_to(root_path) }
|
||||
it { expect(flash.notice).to eq(I18n.t('devise.registrations.signed_up_but_unconfirmed')) }
|
||||
it { expect(UserMailer).to have_received(:new_account_warning) }
|
||||
end
|
||||
|
||||
context 'and the user is not confirmed' do
|
||||
let(:confirmed_at) { nil }
|
||||
|
||||
before do
|
||||
expect_any_instance_of(User).to receive(:resend_confirmation_instructions)
|
||||
subject
|
||||
end
|
||||
|
||||
it { expect(response).to redirect_to(root_path) }
|
||||
it { expect(flash.notice).to eq(I18n.t('devise.registrations.signed_up_but_unconfirmed')) }
|
||||
it { expect(UserMailer).not_to have_received(:new_account_warning) }
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue