Less mokey patching
This commit is contained in:
parent
f6421e081a
commit
cc4eba2b36
2 changed files with 0 additions and 24 deletions
|
@ -1,21 +1,3 @@
|
|||
ActiveStorage::Service.url_expires_in = 1.hour
|
||||
|
||||
# We want to run the virus scan on every ActiveStorage attachment,
|
||||
# regardless of its type (user-uploaded document, instructeur-uploaded attestation, form template, etc.)
|
||||
#
|
||||
# To do this, the best place to work on is the ActiveStorage::Attachment
|
||||
# objects themselves.
|
||||
#
|
||||
# We have to monkey patch ActiveStorage in order to always run an analyzer.
|
||||
# The way analyzable blob interface work is by running the first accepted analyzer.
|
||||
# This is not what we want for the virus scan. Using analyzer interface is still beneficial
|
||||
# as it takes care of downloading the blob.
|
||||
ActiveStorage::Attached::One.class_eval do
|
||||
def virus_scanner
|
||||
if attached?
|
||||
ActiveStorage::VirusScanner.new(attachment.blob)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
ActiveSupport.on_load(:active_storage_blob) { include BlobVirusScanner }
|
||||
|
|
|
@ -390,12 +390,6 @@ describe Champ do
|
|||
|
||||
it { expect(champ.piece_justificative_file.virus_scanner.started?).to be_truthy }
|
||||
end
|
||||
|
||||
context 'and there is no blob' do
|
||||
before { champ.save }
|
||||
|
||||
it { expect(champ.piece_justificative_file.virus_scanner).to be_nil }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue