diff --git a/app/components/types_de_champ_editor/conditions_component.rb b/app/components/types_de_champ_editor/conditions_component.rb index fa32a37e3..8e643384b 100644 --- a/app/components/types_de_champ_editor/conditions_component.rb +++ b/app/components/types_de_champ_editor/conditions_component.rb @@ -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] diff --git a/app/models/logic.rb b/app/models/logic.rb index 9888097bd..8f2787754 100644 --- a/app/models/logic.rb +++ b/app/models/logic.rb @@ -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) diff --git a/app/models/logic/not_eq.rb b/app/models/logic/not_eq.rb new file mode 100644 index 000000000..b11ec1c92 --- /dev/null +++ b/app/models/logic/not_eq.rb @@ -0,0 +1,3 @@ +class Logic::NotEq < Logic::Eq + def operation = :!= +end diff --git a/config/locales/models/logic/fr.yml b/config/locales/models/logic/fr.yml index 40eeb5f9f..28fb32923 100644 --- a/config/locales/models/logic/fr.yml +++ b/config/locales/models/logic/fr.yml @@ -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 à diff --git a/spec/models/logic/not_eq_spec.rb b/spec/models/logic/not_eq_spec.rb new file mode 100644 index 000000000..c789bbd05 --- /dev/null +++ b/spec/models/logic/not_eq_spec.rb @@ -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