Merge pull request #5144 from betagouv/add-piece-justificative-filename-to-export

Instructeur : le nom de fichier des pièces justificatives est maintenant indiqué dans les exports tableur
This commit is contained in:
Pierre de La Morinerie 2020-05-14 12:34:35 +02:00 committed by GitHub
commit c01b69214e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 26 additions and 2 deletions

View file

@ -36,6 +36,10 @@ class Champs::PieceJustificativeChamp < Champ
mandatory? && !piece_justificative_file.attached?
end
def for_export
piece_justificative_file.filename.to_s if piece_justificative_file.attached?
end
def for_api
if piece_justificative_file.attached? && (piece_justificative_file.virus_scanner.safe? || piece_justificative_file.virus_scanner.pending?)
piece_justificative_file.service_url

View file

@ -131,11 +131,19 @@ class Dossier < ApplicationRecord
etablissement: :champ,
champs: {
etablissement: :champ,
type_de_champ: :drop_down_list
type_de_champ: :drop_down_list,
piece_justificative_file_attachment: :blob,
champs: [
piece_justificative_file_attachment: :blob
]
},
champs_private: {
etablissement: :champ,
type_de_champ: :drop_down_list
type_de_champ: :drop_down_list,
piece_justificative_file_attachment: :blob,
champs: [
piece_justificative_file_attachment: :blob
]
},
procedure: :groupe_instructeurs
).order(en_construction_at: 'asc')

View file

@ -14,6 +14,18 @@ describe Champs::PieceJustificativeChamp do
it { is_expected.to validate_content_type_of(:piece_justificative_file).allowing(Champs::PieceJustificativeChamp::ACCEPTED_FORMATS) }
end
describe "#for_export" do
let(:champ_pj) { create(:champ_piece_justificative) }
subject { champ_pj.for_export }
it { is_expected.to eq('toto.txt') }
context 'without attached file' do
before { champ_pj.piece_justificative_file.purge }
it { is_expected.to eq(nil) }
end
end
describe '#for_api' do
let(:champ_pj) { create(:champ_piece_justificative) }
let(:metadata) { champ_pj.piece_justificative_file.blob.metadata }