diff --git a/app/models/logic/binary_operator.rb b/app/models/logic/binary_operator.rb index 1af4c8129..d33d1088d 100644 --- a/app/models/logic/binary_operator.rb +++ b/app/models/logic/binary_operator.rb @@ -1,22 +1,20 @@ class Logic::BinaryOperator < Logic::Term attr_reader :left, :right - def initialize(left, right, id = nil) + def initialize(left, right) @left, @right = left, right - super(id) end def to_h { "term" => self.class.name, "left" => @left.to_h, - "right" => @right.to_h, - "id" => @id + "right" => @right.to_h } end def self.from_h(h) - self.new(Logic.from_h(h['left']), Logic.from_h(h['right']), h['id']) + self.new(Logic.from_h(h['left']), Logic.from_h(h['right'])) end def errors(stable_ids = []) diff --git a/app/models/logic/champ_value.rb b/app/models/logic/champ_value.rb index ad7197960..ae8c71555 100644 --- a/app/models/logic/champ_value.rb +++ b/app/models/logic/champ_value.rb @@ -17,9 +17,8 @@ class Logic::ChampValue < Logic::Term attr_reader :stable_id - def initialize(stable_id, id = nil) + def initialize(stable_id) @stable_id = stable_id - super(id) end def compute(champs) @@ -61,13 +60,12 @@ class Logic::ChampValue < Logic::Term def to_h { "term" => self.class.name, - "stable_id" => @stable_id, - "id" => @id + "stable_id" => @stable_id } end def self.from_h(h) - self.new(h['stable_id'], h['id']) + self.new(h['stable_id']) end def ==(other) diff --git a/app/models/logic/constant.rb b/app/models/logic/constant.rb index ae54e58fe..ce27d77d8 100644 --- a/app/models/logic/constant.rb +++ b/app/models/logic/constant.rb @@ -1,9 +1,8 @@ class Logic::Constant < Logic::Term attr_reader :value - def initialize(value, id = nil) + def initialize(value) @value = value - super(id) end def compute(_champs = nil) = @value @@ -35,13 +34,12 @@ class Logic::Constant < Logic::Term def to_h { "term" => self.class.name, - "value" => @value, - "id" => @id + "value" => @value } end def self.from_h(h) - self.new(h['value'], h['id']) + self.new(h['value']) end def ==(other) diff --git a/app/models/logic/empty.rb b/app/models/logic/empty.rb index ea4961be3..08a92a101 100644 --- a/app/models/logic/empty.rb +++ b/app/models/logic/empty.rb @@ -1,8 +1,4 @@ class Logic::Empty < Logic::Term - def initialize(id = nil) - super(id) - end - def to_s = I18n.t('logic.empty') def type = :empty @@ -11,13 +7,12 @@ class Logic::Empty < Logic::Term def to_h { - "term" => self.class.name, - "id" => @id + "term" => self.class.name } end - def self.from_h(h) - self.new(h['id']) + def self.from_h(_h) + self.new end def ==(other) diff --git a/app/models/logic/n_ary_operator.rb b/app/models/logic/n_ary_operator.rb index 0e7eb94c8..8e274acb8 100644 --- a/app/models/logic/n_ary_operator.rb +++ b/app/models/logic/n_ary_operator.rb @@ -1,21 +1,19 @@ class Logic::NAryOperator < Logic::Term attr_reader :operands - def initialize(operands, id = nil) + def initialize(operands) @operands = operands - super(id) end def to_h { "term" => self.class.name, - "operands" => @operands.map(&:to_h), - "id" => @id + "operands" => @operands.map(&:to_h) } end def self.from_h(h) - self.new(h['operands'].map { |operand_h| Logic.from_h(operand_h) }, h['id']) + self.new(h['operands'].map { |operand_h| Logic.from_h(operand_h) }) end def errors(stable_ids = []) diff --git a/app/models/logic/term.rb b/app/models/logic/term.rb index a55c1d14a..3cbed35a6 100644 --- a/app/models/logic/term.rb +++ b/app/models/logic/term.rb @@ -1,10 +1,4 @@ class Logic::Term - attr_reader :id - - def initialize(id = nil) - @id = id || SecureRandom.uuid - end - def to_json to_h.to_json end diff --git a/spec/models/logic_spec.rb b/spec/models/logic_spec.rb index ae6921eae..c7ba00e4e 100644 --- a/spec/models/logic_spec.rb +++ b/spec/models/logic_spec.rb @@ -15,18 +15,6 @@ describe Logic do .to eq(ds_and([constant(true), constant(true), constant(false)])) end - it 'saves its id' do - [ - constant(1), - empty, - champ_value(1), - ds_eq(empty, empty), - ds_and([constant(true), constant(true)]) - ].each do |term| - expect(Logic.from_h(term.to_h).id).to eq(term.id) - end - end - describe '.ensure_compatibility_from_left' do subject { Logic.ensure_compatibility_from_left(condition) }