diff --git a/app/workers/email_confirmation_worker.rb b/app/workers/email_confirmation_worker.rb index 9ec022ef5d..996056a968 100644 --- a/app/workers/email_confirmation_worker.rb +++ b/app/workers/email_confirmation_worker.rb @@ -6,5 +6,7 @@ class EmailConfirmationWorker def perform(user_id) user = User.find(user_id) CustomerMailer.confirmation_email(user).deliver_now + rescue Net::SMTPSyntaxError + user.destroy end end diff --git a/spec/workers/email_confirmation_worker_spec.rb b/spec/workers/email_confirmation_worker_spec.rb index f17bb0a973..f60e366dfa 100644 --- a/spec/workers/email_confirmation_worker_spec.rb +++ b/spec/workers/email_confirmation_worker_spec.rb @@ -8,4 +8,12 @@ EmailConfirmationWorker.new.perform(user.id) expect(ActionMailer::Base.deliveries.empty?).to be_falsey end + + it 'deletes user if email is invalid' do + user = FactoryGirl.create(:user) + user.update_attribute(email: 'notaemail@fakeonotreal.blorgh') + EmailConfirmationWorker.new.perform(user.id) + puts ActionMailer::Base.deliveries.inspect + expect(User.count).to be_zero + end end