post_process_media_worker_spec.rb 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. describe PostProcessMediaWorker, :paperclip_processing do
  4. let(:worker) { described_class.new }
  5. describe '#perform' do
  6. let(:media_attachment) { Fabricate(:media_attachment) }
  7. it 'reprocesses and updates the media attachment' do
  8. worker.perform(media_attachment.id)
  9. expect(media_attachment.processing).to eq('complete')
  10. end
  11. it 'returns true for non-existent record' do
  12. result = worker.perform(123_123_123)
  13. expect(result).to be(true)
  14. end
  15. context 'when sidekiq retries are exhausted' do
  16. it 'sets state to failed' do
  17. described_class.within_sidekiq_retries_exhausted_block({ 'args' => [media_attachment.id] }) do
  18. worker.perform(media_attachment.id)
  19. end
  20. expect(media_attachment.reload.processing).to eq('failed')
  21. end
  22. it 'returns true for non-existent record' do
  23. described_class.within_sidekiq_retries_exhausted_block({ 'args' => [123_123_123] }) do
  24. expect(worker.perform(123_123_123)).to be(true)
  25. end
  26. end
  27. end
  28. end
  29. end