Don't try to subscribe users without emails (#14244)

This commit is contained in:
Jamie Gaskins 2021-07-15 10:34:23 -04:00 committed by GitHub
parent e25e197366
commit 355881f744
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 1 deletions

View file

@ -6,7 +6,7 @@ module Users
def perform(user_id)
user = User.find_by(id: user_id)
Mailchimp::Bot.new(user).upsert if user
Mailchimp::Bot.new(user).upsert if user&.email
end
end
end

View file

@ -16,5 +16,16 @@ RSpec.describe Users::SubscribeToMailchimpNewsletterWorker, type: :worker do
expect(mailchimp_bot).to have_received(:upsert)
end
it "does not subscribe the user if they don't have an email" do
mailchimp_bot = double
allow(Mailchimp::Bot).to receive(:new).and_return(mailchimp_bot)
allow(mailchimp_bot).to receive(:upsert)
user.update! email: nil
worker.perform(user.id)
expect(mailchimp_bot).not_to have_received(:upsert)
end
end
end