Use enum to the fullest with VirusScan.statuses

This commit is contained in:
gregoirenovel 2018-08-28 09:53:19 +02:00
parent 7efa64a091
commit 606b56033a
3 changed files with 6 additions and 6 deletions

View file

@ -9,9 +9,9 @@ class AntiVirusJob < ApplicationJob
if @blob.present?
download_blob_to_tempfile do |file|
if ClamavService.safe_file?(file.path)
status = "safe"
status = VirusScan.statuses.fetch(:safe)
else
status = "infected"
status = VirusScan.statuses.fetch(:infected)
end
virus_scan.update(scanned_at: Time.now, status: status)
end

View file

@ -54,7 +54,7 @@ class Champs::PieceJustificativeChamp < Champ
if self.piece_justificative_file&.attachment&.blob.present?
VirusScan.where(champ: self).where.not(blob_key: self.piece_justificative_file.blob.key).delete_all
VirusScan.find_or_create_by!(champ: self, blob_key: self.piece_justificative_file.blob.key) do |virus_scan|
virus_scan.status = "pending"
virus_scan.status = VirusScan.statuses.fetch(:pending)
end
end
end

View file

@ -4,7 +4,7 @@ RSpec.describe AntiVirusJob, type: :job do
champ.piece_justificative_file.attach(io: StringIO.new("toto"), filename: "toto.txt", content_type: "text/plain")
champ
end
let(:virus_scan) { create(:virus_scan, status: "pending", champ: champ, blob_key: champ.piece_justificative_file.blob.key) }
let(:virus_scan) { create(:virus_scan, status: VirusScan.statuses.fetch(:pending), champ: champ, blob_key: champ.piece_justificative_file.blob.key) }
subject { AntiVirusJob.new.perform(virus_scan) }
@ -16,7 +16,7 @@ RSpec.describe AntiVirusJob, type: :job do
subject
end
it { expect(virus_scan.reload.status).to eq("safe") }
it { expect(virus_scan.reload.status).to eq(VirusScan.statuses.fetch(:safe)) }
end
context "when a virus is found" do
@ -27,6 +27,6 @@ RSpec.describe AntiVirusJob, type: :job do
subject
end
it { expect(virus_scan.reload.status).to eq("infected") }
it { expect(virus_scan.reload.status).to eq(VirusScan.statuses.fetch(:infected)) }
end
end