Skip to content

Commit

Permalink
wip try to fix test with a before_save hook
Browse files Browse the repository at this point in the history
  • Loading branch information
lisa-durand authored and E-L-T committed Dec 20, 2024
1 parent 51a8ed9 commit d5b2d19
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions app/models/champs/drop_down_list_champ.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ class Champs::DropDownListChamp < Champ
OTHER = '__other__'
delegate :options_without_empty_value_when_mandatory, to: :type_de_champ
validate :value_is_in_options, if: -> { validate_champ_value? && !(value.blank? || drop_down_other?) }
before_save :store_referentiel

def render_as_radios?
options = referentiel? ? referentiel_drop_down_options : drop_down_options
Expand Down Expand Up @@ -37,18 +38,27 @@ def other?
def value=(value)
if value == OTHER
self.other = true
self.referentiel = nil if self.referentiel?
write_attribute(:value, nil)
else
self.other = false
self.referentiel = set_referentiel_from(value) if self.referentiel? && value
write_attribute(:value, value)
end
end

def store_referentiel
return if !self.referentiel?
if self.other?

Check warning on line 50 in app/models/champs/drop_down_list_champ.rb

View check run for this annotation

Codecov / codecov/patch

app/models/champs/drop_down_list_champ.rb#L50

Added line #L50 was not covered by tests
self.referentiel = nil
else
self.referentiel = set_referentiel_from(value) if value
end
end

def set_referentiel_from(value)
referentiel_item = ReferentielItem.find(value)
{ data: referentiel_item.data }
if value.present?
referentiel_item = ReferentielItem.find(value)
{ data: referentiel_item.data }

Check warning on line 60 in app/models/champs/drop_down_list_champ.rb

View check run for this annotation

Codecov / codecov/patch

app/models/champs/drop_down_list_champ.rb#L60

Added line #L60 was not covered by tests
end
end

def value_other=(value)
Expand Down

0 comments on commit d5b2d19

Please sign in to comment.