diff --git a/app/models/champs/drop_down_list_champ.rb b/app/models/champs/drop_down_list_champ.rb index 248eb443f..6fbbf0996 100644 --- a/app/models/champs/drop_down_list_champ.rb +++ b/app/models/champs/drop_down_list_champ.rb @@ -56,7 +56,7 @@ class Champs::DropDownListChamp < Champ end def drop_down_other? - drop_down_other + drop_down_other == "1" || drop_down_other == true end def value=(value) diff --git a/spec/models/champs/drop_down_list_champ_spec.rb b/spec/models/champs/drop_down_list_champ_spec.rb new file mode 100644 index 000000000..1c7cec6b0 --- /dev/null +++ b/spec/models/champs/drop_down_list_champ_spec.rb @@ -0,0 +1,24 @@ +describe Champs::DropDownListChamp do + describe '#drop_down_other?' do + let(:drop_down) { create(:champ_drop_down_list) } + + context 'when drop_down_other is nil' do + it do + drop_down.type_de_champ.drop_down_other = nil + expect(drop_down.drop_down_other?).to be false + + drop_down.type_de_champ.drop_down_other = "0" + expect(drop_down.drop_down_other?).to be false + + drop_down.type_de_champ.drop_down_other = false + expect(drop_down.drop_down_other?).to be false + + drop_down.type_de_champ.drop_down_other = "1" + expect(drop_down.drop_down_other?).to be true + + drop_down.type_de_champ.drop_down_other = true + expect(drop_down.drop_down_other?).to be true + end + end + end +end