From 384006d93740334e59ba6357472f006c1a5b489d Mon Sep 17 00:00:00 2001 From: Lisa Durand Date: Wed, 18 Dec 2024 17:34:17 +0100 Subject: [PATCH] wip fix test --- spec/models/champ_spec.rb | 7 +++++-- spec/models/champs/drop_down_list_champ_spec.rb | 6 ++++-- spec/models/logic/champ_value_spec.rb | 7 ++++++- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/spec/models/champ_spec.rb b/spec/models/champ_spec.rb index 90fbf30e41c..f1d474f7586 100644 --- a/spec/models/champ_spec.rb +++ b/spec/models/champ_spec.rb @@ -306,8 +306,11 @@ end context 'for drop down list champ' do - let(:champ) { Champs::DropDownListChamp.new(value:) } - before { allow(champ).to receive(:type_de_champ).and_return(build(:type_de_champ_drop_down_list)) } + let(:champ) { Champs::DropDownListChamp.new() } + before do + allow(champ).to receive(:type_de_champ).and_return(build(:type_de_champ_drop_down_list)) + champ.value = value + end let(:value) { "val1" } it { is_expected.to eq([value]) } diff --git a/spec/models/champs/drop_down_list_champ_spec.rb b/spec/models/champs/drop_down_list_champ_spec.rb index d69487b087c..5f8f40ed2c4 100644 --- a/spec/models/champs/drop_down_list_champ_spec.rb +++ b/spec/models/champs/drop_down_list_champ_spec.rb @@ -3,10 +3,12 @@ describe Champs::DropDownListChamp do describe 'validations' do describe 'inclusion' do - let(:champ) { described_class.new(other:, value:, dossier: build(:dossier)) } + let(:champ) { described_class.new(other:, dossier: create(:dossier)) } before do - allow(champ).to receive(:type_de_champ).and_return(build(:type_de_champ_drop_down_list, drop_down_other: other)) + type_de_champ = build(:type_de_champ_drop_down_list, drop_down_other: other) + allow(champ).to receive(:type_de_champ).and_return(type_de_champ) allow(champ).to receive(:in_dossier_revision?).and_return(true) + champ.value = value end subject { champ.validate(:champs_public_value) } diff --git a/spec/models/logic/champ_value_spec.rb b/spec/models/logic/champ_value_spec.rb index 1659d129e4f..736e11944d6 100644 --- a/spec/models/logic/champ_value_spec.rb +++ b/spec/models/logic/champ_value_spec.rb @@ -64,10 +64,14 @@ context 'dropdown tdc' do let(:tdc_type) { :drop_down_list } - let(:champ) { Champs::DropDownListChamp.new(value:, other:, stable_id: tdc.stable_id, dossier:) } + let(:champ) { Champs::DropDownListChamp.new(other:, stable_id: tdc.stable_id, dossier:) } let(:value) { 'val1' } let(:other) { nil } + before do + champ.value = value + end + it { expect(champ_value(champ.stable_id).type([champ.type_de_champ])).to eq(:enum) } it { is_expected.to eq('val1') } it { expect(champ_value(champ.stable_id).options([champ.type_de_champ])).to match_array([["val1", "val1"], ["val2", "val2"], ["val3", "val3"]]) } @@ -81,6 +85,7 @@ context 'with other filled' do let(:other) { true } + let(:value) { Champs::DropDownListChamp::OTHER } it { is_expected.to eq(Champs::DropDownListChamp::OTHER) } end