Merge pull request #3573 from betagouv/frederic/fix_3572-balises_sur_mauvais_type_de_champ

[Fix #3572] Use champ with correct type for balise
This commit is contained in:
Frederic Merizen 2019-03-08 20:07:26 +01:00 committed by GitHub
commit 8626d0a055
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 32 additions and 25 deletions

View file

@ -23,25 +23,25 @@ class TypesDeChamp::LinkedDropDownListTypeDeChamp < TypesDeChamp::TypeDeChampBas
def tags_for_template
tags = super
l = libelle
tdc = @type_de_champ
tags.push(
{
libelle: "#{l}/primaire",
libelle: "#{libelle}/primaire",
description: "#{description} (menu primaire)",
lambda: -> (champs) {
champs
.detect { |champ| champ.libelle == l }
.detect { |champ| champ.type_de_champ == tdc }
&.primary_value
}
}
)
tags.push(
{
libelle: "#{l}/secondaire",
libelle: "#{libelle}/secondaire",
description: "#{description} (menu secondaire)",
lambda: -> (champs) {
champs
.detect { |champ| champ.libelle == l }
.detect { |champ| champ.type_de_champ == tdc }
&.secondary_value
}
}

View file

@ -8,13 +8,13 @@ class TypesDeChamp::TypeDeChampBase
end
def tags_for_template
l = libelle
tdc = @type_de_champ
[
{
libelle: l,
libelle: libelle,
description: description,
lambda: -> (champs) {
champs.detect { |champ| champ.libelle == l }
champs.detect { |champ| champ.type_de_champ == tdc }
}
}
]

View file

@ -115,12 +115,10 @@ describe TagsSubstitutionConcern, type: :model do
end
context 'when the procedure has a linked drop down menus type de champ' do
let(:types_de_champ) do
[
create(:type_de_champ_linked_drop_down_list, libelle: 'libelle')
]
let(:type_de_champ) do
create(:type_de_champ_linked_drop_down_list, libelle: 'libelle')
end
let(:types_de_champ) { [type_de_champ] }
let(:template) { 'tout : --libelle--, primaire : --libelle/primaire--, secondaire : --libelle/secondaire--' }
context 'and the champ has no value' do
@ -129,22 +127,31 @@ describe TagsSubstitutionConcern, type: :model do
context 'and the champ has a primary value' do
before do
c = dossier.champs.detect { |champ| champ.libelle == 'libelle' }
c.primary_value = 'primo'
c.save
dossier.champs.find_by(type_de_champ: type_de_champ).update(primary_value: 'primo')
dossier.reload
end
it { is_expected.to eq('tout : primo, primaire : primo, secondaire : ') }
end
context 'and the champ has a primary and secondary value' do
before do
c = dossier.champs.detect { |champ| champ.libelle == 'libelle' }
c.primary_value = 'primo'
c.secondary_value = 'secundo'
c.save
context 'and the champ has a secondary value' do
before do
dossier.champs.find_by(type_de_champ: type_de_champ).update(secondary_value: 'secundo')
dossier.reload
end
it { is_expected.to eq('tout : primo / secundo, primaire : primo, secondaire : secundo') }
context 'and the same libelle is used by a header' do
let(:types_de_champ) do
[
type_de_champ,
create(:type_de_champ_header_section, libelle: 'libelle')
]
end
it { is_expected.to eq('tout : primo / secundo, primaire : primo, secondaire : secundo') }
end
end
it { is_expected.to eq('tout : primo / secundo, primaire : primo, secondaire : secundo') }
end
end