2024-04-29 00:17:15 +02:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2022-09-09 15:36:50 +02:00
|
|
|
describe Logic::IncludeOperator do
|
|
|
|
include Logic
|
|
|
|
|
2024-07-01 15:31:32 +02:00
|
|
|
let(:procedure) { create(:procedure, types_de_champ_public: [{ type: :multiple_drop_down_list }]) }
|
|
|
|
let(:tdc) { procedure.active_revision.types_de_champ.first }
|
|
|
|
let(:dossier) { create(:dossier, procedure:) }
|
|
|
|
let(:champ) { Champs::MultipleDropDownListChamp.new(value: '["val1", "val2"]', stable_id: tdc.stable_id, dossier:) }
|
2022-09-09 15:36:50 +02:00
|
|
|
|
|
|
|
describe '#compute' do
|
|
|
|
it { expect(ds_include(champ_value(champ.stable_id), constant('val1')).compute([champ])).to be(true) }
|
|
|
|
it { expect(ds_include(champ_value(champ.stable_id), constant('something else')).compute([champ])).to be(false) }
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#errors' do
|
2022-09-26 21:11:43 +02:00
|
|
|
it { expect(ds_include(champ_value(champ.stable_id), constant('val1')).errors([champ.type_de_champ])).to be_empty }
|
2022-09-14 10:43:18 +02:00
|
|
|
it do
|
|
|
|
expected = {
|
|
|
|
right: constant('something else'),
|
|
|
|
stable_id: champ.stable_id,
|
|
|
|
type: :not_included
|
|
|
|
}
|
|
|
|
|
2022-09-26 21:11:43 +02:00
|
|
|
expect(ds_include(champ_value(champ.stable_id), constant('something else')).errors([champ.type_de_champ])).to eq([expected])
|
2022-09-14 10:43:18 +02:00
|
|
|
end
|
|
|
|
|
2022-09-26 21:11:43 +02:00
|
|
|
it { expect(ds_include(constant(1), constant('val1')).errors([])).to eq([{ type: :required_list }]) }
|
2022-09-09 15:36:50 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
describe '#==' do
|
|
|
|
it { expect(ds_include(champ_value(champ.stable_id), constant('val1'))).to eq(ds_include(champ_value(champ.stable_id), constant('val1'))) }
|
|
|
|
end
|
|
|
|
end
|