diff --git a/app/jobs/regular/invite_email.rb b/app/jobs/regular/invite_email.rb index f373134a2bd..09c2dd0dba8 100644 --- a/app/jobs/regular/invite_email.rb +++ b/app/jobs/regular/invite_email.rb @@ -9,6 +9,8 @@ module Jobs raise Discourse::InvalidParameters.new(:invite_id) unless args[:invite_id].present? invite = Invite.find_by(id: args[:invite_id]) + return unless invite.present? + message = InviteMailer.send_invite(invite) Email::Sender.new(message, :invite).send end diff --git a/spec/jobs/invite_email_spec.rb b/spec/jobs/invite_email_spec.rb index 184fd60b468..9d31a761da2 100644 --- a/spec/jobs/invite_email_spec.rb +++ b/spec/jobs/invite_email_spec.rb @@ -20,6 +20,11 @@ describe Jobs::InviteEmail do Jobs::InviteEmail.new.execute(invite_id: invite.id) end + it "aborts without error when the invite doesn't exist anymore" do + invite.destroy + InviteMailer.expects(:send_invite).never + Jobs::InviteEmail.new.execute(invite_id: invite.id) + end end end