From 3c8a705866b62e069536de41939e2c3fbcfd8426 Mon Sep 17 00:00:00 2001 From: Meir Taffel Date: Mon, 22 Jan 2018 10:23:36 +0000 Subject: [PATCH] Delete user if email isn't confirmable --- app/workers/email_confirmation_worker.rb | 2 ++ spec/workers/email_confirmation_worker_spec.rb | 7 +++++++ 2 files changed, 9 insertions(+) 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..7944d0f0e9 100644 --- a/spec/workers/email_confirmation_worker_spec.rb +++ b/spec/workers/email_confirmation_worker_spec.rb @@ -8,4 +8,11 @@ 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(email: 'notaemail@fakeonotreal.blorgh') + EmailConfirmationWorker.new.perform(user.id) + expect(User.count).to be_zero + end end