This commit is contained in:
kara Diaby 2021-11-04 12:01:16 +01:00
parent 9ee9389ba1
commit 1b27ab5aff

View file

@ -7,15 +7,26 @@ describe VirusScannerJob, type: :job do
VirusScannerJob.perform_now(blob)
end
context "when the blob is not analyzed yet" do
it "retries the job later" do
expect { subject }.to have_enqueued_job(VirusScannerJob)
context "when the virus scan launch before rails analyze" do
before do
allow(ClamavService).to receive(:safe_file?).and_return(true)
subject
blob.analyze
end
it { expect(blob.virus_scanner.safe?).to be_truthy }
it { expect(blob.analyzed?).to be_truthy }
it { expect(blob.lock_version).to eq(2) }
end
context "when the blob has been analyzed" do
context "should raise ActiveRecord::StaleObjectError" do
let(:blob_2) { ActiveStorage::Blob.find(blob.id) }
before do
blob.analyze
blob_2.metadata[:virus_scan_result] = "infected"
blob.metadata[:virus_scan_result] = "safe"
blob.save
end
it { expect { blob_2.save }.to raise_error(ActiveRecord::StaleObjectError) }
end
context "when there is an integrity error" do
@ -60,4 +71,3 @@ describe VirusScannerJob, type: :job do
end
end
end
end