Skip to content

Commit

Permalink
Merge pull request #756 from uktrade/develop
Browse files Browse the repository at this point in the history
Release 13/11
  • Loading branch information
rafa-garcia authored Nov 13, 2020
2 parents 86552ca + 95e3734 commit 7e32582
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ class DeleteOldSubscriptionNotificationsWorker
sidekiq_options retry: false

def perform
SubscriptionNotification.where('created_at > ?', 30.days.ago).destroy_all
SubscriptionNotification.where('created_at < ?', 1.month.ago).destroy_all
end
end
18 changes: 8 additions & 10 deletions spec/workers/delete_old_subscription_notifications_worker_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,16 @@

RSpec.describe DeleteOldSubscriptionNotificationsWorker do

subject { DeleteOldSubscriptionNotificationsWorker.new }

it 'deletes subscription notifications older than 30 days' do
SubscriptionNotification.destroy_all
SubscriptionNotification.delete_all
create(:subscription_notification)
old_notification = create(:subscription_notification)
old_notification.update_columns(
updated_at: 2.months.ago,
created_at: 2.months.ago
)
travel_to(2.months.ago) { create(:subscription_notification) }

expect(SubscriptionNotification.count).to eq(2)
DeleteOldSubscriptionNotificationsWorker.new.perform
expect(SubscriptionNotification.count).to eq(1)
expect { subject.perform }
.to change { SubscriptionNotification.count }.from(2).to(1)
expect(SubscriptionNotification.where('created_at < ?', 1.month.ago))
.to be_empty
end

end

0 comments on commit 7e32582

Please sign in to comment.