Merge pull request #117 from sgmap/pieces_justificatives_improvements
Pieces justificatives improvements
This commit is contained in:
commit
b36252b916
2 changed files with 8 additions and 8 deletions
|
@ -2,17 +2,17 @@ class PiecesJustificativesService
|
||||||
def self.upload!(dossier, user, params)
|
def self.upload!(dossier, user, params)
|
||||||
tpj_contents = dossier.types_de_piece_justificative
|
tpj_contents = dossier.types_de_piece_justificative
|
||||||
.map { |tpj| [tpj, params["piece_justificative_#{tpj.id}"]] }
|
.map { |tpj| [tpj, params["piece_justificative_#{tpj.id}"]] }
|
||||||
.select { |_, content| content }
|
.select { |_, content| content.present? }
|
||||||
|
|
||||||
without_virus, with_virus = tpj_contents
|
without_virus, with_virus = tpj_contents
|
||||||
.partition { |_, content| ClamavService.safe_file?(content.path) }
|
.partition { |_, content| ClamavService.safe_file?(content.path) }
|
||||||
|
|
||||||
errors = with_virus
|
errors = with_virus
|
||||||
.map { |_, content| content.original_filename + ': <b>Virus détecté !!</b>' }
|
.map { |_, content| content.original_filename + ' : virus détecté' }
|
||||||
|
|
||||||
errors += without_virus
|
errors += without_virus
|
||||||
.map { |tpj, content| save_pj(content, dossier, tpj, user) }
|
.map { |tpj, content| save_pj(content, dossier, tpj, user) }
|
||||||
.reject(&:empty?)
|
.compact()
|
||||||
|
|
||||||
errors += missing_pj_error_messages(dossier)
|
errors += missing_pj_error_messages(dossier)
|
||||||
end
|
end
|
||||||
|
@ -40,7 +40,7 @@ class PiecesJustificativesService
|
||||||
type_de_piece_justificative: tpj,
|
type_de_piece_justificative: tpj,
|
||||||
user: user)
|
user: user)
|
||||||
|
|
||||||
pj.save ? '' : "le fichier #{pj.libelle} n'a pas pu être sauvegardé"
|
pj.save ? nil : "le fichier #{content.original_filename} (#{pj.libelle}) n'a pas pu être sauvegardé"
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.missing_pj_error_messages(dossier)
|
def self.missing_pj_error_messages(dossier)
|
||||||
|
|
|
@ -31,11 +31,11 @@ describe PiecesJustificativesService do
|
||||||
let(:hash) do
|
let(:hash) do
|
||||||
{
|
{
|
||||||
"piece_justificative_#{tpj_not_mandatory.id}" =>
|
"piece_justificative_#{tpj_not_mandatory.id}" =>
|
||||||
double(path: '', original_filename: 'file')
|
double(path: '', original_filename: 'filename')
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
it { expect(errors).to match(["le fichier not mandatory n'a pas pu être sauvegardé"]) }
|
it { expect(errors).to match(["le fichier filename (not mandatory) n'a pas pu être sauvegardé"]) }
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'when a virus is provided' do
|
context 'when a virus is provided' do
|
||||||
|
@ -47,7 +47,7 @@ describe PiecesJustificativesService do
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
it { expect(errors).to match(['bad_file: <b>Virus détecté !!</b>']) }
|
it { expect(errors).to match(['bad_file : virus détecté']) }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -63,7 +63,7 @@ describe PiecesJustificativesService do
|
||||||
# we are messing around piece_justificative
|
# we are messing around piece_justificative
|
||||||
# because directly doubling carrierwave params seems complicated
|
# because directly doubling carrierwave params seems complicated
|
||||||
|
|
||||||
allow(PiecesJustificativesService).to receive(:save_pj).and_return('')
|
allow(PiecesJustificativesService).to receive(:save_pj).and_return(nil)
|
||||||
piece_justificative_double = double(type_de_piece_justificative: tpj_mandatory)
|
piece_justificative_double = double(type_de_piece_justificative: tpj_mandatory)
|
||||||
expect(dossier).to receive(:pieces_justificatives).and_return([piece_justificative_double])
|
expect(dossier).to receive(:pieces_justificatives).and_return([piece_justificative_double])
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Reference in a new issue