feat(logic): operators sources

This commit is contained in:
Colin Darie 2023-01-04 11:10:10 +01:00
parent 0df7090eaa
commit 81f00774af
10 changed files with 48 additions and 0 deletions

View file

@ -18,6 +18,16 @@ describe Logic::BinaryOperator do
describe '#errors' do
it { expect(greater_than(constant(1), constant(true)).errors).to eq([{ operator_name: "Logic::GreaterThan", type: :required_number }]) }
end
describe '#sources' do
let(:champ) { create(:champ_integer_number, value: nil) }
let(:champ2) { create(:champ_integer_number, value: nil) }
it { expect(two_greater_than_one.sources).to eq([]) }
it { expect(greater_than(champ_value(champ.stable_id), constant(2)).sources).to eq([champ.stable_id]) }
it { expect(greater_than(constant(2), champ_value(champ.stable_id)).sources).to eq([champ.stable_id]) }
it { expect(greater_than(champ_value(champ.stable_id), champ_value(champ2.stable_id)).sources).to eq([champ.stable_id, champ2.stable_id]) }
end
end
describe Logic::GreaterThan do

View file

@ -83,6 +83,12 @@ describe Logic::ChampValue do
it { expect(champ_value(champ.stable_id).errors([])).to eq([{ type: :not_available }]) }
end
describe '#sources' do
let(:champ) { create(:champ) }
it { expect(champ_value(champ.stable_id).sources).to eq([champ.stable_id]) }
end
context 'with multiple revision' do
let(:options) { ['revision_1'] }
let(:procedure) do

View file

@ -21,4 +21,8 @@ describe Logic::Constant do
it { expect(constant(1)).to eq(constant(1)) }
it { expect(constant(1)).not_to eq(constant('a')) }
end
describe '#sources' do
it { expect(constant(1).sources).to eq([]) }
end
end

View file

@ -17,4 +17,8 @@ describe Logic::Constant do
describe '#to_s' do
it { expect(empty.to_s).to eq('un membre vide') }
end
describe '#sources' do
it { expect(empty.sources).to eq([]) }
end
end

View file

@ -23,6 +23,10 @@ describe Logic::NAryOperator do
end
end
describe '#sources' do
it { expect(and_from([false, true]).sources).to eq([]) }
end
def and_from(boolean_to_constants)
ds_and(boolean_to_constants.map { |b| constant(b) })
end