refactor(condition): use standard revision change ops

This commit is contained in:
Paul Chavard 2022-07-13 15:32:25 +02:00
parent 2cad0e11d3
commit 0adfd92213
3 changed files with 32 additions and 46 deletions

View file

@ -378,27 +378,17 @@ class ProcedureRevision < ApplicationRecord
}
end
from_condition = from_type_de_champ.condition
to_condition = to_type_de_champ.condition
if from_condition != to_condition
condition_change = {
if from_type_de_champ.condition != to_type_de_champ.condition
changes << {
model: :type_de_champ,
op: :update,
attribute: :condition,
label: from_type_de_champ.libelle,
private: from_type_de_champ.private?,
from: from_type_de_champ.condition.to_s,
to: to_type_de_champ.condition.to_s,
from: from_type_de_champ.condition&.to_s,
to: to_type_de_champ.condition&.to_s,
stable_id: from_type_de_champ.stable_id
}
if from_condition.nil?
condition_change[:condition_op] = :add
elsif to_condition.nil?
condition_change[:condition_op] = :remove
else
condition_change[:condition_op] = :update
end
changes << condition_change
end
if to_type_de_champ.drop_down_list?

View file

@ -55,10 +55,9 @@
- if removed.present?
%li= t(:remove_option, scope: [:administrateurs, :revision_changes], items: removed.map{ |term| "« #{t(term, scope: [:administrateurs, :carte_layers])} »" }.join(", "))
- when :condition
- case change[:condition_op]
- when :add
- if change[:from].nil?
%li= t(:add_condition, scope: [:administrateurs, :revision_changes], label: change[:label], to: change[:to])
- when :remove
%li= t(:remove_condition, scope: [:administrateurs, :revision_changes], label: change[:label], to: change[:to])
- when :update
- elsif change[:to].nil?
%li= t(:remove_condition, scope: [:administrateurs, :revision_changes], label: change[:label])
- else
%li= t(:update_condition, scope: [:administrateurs, :revision_changes], label: change[:label], to: change[:to])

View file

@ -347,15 +347,14 @@ describe ProcedureRevision do
it do
is_expected.to eq([
{
:attribute => :condition,
:condition_op => :add,
:from => "",
:label => "l2",
:model => :type_de_champ,
:op => :update,
:private => false,
:stable_id => second_tdc.stable_id,
:to => "(l1 == 3)"
attribute: :condition,
from: nil,
label: "l2",
model: :type_de_champ,
op: :update,
private: false,
stable_id: second_tdc.stable_id,
to: "(l1 == 3)"
}
])
end
@ -373,15 +372,14 @@ describe ProcedureRevision do
it do
is_expected.to eq([
{
:attribute => :condition,
:condition_op => :remove,
:from => "(l1 == 2)",
:label => "l2",
:model => :type_de_champ,
:op => :update,
:private => false,
:stable_id => second_tdc.stable_id,
:to => ""
attribute: :condition,
from: "(l1 == 2)",
label: "l2",
model: :type_de_champ,
op: :update,
private: false,
stable_id: second_tdc.stable_id,
to: nil
}
])
end
@ -399,15 +397,14 @@ describe ProcedureRevision do
it do
is_expected.to eq([
{
:attribute => :condition,
:condition_op => :update,
:from => "(l1 == 2)",
:label => "l2",
:model => :type_de_champ,
:op => :update,
:private => false,
:stable_id => second_tdc.stable_id,
:to => "(l1 == 3)"
attribute: :condition,
from: "(l1 == 2)",
label: "l2",
model: :type_de_champ,
op: :update,
private: false,
stable_id: second_tdc.stable_id,
to: "(l1 == 3)"
}
])
end