2023-11-16 09:36:59 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'rails_helper'
|
|
|
|
|
2024-09-04 01:12:25 -04:00
|
|
|
RSpec.describe BackupWorker do
|
2023-11-16 09:36:59 -05:00
|
|
|
let(:worker) { described_class.new }
|
|
|
|
let(:service) { instance_double(BackupService, call: true) }
|
|
|
|
|
|
|
|
describe '#perform' do
|
|
|
|
before do
|
|
|
|
allow(BackupService).to receive(:new).and_return(service)
|
|
|
|
end
|
|
|
|
|
|
|
|
let(:backup) { Fabricate(:backup) }
|
|
|
|
let!(:other_backup) { Fabricate(:backup, user: backup.user) }
|
|
|
|
|
2024-07-08 12:01:08 -04:00
|
|
|
it 'sends the backup to the service and removes other backups', :inline_jobs do
|
2024-02-19 10:57:47 -05:00
|
|
|
emails = capture_emails { worker.perform(backup.id) }
|
2023-11-16 09:36:59 -05:00
|
|
|
|
|
|
|
expect(service).to have_received(:call).with(backup)
|
|
|
|
expect { other_backup.reload }.to raise_error(ActiveRecord::RecordNotFound)
|
2024-02-19 10:57:47 -05:00
|
|
|
expect(emails.size)
|
|
|
|
.to eq(1)
|
|
|
|
expect(emails.first)
|
|
|
|
.to have_attributes(
|
|
|
|
to: contain_exactly(backup.user.email),
|
|
|
|
subject: I18n.t('user_mailer.backup_ready.subject')
|
|
|
|
)
|
2023-11-16 09:36:59 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'when sidekiq retries are exhausted' do
|
|
|
|
it 'destroys the backup' do
|
|
|
|
described_class.within_sidekiq_retries_exhausted_block({ 'args' => [backup.id] }) do
|
|
|
|
worker.perform(backup.id)
|
|
|
|
end
|
|
|
|
|
|
|
|
expect { backup.reload }.to raise_error(ActiveRecord::RecordNotFound)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|