feat(conditional): add exclude operator
This commit is contained in:
parent
ba17f8d8aa
commit
f945c02c3c
6 changed files with 39 additions and 3 deletions
|
@ -99,7 +99,8 @@ class Conditions::ConditionsComponent < ApplicationComponent
|
|||
]
|
||||
when ChampValue::CHAMP_VALUE_TYPE.fetch(:enums)
|
||||
[
|
||||
[t(IncludeOperator.name, scope: 'logic.operators'), IncludeOperator.name]
|
||||
[t(IncludeOperator.name, scope: 'logic.operators'), IncludeOperator.name],
|
||||
[t(ExcludeOperator.name, scope: 'logic.operators'), ExcludeOperator.name]
|
||||
]
|
||||
when ChampValue::CHAMP_VALUE_TYPE.fetch(:number)
|
||||
[Eq, LessThan, GreaterThan, LessThanEq, GreaterThanEq]
|
||||
|
|
|
@ -92,7 +92,7 @@ class GroupeInstructeur < ApplicationRecord
|
|||
end
|
||||
|
||||
def valid_rule_line?(rule)
|
||||
([rule.left, rule, rule.right] in [ChampValue, (LessThan | LessThanEq | Eq | NotEq | GreaterThanEq | GreaterThan | IncludeOperator), Constant]) && routing_rule_matches_tdc?(rule)
|
||||
([rule.left, rule, rule.right] in [ChampValue, (LessThan | LessThanEq | Eq | NotEq | GreaterThanEq | GreaterThan | IncludeOperator | ExcludeOperator), Constant]) && routing_rule_matches_tdc?(rule)
|
||||
end
|
||||
|
||||
def non_unique_rule?
|
||||
|
|
|
@ -8,7 +8,7 @@ module Logic
|
|||
end
|
||||
|
||||
def self.class_from_name(name)
|
||||
[ChampValue, Constant, Empty, LessThan, LessThanEq, Eq, NotEq, GreaterThanEq, GreaterThan, EmptyOperator, IncludeOperator, And, Or]
|
||||
[ChampValue, Constant, Empty, LessThan, LessThanEq, Eq, NotEq, GreaterThanEq, GreaterThan, EmptyOperator, IncludeOperator, ExcludeOperator, And, Or]
|
||||
.find { |c| c.name == name }
|
||||
end
|
||||
|
||||
|
@ -88,6 +88,8 @@ module Logic
|
|||
|
||||
def ds_include(left, right) = Logic::IncludeOperator.new(left, right)
|
||||
|
||||
def ds_exclude(left, right) = Logic::ExcludeOperator.new(left, right)
|
||||
|
||||
def constant(value) = Logic::Constant.new(value)
|
||||
|
||||
def champ_value(stable_id) = Logic::ChampValue.new(stable_id)
|
||||
|
|
3
app/models/logic/exclude_operator.rb
Normal file
3
app/models/logic/exclude_operator.rb
Normal file
|
@ -0,0 +1,3 @@
|
|||
class Logic::ExcludeOperator < Logic::IncludeOperator
|
||||
def operation = :exclude?
|
||||
end
|
|
@ -14,3 +14,4 @@ fr:
|
|||
'Logic::Or': Ou
|
||||
'Logic::NotEq': N’est pas
|
||||
'Logic::IncludeOperator': Contient
|
||||
'Logic::ExcludeOperator': Ne contient pas
|
||||
|
|
29
spec/models/logic/exclude_operator_spec.rb
Normal file
29
spec/models/logic/exclude_operator_spec.rb
Normal file
|
@ -0,0 +1,29 @@
|
|||
describe Logic::ExcludeOperator do
|
||||
include Logic
|
||||
|
||||
let(:champ) { create(:champ_multiple_drop_down_list, value: '["val1", "val2"]') }
|
||||
|
||||
describe '#compute' do
|
||||
it { expect(ds_exclude(champ_value(champ.stable_id), constant('val1')).compute([champ])).to be(false) }
|
||||
it { expect(ds_exclude(champ_value(champ.stable_id), constant('something else')).compute([champ])).to be(true) }
|
||||
end
|
||||
|
||||
describe '#errors' do
|
||||
it { expect(ds_exclude(champ_value(champ.stable_id), constant('val1')).errors([champ.type_de_champ])).to be_empty }
|
||||
it do
|
||||
expected = {
|
||||
right: constant('something else'),
|
||||
stable_id: champ.stable_id,
|
||||
type: :not_included
|
||||
}
|
||||
|
||||
expect(ds_exclude(champ_value(champ.stable_id), constant('something else')).errors([champ.type_de_champ])).to eq([expected])
|
||||
end
|
||||
|
||||
it { expect(ds_exclude(constant(1), constant('val1')).errors([])).to eq([{ type: :required_list }]) }
|
||||
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
|
Loading…
Reference in a new issue