Merge pull request #7670 from betagouv/add_is_not_eq
feat(conditional): ajoute l'operateur "n'est pas égal" s'appliquant à un choix parmis une liste
This commit is contained in:
commit
354248c88a
5 changed files with 26 additions and 2 deletions
|
@ -111,7 +111,8 @@ class TypesDeChampEditor::ConditionsComponent < ApplicationComponent
|
|||
]
|
||||
when ChampValue::CHAMP_VALUE_TYPE.fetch(:enum)
|
||||
[
|
||||
[t('is', scope: 'logic'), Eq.name]
|
||||
[t('is', scope: 'logic'), Eq.name],
|
||||
[t('is_not', scope: 'logic'), NotEq.name]
|
||||
]
|
||||
when ChampValue::CHAMP_VALUE_TYPE.fetch(:number)
|
||||
[Eq, LessThan, GreaterThan, LessThanEq, GreaterThanEq]
|
||||
|
|
|
@ -8,7 +8,7 @@ module Logic
|
|||
end
|
||||
|
||||
def self.class_from_name(name)
|
||||
[ChampValue, Constant, Empty, LessThan, LessThanEq, Eq, GreaterThanEq, GreaterThan, EmptyOperator, And, Or]
|
||||
[ChampValue, Constant, Empty, LessThan, LessThanEq, Eq, NotEq, GreaterThanEq, GreaterThan, EmptyOperator, And, Or]
|
||||
.find { |c| c.name == name }
|
||||
end
|
||||
|
||||
|
@ -74,6 +74,8 @@ module Logic
|
|||
|
||||
def ds_eq(left, right) = Logic::Eq.new(left, right)
|
||||
|
||||
def ds_not_eq(left, right) = Logic::NotEq.new(left, right)
|
||||
|
||||
def greater_than(left, right) = Logic::GreaterThan.new(left, right)
|
||||
|
||||
def greater_than_eq(left, right) = Logic::GreaterThanEq.new(left, right)
|
||||
|
|
3
app/models/logic/not_eq.rb
Normal file
3
app/models/logic/not_eq.rb
Normal file
|
@ -0,0 +1,3 @@
|
|||
class Logic::NotEq < Logic::Eq
|
||||
def operation = :!=
|
||||
end
|
|
@ -2,6 +2,7 @@ fr:
|
|||
logic:
|
||||
empty: un membre vide
|
||||
is: Est
|
||||
is_not: N’est pas
|
||||
operators:
|
||||
'Logic::LessThan': Inférieur à
|
||||
'Logic::LessThanEq': Inférieur ou égal à
|
||||
|
|
17
spec/models/logic/not_eq_spec.rb
Normal file
17
spec/models/logic/not_eq_spec.rb
Normal file
|
@ -0,0 +1,17 @@
|
|||
describe Logic::NotEq do
|
||||
include Logic
|
||||
|
||||
describe '#compute' do
|
||||
it { expect(ds_not_eq(constant(1), constant(1)).compute).to be(false) }
|
||||
it { expect(ds_not_eq(constant(1), constant(2)).compute).to be(true) }
|
||||
end
|
||||
|
||||
describe '#errors' do
|
||||
it { expect(ds_not_eq(constant(true), constant(true)).errors).to be_empty }
|
||||
it { expect(ds_not_eq(constant(true), constant(1)).errors).to eq(["les types sont incompatibles : (Oui != 1)"]) }
|
||||
end
|
||||
|
||||
describe '#==' do
|
||||
it { expect(ds_not_eq(constant(true), constant(false))).to eq(ds_not_eq(constant(false), constant(true))) }
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue