redownload_media_worker_spec.rb 912 B

12345678910111213141516171819202122232425262728293031323334353637
  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. RSpec.describe RedownloadMediaWorker do
  4. let(:worker) { described_class.new }
  5. describe '#perform' do
  6. it 'returns nil for non-existent record' do
  7. result = worker.perform(123_123_123)
  8. expect(result).to be_nil
  9. end
  10. it 'returns nil without a remote_url' do
  11. media_attachment = Fabricate(:media_attachment, remote_url: '')
  12. result = worker.perform(media_attachment.id)
  13. expect(result).to be_nil
  14. end
  15. context 'with a valid remote url' do
  16. let(:url) { 'https://example.host/file.txt' }
  17. before { stub_request(:get, url).to_return(status: 200) }
  18. it 'processes downloads for valid record' do
  19. media_attachment = Fabricate(:media_attachment, remote_url: url)
  20. worker.perform(media_attachment.id)
  21. expect(a_request(:get, url)).to have_been_made
  22. end
  23. end
  24. end
  25. end