Skip to content

Commit

Permalink
same for direct access by champ.value
Browse files Browse the repository at this point in the history
  • Loading branch information
LeSim committed Dec 12, 2024
1 parent 5f63ade commit a362e95
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 16 deletions.
13 changes: 0 additions & 13 deletions app/models/types_de_champ/drop_down_list_type_de_champ.rb
Original file line number Diff line number Diff line change
@@ -1,17 +1,4 @@
# frozen_string_literal: true

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
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def selected_options(champ)
[champ.value]
else
JSON.parse(champ.value)
end.filter { drop_down_options.include?(_1) }
end
rescue JSON::ParserError
[]
end
Expand Down
4 changes: 2 additions & 2 deletions spec/models/concerns/dossier_rebase_concern_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@
tdc_to_update.update(drop_down_options: ["option", "updated"])
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

context 'when a dropdown unused option is removed' do
Expand Down Expand Up @@ -495,7 +495,7 @@
tdc_to_update.update(drop_down_options: ["option", "updated"])
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

context 'when a dropdown unused option is removed' do
Expand Down

0 comments on commit a362e95

Please sign in to comment.