Merge pull request #5323 from betagouv/dev

This commit is contained in:
Pierre de La Morinerie 2020-07-01 16:17:27 +02:00 committed by GitHub
commit 83d230f8b4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
17 changed files with 53 additions and 58 deletions

View file

@ -8,17 +8,11 @@ def format_in_2_lines(pdf, label, text)
pdf.text "\n", size: 9
end
def render_box(pdf, text, x, width)
box = ::Prawn::Text::Box.new(text, { document: pdf, width: width, overflow: :expand, at: [x, pdf.cursor] })
box.render
box.height
end
def format_in_2_columns(pdf, label, text)
h1 = render_box(pdf, label, 0, 100)
h2 = render_box(pdf, ':', 100, 10)
h3 = render_box(pdf, text, 110, pdf.bounds.width - 110)
pdf.move_down 5 + [h1,h2,h3].max
pdf.text_box label, width: 200, height: 100, overflow: :expand, at: [0, pdf.cursor]
pdf.text_box ":", width: 10, height: 100, overflow: :expand, at: [100, pdf.cursor]
pdf.text_box text, width: 420, height: 100, overflow: :expand, at: [110, pdf.cursor]
pdf.text "\n"
end
def add_title(pdf, title)
@ -53,32 +47,33 @@ def render_siret_info(pdf, etablissement)
end
def render_identite_etablissement(pdf, etablissement)
format_in_2_columns(pdf, "SIRET", etablissement.siret)
format_in_2_columns(pdf, "SIRET du siège social", etablissement.entreprise.siret_siege_social) if etablissement.entreprise.siret_siege_social.present?
format_in_2_columns(pdf, "Dénomination", raison_sociale_or_name(etablissement))
format_in_2_columns(pdf, "Forme juridique ", etablissement.entreprise_forme_juridique)
pdf.text " - SIRET : #{etablissement.siret}"
pdf.text " - SIRET du siège social: #{etablissement.entreprise.siret_siege_social}"
pdf.text " - Dénomination : #{raison_sociale_or_name(etablissement)}"
pdf.text " - Forme juridique : #{etablissement.entreprise_forme_juridique}"
if etablissement.entreprise_capital_social.present?
format_in_2_columns(pdf, "Capital social ", pretty_currency(etablissement.entreprise_capital_social))
pdf.text " - Capital social : #{pretty_currency(etablissement.entreprise_capital_social)}"
end
format_in_2_columns(pdf, "Libellé NAF ", etablissement.libelle_naf)
format_in_2_columns(pdf, "Code NAF ", etablissement.naf)
format_in_2_columns(pdf, "Date de création ", try_format_date(etablissement.entreprise.date_creation))
pdf.text " - Libellé NAF : #{etablissement.libelle_naf}"
pdf.text " - Code NAF : #{etablissement.naf}"
pdf.text " - Date de création : #{try_format_date(etablissement.entreprise.date_creation)}"
if @include_infos_administration
format_in_2_columns(pdf, "Effectif mensuel #{try_format_mois_effectif(etablissement)} (URSSAF) ", etablissement.entreprise_effectif_mensuel)
format_in_2_columns(pdf, "Effectif moyen annuel #{etablissement.entreprise_effectif_annuel_annee} (URSSAF) ", etablissement.entreprise_effectif_annuel)
pdf.text " - Effectif mensuel #{try_format_mois_effectif(etablissement)} (URSSAF) : #{etablissement.entreprise_effectif_mensuel}"
pdf.text " - Effectif moyen annuel #{etablissement.entreprise_effectif_annuel_annee} (URSSAF) : #{etablissement.entreprise_effectif_annuel}"
end
format_in_2_columns(pdf, "Effectif (ISPF) ", effectif(etablissement))
format_in_2_columns(pdf, "Code effectif ", etablissement.entreprise.code_effectif_entreprise)
format_in_2_columns(pdf, "Numéro de TVA intracommunautaire ", etablissement.entreprise.numero_tva_intracommunautaire) if etablissement.entreprise.numero_tva_intracommunautaire.present?
format_in_2_columns(pdf, "Adresse ", etablissement.adresse)
pdf.text " - Effectif de l'organisation (INSEE) : #{effectif(etablissement)}"
pdf.text " - Code effectif : #{etablissement.entreprise.code_effectif_entreprise}"
pdf.text " - Numéro de TVA intracommunautaire : #{etablissement.entreprise.numero_tva_intracommunautaire}"
pdf.text " - Adresse : #{etablissement.adresse}"
if etablissement.association?
format_in_2_columns(pdf, "Numéro RNA ", etablissement.association_rna)
format_in_2_columns(pdf, "Titre ", etablissement.association_titre)
format_in_2_columns(pdf, "Objet ", etablissement.association_objet)
format_in_2_columns(pdf, "Date de création ", try_format_date(etablissement.association_date_creation))
format_in_2_columns(pdf, "Date de publication ", try_format_date(etablissement.association_date_publication))
format_in_2_columns(pdf, "Date de déclaration ", try_format_date(etablissement.association_date_declaration))
pdf.text " - Numéro RNA : #{etablissement.association_rna}"
pdf.text " - Titre : #{etablissement.association_titre}"
pdf.text " - Objet : #{etablissement.association_objet}"
pdf.text " - Date de création : #{try_format_date(etablissement.association_date_creation)}"
pdf.text " - Date de publication : #{try_format_date(etablissement.association_date_publication)}"
pdf.text " - Date de déclaration : #{try_format_date(etablissement.association_date_declaration)}"
end
pdf.text "\n"
end
def render_single_champ(pdf, champ)

