2019-03-30 03:15:48 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2019-08-29 03:56:52 -04:00
|
|
|
require 'spec_helper'
|
2017-02-22 14:25:06 -05:00
|
|
|
|
|
|
|
describe UploadChecksumWorker do
|
|
|
|
describe '#perform' do
|
2018-01-29 12:57:34 -05:00
|
|
|
subject { described_class.new }
|
|
|
|
|
|
|
|
context 'without a valid record' do
|
|
|
|
it 'rescues ActiveRecord::RecordNotFound' do
|
2020-04-01 11:07:45 -04:00
|
|
|
expect { subject.perform(non_existing_record_id) }.not_to raise_error
|
2018-01-29 12:57:34 -05:00
|
|
|
end
|
2017-02-22 14:25:06 -05:00
|
|
|
end
|
|
|
|
|
2018-01-29 12:57:34 -05:00
|
|
|
context 'with a valid record' do
|
|
|
|
let(:upload) { create(:user, :with_avatar).avatar.upload }
|
|
|
|
|
|
|
|
before do
|
|
|
|
expect(Upload).to receive(:find).and_return(upload)
|
|
|
|
allow(upload).to receive(:foreground_checksumable?).and_return(false)
|
|
|
|
end
|
2017-02-22 14:25:06 -05:00
|
|
|
|
2018-01-29 12:57:34 -05:00
|
|
|
it 'calls calculate_checksum!' do
|
|
|
|
expect(upload).to receive(:calculate_checksum!)
|
|
|
|
subject.perform(upload.id)
|
|
|
|
end
|
2017-02-22 14:25:06 -05:00
|
|
|
|
2018-01-29 12:57:34 -05:00
|
|
|
it 'calls save!' do
|
|
|
|
expect(upload).to receive(:save!)
|
|
|
|
subject.perform(upload.id)
|
|
|
|
end
|
2017-02-22 14:25:06 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|