forked from forem/forem
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move BadgeAchievements::SendEmailNotificationWorker to Sidekiq (forem…
…#5779) [deploy]
- Loading branch information
1 parent
ba139f5
commit 783da4b
Showing
4 changed files
with
60 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
app/workers/badge_achievements/send_email_notification_worker.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
module BadgeAchievements | ||
class SendEmailNotificationWorker | ||
include Sidekiq::Worker | ||
|
||
sidekiq_options queue: :low_priority, retry: 10 | ||
|
||
def perform(badge_achievement_id) | ||
badge_achievement = BadgeAchievement.find_by(id: badge_achievement_id) | ||
return unless badge_achievement | ||
|
||
NotifyMailer.new_badge_email(badge_achievement).deliver_now | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
spec/workers/badge_achievements/send_email_notification_worker_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
require "rails_helper" | ||
|
||
RSpec.describe BadgeAchievements::SendEmailNotificationWorker, type: :worker do | ||
let(:worker) { subject } | ||
|
||
# passing in a random badge_achievement_id argument since the worker itself won't be executed | ||
include_examples "#enqueues_on_correct_queue", "low_priority", [456] | ||
|
||
describe "#perform_now" do | ||
context "with badge achievement" do | ||
let_it_be(:badge_achievement) { double } | ||
|
||
before do | ||
allow(BadgeAchievement).to receive(:find_by).with(id: 1).and_return(badge_achievement) | ||
end | ||
|
||
it "sends badge email" do | ||
mailer = double | ||
allow(mailer).to receive(:deliver_now) | ||
allow(NotifyMailer).to receive(:new_badge_email).with(badge_achievement).and_return(mailer) | ||
|
||
worker.perform(1) | ||
|
||
expect(NotifyMailer).to have_received(:new_badge_email).with(badge_achievement) | ||
expect(mailer).to have_received(:deliver_now) | ||
end | ||
end | ||
|
||
context "without badge achievement" do | ||
it "does not error" do | ||
expect { worker.perform(nil) }.not_to raise_error | ||
end | ||
|
||
it "does not call NotifyMailer" do | ||
allow(NotifyMailer).to receive(:new_badge_email) | ||
|
||
worker.perform(nil) | ||
|
||
expect(NotifyMailer).not_to have_received(:new_badge_email) | ||
end | ||
end | ||
end | ||
end |