Use enum to the fullest with VirusScan.statuses
This commit is contained in:
parent
7efa64a091
commit
606b56033a
3 changed files with 6 additions and 6 deletions
|
@ -9,9 +9,9 @@ class AntiVirusJob < ApplicationJob
|
||||||
if @blob.present?
|
if @blob.present?
|
||||||
download_blob_to_tempfile do |file|
|
download_blob_to_tempfile do |file|
|
||||||
if ClamavService.safe_file?(file.path)
|
if ClamavService.safe_file?(file.path)
|
||||||
status = "safe"
|
status = VirusScan.statuses.fetch(:safe)
|
||||||
else
|
else
|
||||||
status = "infected"
|
status = VirusScan.statuses.fetch(:infected)
|
||||||
end
|
end
|
||||||
virus_scan.update(scanned_at: Time.now, status: status)
|
virus_scan.update(scanned_at: Time.now, status: status)
|
||||||
end
|
end
|
||||||
|
|
|
@ -54,7 +54,7 @@ class Champs::PieceJustificativeChamp < Champ
|
||||||
if self.piece_justificative_file&.attachment&.blob.present?
|
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.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|
|
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
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -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.piece_justificative_file.attach(io: StringIO.new("toto"), filename: "toto.txt", content_type: "text/plain")
|
||||||
champ
|
champ
|
||||||
end
|
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) }
|
subject { AntiVirusJob.new.perform(virus_scan) }
|
||||||
|
|
||||||
|
@ -16,7 +16,7 @@ RSpec.describe AntiVirusJob, type: :job do
|
||||||
subject
|
subject
|
||||||
end
|
end
|
||||||
|
|
||||||
it { expect(virus_scan.reload.status).to eq("safe") }
|
it { expect(virus_scan.reload.status).to eq(VirusScan.statuses.fetch(:safe)) }
|
||||||
end
|
end
|
||||||
|
|
||||||
context "when a virus is found" do
|
context "when a virus is found" do
|
||||||
|
@ -27,6 +27,6 @@ RSpec.describe AntiVirusJob, type: :job do
|
||||||
subject
|
subject
|
||||||
end
|
end
|
||||||
|
|
||||||
it { expect(virus_scan.reload.status).to eq("infected") }
|
it { expect(virus_scan.reload.status).to eq(VirusScan.statuses.fetch(:infected)) }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue