dossiers: fix dossier_vide with drop_down_list

Previously a drop-down list with an ["Autre", "__other__"] value crashed
the PDF generation.
This commit is contained in:
Pierre de La Morinerie 2022-05-04 16:34:20 +02:00
parent 0e60830102
commit 59d8479b85
4 changed files with 14 additions and 2 deletions

View file

@ -26,7 +26,10 @@ def format_in_2_columns(pdf, label)
pdf.text "\n"
end
def format_with_checkbox(pdf, label, offset = 0)
def format_with_checkbox(pdf, option, offset = 0)
# Option is a [text, value] pair, or a string used for both.
label = option.is_a?(String) ? option : option.first
pdf.font 'marianne', size: 9 do
pdf.stroke_rectangle [0 + offset, pdf.cursor], 10, 10
pdf.text_box label, at: [15 + offset, pdf.cursor]

View file

@ -202,6 +202,12 @@ FactoryBot.define do
end
end
trait :with_drop_down_list do
after(:build) do |procedure, _evaluator|
build(:type_de_champ_drop_down_list, :with_other, procedure: procedure)
end
end
trait :with_address do
after(:build) do |procedure, _evaluator|
build(:type_de_champ_address, procedure: procedure)

View file

@ -92,6 +92,9 @@ FactoryBot.define do
trait :without_selectable_values do
drop_down_list_value { "\r\n--separateur--\r\n--separateur 2--\r\n \r\n" }
end
trait :with_other do
drop_down_other { true }
end
end
factory :type_de_champ_multiple_drop_down_list do
type_champ { TypeDeChamp.type_champs.fetch(:multiple_drop_down_list) }

View file

@ -1,5 +1,5 @@
describe 'dossiers/dossier_vide.pdf.prawn', type: :view do
let(:procedure) { create(:procedure, :with_all_champs) }
let(:procedure) { create(:procedure, :with_all_champs, :with_drop_down_list) }
let(:dossier) { create(:dossier, procedure: procedure) }
before do