backup_worker_spec.rb 1.1 KB

123456789101112131415161718192021222324252627282930313233343536
  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. describe BackupWorker do
  4. let(:worker) { described_class.new }
  5. let(:service) { instance_double(BackupService, call: true) }
  6. describe '#perform' do
  7. before do
  8. allow(BackupService).to receive(:new).and_return(service)
  9. end
  10. let(:backup) { Fabricate(:backup) }
  11. let!(:other_backup) { Fabricate(:backup, user: backup.user) }
  12. it 'sends the backup to the service and removes other backups', :sidekiq_inline do
  13. expect do
  14. worker.perform(backup.id)
  15. end.to change(UserMailer.deliveries, :size).by(1)
  16. expect(service).to have_received(:call).with(backup)
  17. expect { other_backup.reload }.to raise_error(ActiveRecord::RecordNotFound)
  18. end
  19. context 'when sidekiq retries are exhausted' do
  20. it 'destroys the backup' do
  21. described_class.within_sidekiq_retries_exhausted_block({ 'args' => [backup.id] }) do
  22. worker.perform(backup.id)
  23. end
  24. expect { backup.reload }.to raise_error(ActiveRecord::RecordNotFound)
  25. end
  26. end
  27. end
  28. end