From 2a4822855277fda69714700613e5e3c5c32ccdeb Mon Sep 17 00:00:00 2001 From: Paul Chavard Date: Tue, 4 Apr 2023 14:54:29 +0200 Subject: [PATCH] fix(dossier): improuve commune champ rendering in pdf --- app/models/champs/commune_champ.rb | 2 +- app/views/dossiers/show.pdf.prawn | 8 ++++---- spec/controllers/instructeurs/dossiers_controller_spec.rb | 7 +++++++ spec/models/dossier_spec.rb | 4 ++-- 4 files changed, 14 insertions(+), 7 deletions(-) diff --git a/app/models/champs/commune_champ.rb b/app/models/champs/commune_champ.rb index ccd741461..b30ad97cf 100644 --- a/app/models/champs/commune_champ.rb +++ b/app/models/champs/commune_champ.rb @@ -25,7 +25,7 @@ class Champs::CommuneChamp < Champs::TextChamp before_validation :on_code_postal_change def for_export - [name, code, departement? ? departement_code_and_name : ''] + [name, code? ? code : '', departement? ? departement_code_and_name : ''] end def departement_name diff --git a/app/views/dossiers/show.pdf.prawn b/app/views/dossiers/show.pdf.prawn index 5e08edf8b..b630586a7 100644 --- a/app/views/dossiers/show.pdf.prawn +++ b/app/views/dossiers/show.pdf.prawn @@ -170,14 +170,14 @@ def add_single_champ(pdf, champ) add_identite_etablissement(pdf, champ.etablissement) end when 'Champs::NumberChamp' - value = champ.to_s.empty? ? 'Non communiqué' : number_with_delimiter(champ.to_s) + value = champ.blank? ? 'Non communiqué' : number_with_delimiter(champ.to_s) format_in_2_lines(pdf, tdc.libelle, value) when 'Champs::CommuneChamp' - value = champ.to_s.empty? ? 'Non communiqué' : champ.to_s + value = champ.blank? ? 'Non communiqué' : champ.to_s format_in_2_lines(pdf, tdc.libelle, value) - pdf.text "Département : #{champ.departement}" if champ.departement.present? + pdf.text "Département : #{champ.departement_code_and_name}" if champ.departement? else - value = champ.to_s.empty? ? 'Non communiqué' : champ.to_s + value = champ.blank? ? 'Non communiqué' : champ.to_s format_in_2_lines(pdf, tdc.libelle, value) end end diff --git a/spec/controllers/instructeurs/dossiers_controller_spec.rb b/spec/controllers/instructeurs/dossiers_controller_spec.rb index d708bae10..3c55f2b49 100644 --- a/spec/controllers/instructeurs/dossiers_controller_spec.rb +++ b/spec/controllers/instructeurs/dossiers_controller_spec.rb @@ -738,6 +738,13 @@ describe Instructeurs::DossiersController, type: :controller do it { expect(assigns(:include_infos_administration)).to eq(true) } it { expect(assigns(:is_dossier_in_batch_operation)).to eq(false) } it { expect(response).to render_template 'dossiers/show' } + + context 'empty champs commune' do + let(:procedure) { create(:procedure, :published, :with_commune, instructeurs:) } + let(:dossier) { create(:dossier, :accepte, procedure:) } + + it { expect(response).to render_template 'dossiers/show' } + end end context 'with dossier in batch_operation' do diff --git a/spec/models/dossier_spec.rb b/spec/models/dossier_spec.rb index becc9e888..bcdde92d6 100644 --- a/spec/models/dossier_spec.rb +++ b/spec/models/dossier_spec.rb @@ -1680,8 +1680,8 @@ describe Dossier do [ [yes_no_tdc.libelle, "Oui"], [text_tdc.libelle, "text"], - ["commune", nil], - ["commune (Code insee)", nil], + ["commune", ''], + ["commune (Code insee)", ''], ["commune (Département)", ""] ] end