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