same for direct access by champ.value
This commit is contained in:
parent
5f63ade97a
commit
a362e95542
3 changed files with 3 additions and 16 deletions
|
@ -1,17 +1,4 @@
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
class TypesDeChamp::DropDownListTypeDeChamp < TypesDeChamp::TypeDeChampBase
|
class TypesDeChamp::DropDownListTypeDeChamp < TypesDeChamp::TypeDeChampBase
|
||||||
def champ_blank?(champ)
|
|
||||||
super || !champ_value_in_options?(champ)
|
|
||||||
end
|
|
||||||
|
|
||||||
private
|
|
||||||
|
|
||||||
def champ_value_in_options?(champ)
|
|
||||||
champ_with_other_value?(champ) || drop_down_options.include?(champ.value)
|
|
||||||
end
|
|
||||||
|
|
||||||
def champ_with_other_value?(champ)
|
|
||||||
drop_down_other? && champ.value_json&.fetch('other', false)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -24,7 +24,7 @@ class TypesDeChamp::MultipleDropDownListTypeDeChamp < TypesDeChamp::TypeDeChampB
|
||||||
[champ.value]
|
[champ.value]
|
||||||
else
|
else
|
||||||
JSON.parse(champ.value)
|
JSON.parse(champ.value)
|
||||||
end.filter { drop_down_options.include?(_1) }
|
end
|
||||||
rescue JSON::ParserError
|
rescue JSON::ParserError
|
||||||
[]
|
[]
|
||||||
end
|
end
|
||||||
|
|
|
@ -449,7 +449,7 @@ describe DossierRebaseConcern do
|
||||||
tdc_to_update.update(drop_down_options: ["option", "updated"])
|
tdc_to_update.update(drop_down_options: ["option", "updated"])
|
||||||
end
|
end
|
||||||
|
|
||||||
it { expect { subject }.to change { dossier.project_champs_public.first.to_s }.from('v1').to('') }
|
it { expect { subject }.not_to change { dossier.project_champs_public.first.to_s } }
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'when a dropdown unused option is removed' do
|
context 'when a dropdown unused option is removed' do
|
||||||
|
@ -495,7 +495,7 @@ describe DossierRebaseConcern do
|
||||||
tdc_to_update.update(drop_down_options: ["option", "updated"])
|
tdc_to_update.update(drop_down_options: ["option", "updated"])
|
||||||
end
|
end
|
||||||
|
|
||||||
it { expect { subject }.to change { dossier.project_champs_public.first.to_s }.from('v1, option').to('option') }
|
it { expect { subject }.not_to change { dossier.project_champs_public.first.to_s } }
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'when a dropdown unused option is removed' do
|
context 'when a dropdown unused option is removed' do
|
||||||
|
|
Loading…
Reference in a new issue