View file

@ -27,7 +27,7 @@ describe API::V2::GraphqlController do
end.base64digest
end
let(:file) { Rack::Test::UploadedFile.new("./spec/fixtures/files/logo_test_procedure.png", 'image/png') }
let(:file) { fixture_file_upload('spec/fixtures/files/logo_test_procedure.png', 'image/png') }
let(:blob_info) do
{
filename: file.original_filename,

View file

@ -17,7 +17,7 @@ describe Champs::PieceJustificativeController, type: :controller do
end
context 'when the file is valid' do
let(:file) { Rack::Test::UploadedFile.new('spec/fixtures/files/piece_justificative_0.pdf', 'application/pdf') }
let(:file) { fixture_file_upload('spec/fixtures/files/piece_justificative_0.pdf', 'application/pdf') }
it 'attach the file' do
subject
@ -34,7 +34,7 @@ describe Champs::PieceJustificativeController, type: :controller do
end
context 'when the file is invalid' do
let(:file) { Rack::Test::UploadedFile.new('spec/fixtures/files/invalid_file_format.json', 'application/json') }
let(:file) { fixture_file_upload('spec/fixtures/files/invalid_file_format.json', 'application/json') }
# TODO: for now there are no validators on the champ piece_justificative_file,
# so we have to mock a failing validation.

View file

@ -82,7 +82,7 @@ describe Instructeurs::AvisController, type: :controller do
describe 'with attachment' do
include ActiveJob::TestHelper
let(:file) { Rack::Test::UploadedFile.new("./spec/fixtures/files/piece_justificative_0.pdf", 'application/pdf') }
let(:file) { fixture_file_upload('spec/fixtures/files/piece_justificative_0.pdf', 'application/pdf') }
before do
expect(ClamavService).to receive(:safe_file?).and_return(true)
@ -119,7 +119,7 @@ describe Instructeurs::AvisController, type: :controller do
end
context "with a file" do
let(:file) { Rack::Test::UploadedFile.new("./spec/fixtures/files/piece_justificative_0.pdf", 'application/pdf') }
let(:file) { fixture_file_upload('spec/fixtures/files/piece_justificative_0.pdf', 'application/pdf') }
it do
subject
@ -139,7 +139,7 @@ describe Instructeurs::AvisController, type: :controller do
let(:invite_linked_dossiers) { nil }
before do
@introduction_file = Rack::Test::UploadedFile.new("./spec/fixtures/files/piece_justificative_0.pdf", 'application/pdf')
@introduction_file = fixture_file_upload('spec/fixtures/files/piece_justificative_0.pdf', 'application/pdf')
post :create_avis, params: { id: previous_avis.id, procedure_id: procedure.id, avis: { emails: emails, introduction: intro, confidentiel: asked_confidentiel, invite_linked_dossiers: invite_linked_dossiers, introduction_file: @introduction_file } }
created_avis.reload
end

View file

@ -7,7 +7,7 @@ describe Instructeurs::DossiersController, type: :controller do
let(:instructeurs) { [instructeur] }
let(:procedure) { create(:procedure, :published, instructeurs: instructeurs) }
let(:dossier) { create(:dossier, :en_construction, procedure: procedure) }
let(:fake_justificatif) { Rack::Test::UploadedFile.new("./spec/fixtures/files/piece_justificative_0.pdf", 'application/pdf') }
let(:fake_justificatif) { fixture_file_upload('spec/fixtures/files/piece_justificative_0.pdf', 'application/pdf') }
before { sign_in(instructeur.user) }
@ -388,7 +388,7 @@ describe Instructeurs::DossiersController, type: :controller do
describe "#create_commentaire" do
let(:saved_commentaire) { dossier.commentaires.first }
let(:body) { "avant\napres" }
let(:file) { Rack::Test::UploadedFile.new("./spec/fixtures/files/piece_justificative_0.pdf", 'application/pdf') }
let(:file) { fixture_file_upload('spec/fixtures/files/piece_justificative_0.pdf', 'application/pdf') }
let(:scan_result) { true }
subject {

View file

@ -534,7 +534,7 @@ describe Users::DossiersController, type: :controller do
let(:first_champ) { dossier.champs.first }
let(:piece_justificative_champ) { dossier.champs.last }
let(:value) { 'beautiful value' }
let(:file) { Rack::Test::UploadedFile.new("./spec/fixtures/files/piece_justificative_0.pdf", 'application/pdf') }
let(:file) { fixture_file_upload('spec/fixtures/files/piece_justificative_0.pdf', 'application/pdf') }
let(:now) { Time.zone.parse('01/01/2100') }
let(:submit_payload) do
@ -786,7 +786,7 @@ describe Users::DossiersController, type: :controller do
let(:dossier) { create(:dossier, :en_construction, procedure: procedure, user: user) }
let(:saved_commentaire) { dossier.commentaires.first }
let(:body) { "avant\napres" }
let(:file) { Rack::Test::UploadedFile.new("./spec/fixtures/files/piece_justificative_0.pdf", 'application/pdf') }
let(:file) { fixture_file_upload('spec/fixtures/files/piece_justificative_0.pdf', 'application/pdf') }
let(:scan_result) { true }
subject {

View file

@ -5,6 +5,6 @@ FactoryBot.define do
end
trait :with_pdf do
pdf { Rack::Test::UploadedFile.new("./spec/fixtures/files/dossierPDF.pdf", 'application/pdf') }
pdf { Rack::Test::UploadedFile.new('spec/fixtures/files/dossierPDF.pdf', 'application/pdf') }
end
end

View file

@ -7,7 +7,7 @@ FactoryBot.define do
end
trait :with_files do
logo { Rack::Test::UploadedFile.new("./spec/fixtures/files/logo_test_procedure.png", 'image/png') }
signature { Rack::Test::UploadedFile.new("./spec/fixtures/files/logo_test_procedure.png", 'image/png') }
logo { Rack::Test::UploadedFile.new('spec/fixtures/files/logo_test_procedure.png', 'image/png') }
signature { Rack::Test::UploadedFile.new('spec/fixtures/files/logo_test_procedure.png', 'image/png') }
end
end

View file

@ -1,6 +1,6 @@
FactoryBot.define do
factory :bill_signature do
serialized { Rack::Test::UploadedFile.new("./spec/fixtures/files/bill_signature/serialized.json", 'application/json') }
signature { Rack::Test::UploadedFile.new("./spec/fixtures/files/bill_signature/signature.der", 'application/x-x509-ca-cert') }
serialized { Rack::Test::UploadedFile.new('spec/fixtures/files/bill_signature/serialized.json', 'application/json') }
signature { Rack::Test::UploadedFile.new('spec/fixtures/files/bill_signature/signature.der', 'application/x-x509-ca-cert') }
end
end

View file

@ -9,7 +9,7 @@ FactoryBot.define do
end
trait :with_file do
piece_jointe { Rack::Test::UploadedFile.new("./spec/fixtures/files/logo_test_procedure.png", 'image/png') }
piece_jointe { Rack::Test::UploadedFile.new('spec/fixtures/files/logo_test_procedure.png', 'image/png') }
end
end
end

View file

@ -55,7 +55,7 @@ FactoryBot.define do
end
trait :with_logo do
logo { Rack::Test::UploadedFile.new("./spec/fixtures/files/logo_test_procedure.png", 'image/png') }
logo { Rack::Test::UploadedFile.new('spec/fixtures/files/logo_test_procedure.png', 'image/png') }
end
trait :with_path do

View file

@ -96,7 +96,7 @@ class DossierMailerPreview < ActionMailer::Preview
end
def procedure
Procedure.new(id: 1234, libelle: 'Dotation dÉquipement des Territoires Ruraux - Exercice 2019', service: service, logo: Rack::Test::UploadedFile.new("./spec/fixtures/files/logo_test_procedure.png", 'image/png'), auto_archive_on: Time.zone.today + Dossier::REMAINING_DAYS_BEFORE_CLOSING.days)
Procedure.new(id: 1234, libelle: 'Dotation dÉquipement des Territoires Ruraux - Exercice 2019', service: service, logo: Rack::Test::UploadedFile.new('spec/fixtures/files/logo_test_procedure.png', 'image/png'), auto_archive_on: Time.zone.today + Dossier::REMAINING_DAYS_BEFORE_CLOSING.days)
end
def service

View file

@ -57,8 +57,8 @@ describe AttestationTemplate, type: :model do
describe 'dup' do
before do
@logo = Rack::Test::UploadedFile.new('spec/fixtures/files/white.png', 'image/png')
@signature = Rack::Test::UploadedFile.new('spec/fixtures/files/black.png', 'image/png')
@logo = fixture_file_upload('spec/fixtures/files/white.png', 'image/png')
@signature = fixture_file_upload('spec/fixtures/files/black.png', 'image/png')
end
after do
@ -89,8 +89,8 @@ describe AttestationTemplate, type: :model do
describe 'invalidate attestation if images attachments are not valid' do
before do
@logo = Rack::Test::UploadedFile.new('spec/fixtures/files/french-flag.gif', 'image/gif')
@signature = Rack::Test::UploadedFile.new('spec/fixtures/files/beta-gouv.gif', 'image/gif')
@logo = fixture_file_upload('spec/fixtures/files/french-flag.gif', 'image/gif')
@signature = fixture_file_upload('spec/fixtures/files/beta-gouv.gif', 'image/gif')
end
after do

View file

@ -3,7 +3,7 @@ describe MailTemplateConcern do
let(:dossier) { create(:dossier, procedure: procedure) }
let(:dossier2) { create(:dossier, procedure: procedure) }
let(:initiated_mail) { create(:initiated_mail, procedure: procedure) }
let(:justificatif) { Rack::Test::UploadedFile.new("./spec/fixtures/files/piece_justificative_0.pdf", 'application/pdf') }
let(:justificatif) { fixture_file_upload('spec/fixtures/files/piece_justificative_0.pdf', 'application/pdf') }
shared_examples "can replace tokens in template" do
describe 'with no token to replace' do

View file

@ -191,7 +191,7 @@ describe Procedure do
context 'when the deliberation is uploaded ' do
before do
procedure.deliberation = Rack::Test::UploadedFile.new('spec/fixtures/files/file.pdf', 'application/pdf')
procedure.deliberation = fixture_file_upload('spec/fixtures/files/file.pdf', 'application/pdf')
end
it { expect(procedure.valid?).to eq(true) }
@ -199,7 +199,7 @@ describe Procedure do
context 'when the deliberation is uploaded with an unauthorized format' do
before do
procedure.deliberation = Rack::Test::UploadedFile.new('spec/fixtures/files/french-flag.gif', 'image/gif')
procedure.deliberation = fixture_file_upload('spec/fixtures/files/french-flag.gif', 'image/gif')
end
it { expect(procedure.valid?).to eq(false) }
@ -952,7 +952,7 @@ describe Procedure do
p.reload
expect(p.juridique_required).to be_falsey
@deliberation = Rack::Test::UploadedFile.new('spec/fixtures/files/file.pdf', 'application/pdf')
@deliberation = fixture_file_upload('spec/fixtures/files/file.pdf', 'application/pdf')
p.update(deliberation: @deliberation)
p.reload
expect(p.juridique_required).to be_truthy

View file

@ -27,7 +27,7 @@ describe CommentaireService do
end
context 'when it has a file' do
let(:file) { Rack::Test::UploadedFile.new("./spec/fixtures/files/piece_justificative_0.pdf", 'application/pdf') }
let(:file) { fixture_file_upload('spec/fixtures/files/piece_justificative_0.pdf', 'application/pdf') }
before do
expect(ClamavService).to receive(:safe_file?).and_return(true)

View file

@ -1,5 +1,5 @@
describe 'new_administrateur/procedures/edit.html.haml' do
let(:logo) { Rack::Test::UploadedFile.new("./spec/fixtures/files/logo_test_procedure.png", 'image/png') }
let(:logo) { fixture_file_upload('spec/fixtures/files/logo_test_procedure.png', 'image/png') }
let(:procedure) { create(:procedure, logo: logo, lien_site_web: 'http://some.website') }
before do