From 8261ab74d7ee29e3d53c9567d2d41091ba925bbd Mon Sep 17 00:00:00 2001 From: Alex Date: Tue, 4 Feb 2020 17:03:08 -0800 Subject: [PATCH] Remove Notifications::ModerationNotificationJob (#5905) [deploy] --- .../moderation_notification_job.rb | 18 ------ .../moderation_notification_job_spec.rb | 60 ------------------- 2 files changed, 78 deletions(-) delete mode 100644 app/jobs/notifications/moderation_notification_job.rb delete mode 100644 spec/jobs/notifications/moderation_notification_job_spec.rb diff --git a/app/jobs/notifications/moderation_notification_job.rb b/app/jobs/notifications/moderation_notification_job.rb deleted file mode 100644 index 7d6c50e9a..000000000 --- a/app/jobs/notifications/moderation_notification_job.rb +++ /dev/null @@ -1,18 +0,0 @@ -module Notifications - class ModerationNotificationJob < ApplicationJob - queue_as :send_moderation_notification - - def perform(notifiable_id, service = Notifications::Moderation::Send) - random_moderators = Notifications::Moderation.available_moderators.order(Arel.sql("RANDOM()")).first(2) - return unless random_moderators.any? - - # notifiable is currently only comment - notifiable = Comment.find_by(id: notifiable_id) - return unless notifiable - - random_moderators.each do |mod| - service.call(mod, notifiable) - end - end - end -end diff --git a/spec/jobs/notifications/moderation_notification_job_spec.rb b/spec/jobs/notifications/moderation_notification_job_spec.rb deleted file mode 100644 index 7421eb378..000000000 --- a/spec/jobs/notifications/moderation_notification_job_spec.rb +++ /dev/null @@ -1,60 +0,0 @@ -require "rails_helper" - -RSpec.describe Notifications::ModerationNotificationJob do - include_examples "#enqueues_job", "send_moderation_notification", 458 - - describe "#perform_now" do - let(:id) { rand(1000) } - let(:moderation_notification_service) { double } - let(:comment) do - comment = double - allow(Comment).to receive(:find_by).and_return(comment) - end - let(:mod) do - last_moderation_time = Time.zone.now - Notifications::Moderation::MODERATORS_AVAILABILITY_DELAY - 2.hours - create(:user, :trusted, last_moderation_notification: last_moderation_time) - end - - before do - allow(moderation_notification_service).to receive(:call) - end - - describe "When available moderator(s) + comment" do - it "calls the service" do - mod - comment - check_received_call - end - end - - describe "When no available moderator" do - it "does not call the service" do - comment - check_non_received_call - end - end - - describe "When no valid comment" do - it "does not call the service" do - mod - check_non_received_call - end - end - - describe "When no valid comment + no moderator" do - it "does not call the service" do - check_non_received_call - end - end - - def check_received_call - described_class.perform_now(id, moderation_notification_service) - expect(moderation_notification_service).to have_received(:call) - end - - def check_non_received_call - described_class.perform_now(id, moderation_notification_service) - expect(moderation_notification_service).not_to have_received(:call) - end - end -end