errors
This commit is contained in:
parent
70022450cf
commit
12b6a0d6d6
12 changed files with 23 additions and 23 deletions
|
@ -7,7 +7,7 @@ class TypesDeChampEditor::ConditionsErrorsComponent < ApplicationComponent
|
|||
|
||||
def errors
|
||||
@conditions
|
||||
.flat_map { |condition| condition.errors(@upper_tdcs.map(&:stable_id)) }
|
||||
.flat_map { |condition| condition.errors(@upper_tdcs) }
|
||||
.map { |error| humanize(error) }
|
||||
.uniq
|
||||
.map { |message| tag.li(message) }
|
||||
|
@ -48,7 +48,7 @@ class TypesDeChampEditor::ConditionsErrorsComponent < ApplicationComponent
|
|||
|
||||
def render?
|
||||
@conditions
|
||||
.filter { |condition| condition.errors(@upper_tdcs.map(&:stable_id)).present? }
|
||||
.filter { |condition| condition.errors(@upper_tdcs).present? }
|
||||
.present?
|
||||
end
|
||||
end
|
||||
|
|
|
@ -17,14 +17,14 @@ class Logic::BinaryOperator < Logic::Term
|
|||
self.new(Logic.from_h(h['left']), Logic.from_h(h['right']))
|
||||
end
|
||||
|
||||
def errors(stable_ids = [])
|
||||
def errors(type_de_champs = [])
|
||||
errors = []
|
||||
|
||||
if @left.type(type_de_champs) != :number || @right.type(type_de_champs) != :number
|
||||
errors << { type: :required_number, operator_name: self.class.name }
|
||||
end
|
||||
|
||||
errors + @left.errors(stable_ids) + @right.errors(stable_ids)
|
||||
errors + @left.errors(type_de_champs) + @right.errors(type_de_champs)
|
||||
end
|
||||
|
||||
def type(type_de_champs = []) = :boolean
|
||||
|
|
|
@ -60,8 +60,8 @@ class Logic::ChampValue < Logic::Term
|
|||
end
|
||||
end
|
||||
|
||||
def errors(stable_ids)
|
||||
if !stable_ids.include?(stable_id)
|
||||
def errors(type_de_champs)
|
||||
if !type_de_champs.map(&:stable_id).include?(stable_id)
|
||||
[{ type: :not_available }]
|
||||
else
|
||||
[]
|
||||
|
|
|
@ -29,7 +29,7 @@ class Logic::Constant < Logic::Term
|
|||
end
|
||||
end
|
||||
|
||||
def errors(_stable_ids = nil) = []
|
||||
def errors(_type_de_champs = nil) = []
|
||||
|
||||
def to_h
|
||||
{
|
||||
|
|
|
@ -3,7 +3,7 @@ class Logic::Empty < Logic::Term
|
|||
|
||||
def type(_type_de_champs = []) = :empty
|
||||
|
||||
def errors(_stable_ids = nil) = ['empty']
|
||||
def errors(_type_de_champs = []) = ['empty']
|
||||
|
||||
def to_h
|
||||
{
|
||||
|
|
|
@ -3,7 +3,7 @@ class Logic::EmptyOperator < Logic::BinaryOperator
|
|||
|
||||
def type(_type_de_champs = []) = :empty
|
||||
|
||||
def errors(_stable_ids = nil) = []
|
||||
def errors(_type_de_champs = []) = []
|
||||
|
||||
def compute(_champs = [])
|
||||
true
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
class Logic::Eq < Logic::BinaryOperator
|
||||
def operation = :==
|
||||
|
||||
def errors(stable_ids = [])
|
||||
def errors(type_de_champs = [])
|
||||
errors = [@left, @right]
|
||||
.filter { |term| term.type(type_de_champs) == :unmanaged }
|
||||
.map { |term| { type: :unmanaged, stable_id: term.stable_id } }
|
||||
|
@ -22,7 +22,7 @@ class Logic::Eq < Logic::BinaryOperator
|
|||
}
|
||||
end
|
||||
|
||||
errors + @left.errors(stable_ids) + @right.errors(stable_ids)
|
||||
errors + @left.errors(type_de_champs) + @right.errors(type_de_champs)
|
||||
end
|
||||
|
||||
def ==(other)
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
class Logic::IncludeOperator < Logic::BinaryOperator
|
||||
def operation = :include?
|
||||
|
||||
def errors(stable_ids = [])
|
||||
def errors(type_de_champs = [])
|
||||
result = []
|
||||
|
||||
if left_not_a_list?(type_de_champs)
|
||||
|
@ -14,7 +14,7 @@ class Logic::IncludeOperator < Logic::BinaryOperator
|
|||
}
|
||||
end
|
||||
|
||||
result + @left.errors(stable_ids) + @right.errors(stable_ids)
|
||||
result + @left.errors(type_de_champs) + @right.errors(type_de_champs)
|
||||
end
|
||||
|
||||
private
|
||||
|
|
|
@ -16,7 +16,7 @@ class Logic::NAryOperator < Logic::Term
|
|||
self.new(h['operands'].map { |operand_h| Logic.from_h(operand_h) })
|
||||
end
|
||||
|
||||
def errors(stable_ids = [])
|
||||
def errors(type_de_champs = [])
|
||||
errors = []
|
||||
|
||||
if @operands.empty?
|
||||
|
@ -28,7 +28,7 @@ class Logic::NAryOperator < Logic::Term
|
|||
errors += ["'#{operator_name}' ne contient pas que des booléens : #{not_booleans.map(&:to_s).join(', ')}"]
|
||||
end
|
||||
|
||||
errors + @operands.flat_map { |operand| operand.errors(stable_ids) }
|
||||
errors + @operands.flat_map { |operand| operand.errors(type_de_champs) }
|
||||
end
|
||||
|
||||
def type(_type_de_champs = []) = :boolean
|
||||
|
|
|
@ -479,12 +479,12 @@ class ProcedureRevision < ApplicationRecord
|
|||
end
|
||||
|
||||
def conditions_are_valid?
|
||||
stable_ids = types_de_champ_public.map(&:stable_id)
|
||||
public_tdcs = types_de_champ_public.to_a
|
||||
|
||||
types_de_champ_public
|
||||
public_tdcs
|
||||
.map.with_index
|
||||
.filter_map { |tdc, i| tdc.condition.present? ? [tdc, i] : nil }
|
||||
.map { |tdc, i| [tdc, tdc.condition.errors(stable_ids.take(i))] }
|
||||
.map { |tdc, i| [tdc, tdc.condition.errors(public_tdcs.take(i))] }
|
||||
.filter { |_tdc, errors| errors.present? }
|
||||
.each { |tdc, message| errors.add(:condition, message, type_de_champ: tdc) }
|
||||
end
|
||||
|
|
|
@ -79,7 +79,7 @@ describe Logic::ChampValue do
|
|||
describe 'errors' do
|
||||
let(:champ) { create(:champ) }
|
||||
|
||||
it { expect(champ_value(champ.stable_id).errors([champ.stable_id])).to be_empty }
|
||||
it { expect(champ_value(champ.stable_id).errors(['other stable ids'])).to eq([{ type: :not_available }]) }
|
||||
it { expect(champ_value(champ.stable_id).errors([champ.type_de_champ])).to be_empty }
|
||||
it { expect(champ_value(champ.stable_id).errors([])).to eq([{ type: :not_available }]) }
|
||||
end
|
||||
end
|
||||
|
|
|
@ -9,7 +9,7 @@ describe Logic::IncludeOperator do
|
|||
end
|
||||
|
||||
describe '#errors' do
|
||||
it { expect(ds_include(champ_value(champ.stable_id), constant('val1')).errors([champ.stable_id])).to be_empty }
|
||||
it { expect(ds_include(champ_value(champ.stable_id), constant('val1')).errors([champ.type_de_champ])).to be_empty }
|
||||
it do
|
||||
expected = {
|
||||
right: constant('something else'),
|
||||
|
@ -17,10 +17,10 @@ describe Logic::IncludeOperator do
|
|||
type: :not_included
|
||||
}
|
||||
|
||||
expect(ds_include(champ_value(champ.stable_id), constant('something else')).errors([champ.stable_id])).to eq([expected])
|
||||
expect(ds_include(champ_value(champ.stable_id), constant('something else')).errors([champ.type_de_champ])).to eq([expected])
|
||||
end
|
||||
|
||||
it { expect(ds_include(constant(1), constant('val1')).errors).to eq([{ type: :required_list }]) }
|
||||
it { expect(ds_include(constant(1), constant('val1')).errors([])).to eq([{ type: :required_list }]) }
|
||||
end
|
||||
|
||||
describe '#==' do
|
||||
|
|
Loading…
Add table
Reference in a new issue