Don't try to subscribe users without emails (#14244)
This commit is contained in:
parent
e25e197366
commit
355881f744
2 changed files with 12 additions and 1 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue