From e4d9e643ba050eb4a14c27d980cf27722228bac1 Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Wed, 18 Dec 2024 10:33:23 -0500 Subject: [PATCH] Remove deprecated single-argument variation of `UnfilterNotificationsWorker` --- app/workers/unfilter_notifications_worker.rb | 21 +++------------- .../unfilter_notifications_worker_spec.rb | 24 +++++++++---------- 2 files changed, 15 insertions(+), 30 deletions(-) diff --git a/app/workers/unfilter_notifications_worker.rb b/app/workers/unfilter_notifications_worker.rb index 53a35ce12c..cb8a46b8f4 100644 --- a/app/workers/unfilter_notifications_worker.rb +++ b/app/workers/unfilter_notifications_worker.rb @@ -4,25 +4,14 @@ class UnfilterNotificationsWorker include Sidekiq::Worker include Redisable - # Earlier versions of the feature passed a `notification_request` ID - # If `to_account_id` is passed, the first argument is an account ID - # TODO for after 4.3.0: drop the single-argument case - def perform(notification_request_or_account_id, from_account_id = nil) - if from_account_id.present? - @notification_request = nil - @from_account = Account.find_by(id: from_account_id) - @recipient = Account.find_by(id: notification_request_or_account_id) - else - @notification_request = NotificationRequest.find_by(id: notification_request_or_account_id) - @from_account = @notification_request&.from_account - @recipient = @notification_request&.account - end + def perform(account_id, from_account_id) + @from_account = Account.find_by(id: from_account_id) + @recipient = Account.find_by(id: account_id) return if @from_account.nil? || @recipient.nil? push_to_conversations! unfilter_notifications! - remove_request! decrement_worker_count! end @@ -36,10 +25,6 @@ class UnfilterNotificationsWorker filtered_notifications.in_batches.update_all(filtered: false) end - def remove_request! - @notification_request&.destroy! - end - def filtered_notifications Notification.where(account: @recipient, from_account: @from_account, filtered: true) end diff --git a/spec/workers/unfilter_notifications_worker_spec.rb b/spec/workers/unfilter_notifications_worker_spec.rb index 464a4520ff..2fd130301f 100644 --- a/spec/workers/unfilter_notifications_worker_spec.rb +++ b/spec/workers/unfilter_notifications_worker_spec.rb @@ -5,6 +5,7 @@ require 'rails_helper' RSpec.describe UnfilterNotificationsWorker do let(:recipient) { Fabricate(:account) } let(:sender) { Fabricate(:account) } + let(:worker) { described_class.new } before do # Populate multiple kinds of filtered notifications @@ -67,23 +68,22 @@ RSpec.describe UnfilterNotificationsWorker do end describe '#perform' do - context 'with single argument (prerelease behavior)' do - subject { described_class.new.perform(notification_request.id) } - - let(:notification_request) { Fabricate(:notification_request, from_account: sender, account: recipient) } + context 'with recipient and sender' do + subject { worker.perform(recipient.id, sender.id) } it_behaves_like 'shared behavior' - - it 'destroys the notification request' do - expect { subject } - .to change { NotificationRequest.exists?(notification_request.id) }.to(false) - end end - context 'with two arguments' do - subject { described_class.new.perform(recipient.id, sender.id) } + context 'with missing records' do + it 'runs without error for missing sender' do + expect { worker.perform(recipient.id, nil) } + .to_not raise_error + end - it_behaves_like 'shared behavior' + it 'runs without error for missing recipient' do + expect { worker.perform(nil, sender.id) } + .to_not raise_error + end end end end