[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
|
def create
|
||||||
user = User.find_by(email: params[:user][:email])
|
user = User.find_by(email: params[:user][:email])
|
||||||
if user.present?
|
if user.present?
|
||||||
|
if user.confirmed?
|
||||||
UserMailer.new_account_warning(user).deliver_later
|
UserMailer.new_account_warning(user).deliver_later
|
||||||
|
else
|
||||||
|
user.resend_confirmation_instructions
|
||||||
|
end
|
||||||
flash.notice = t('devise.registrations.signed_up_but_unconfirmed')
|
flash.notice = t('devise.registrations.signed_up_but_unconfirmed')
|
||||||
redirect_to root_path
|
redirect_to root_path
|
||||||
else
|
else
|
||||||
|
|
|
@ -34,16 +34,34 @@ describe Users::RegistrationsController, type: :controller do
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'when the user already exists' do
|
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
|
before do
|
||||||
allow(UserMailer).to receive(:new_account_warning).and_return(double(deliver_later: 'deliver'))
|
allow(UserMailer).to receive(:new_account_warning).and_return(double(deliver_later: 'deliver'))
|
||||||
subject
|
|
||||||
end
|
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(response).to redirect_to(root_path) }
|
||||||
it { expect(flash.notice).to eq(I18n.t('devise.registrations.signed_up_but_unconfirmed')) }
|
it { expect(flash.notice).to eq(I18n.t('devise.registrations.signed_up_but_unconfirmed')) }
|
||||||
it { expect(UserMailer).to have_received(:new_account_warning) }
|
it { expect(UserMailer).to have_received(:new_account_warning) }
|
||||||
end
|
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
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue