diff --git a/app/models/concerns/dossier_rebase_concern.rb b/app/models/concerns/dossier_rebase_concern.rb index 90c0909a0..8b0ab50ba 100644 --- a/app/models/concerns/dossier_rebase_concern.rb +++ b/app/models/concerns/dossier_rebase_concern.rb @@ -32,6 +32,10 @@ module DossierRebaseConcern !champs.filter { _1.stable_id == stable_id }.any? { _1.in?(options) } end + def can_rebase_expression_reguliere_change?(stable_id, expression_reguliere) + false + end + private def accepted_en_construction_changes? diff --git a/app/models/procedure_revision_change.rb b/app/models/procedure_revision_change.rb index 8079c8cdb..2bb4a95f9 100644 --- a/app/models/procedure_revision_change.rb +++ b/app/models/procedure_revision_change.rb @@ -60,7 +60,6 @@ class ProcedureRevisionChange def can_rebase?(dossier = nil) return true if private? - case attribute when :drop_down_options (from - to).empty? || dossier&.can_rebase_drop_down_options_change?(stable_id, from - to) @@ -68,7 +67,7 @@ class ProcedureRevisionChange !from && to when :mandatory (from && !to) || dossier&.can_rebase_mandatory_change?(stable_id) - when :type_champ, :condition + when :type_champ, :condition, :expression_reguliere false else true diff --git a/app/validators/expression_reguliere_validator.rb b/app/validators/expression_reguliere_validator.rb index 7ba53525a..72994f767 100644 --- a/app/validators/expression_reguliere_validator.rb +++ b/app/validators/expression_reguliere_validator.rb @@ -2,7 +2,7 @@ class ExpressionReguliereValidator < ActiveModel::Validator def validate(record) if record.value.present? if !record.value.match?(Regexp.new(record.expression_reguliere, timeout: 5.0)) - record.errors.add(:value, I18n.t('errors.messages.invalid_regexp', expression_reguliere_error_message: record.expression_reguliere_error_message)) + record.errors.add(:value, :invalid_regexp) end end rescue Regexp::TimeoutError diff --git a/config/locales/en.yml b/config/locales/en.yml index f56eccf0b..b42a1b05e 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -687,7 +687,6 @@ en: evil_regexp: The regular expression you have entered is potentially dangerous and could lead to performance issues. mismatch_regexp: The provided example must match the regular expression syntax_error_regexp: The syntax of the regular expression is invalid - invalid_regexp: "%{expression_reguliere_error_message}" # # procedure_not_draft: "This procedure is not a draft anymore." # cadastres_empty: # one: "Aucune parcelle cadastrale sur la zone sélectionnée" diff --git a/config/locales/fr.yml b/config/locales/fr.yml index a3b2e23f6..080c89d98 100644 --- a/config/locales/fr.yml +++ b/config/locales/fr.yml @@ -692,7 +692,6 @@ fr: evil_regexp: L'expression régulière que vous avez entrée est potentiellement dangereuse et pourrait entraîner des problèmes de performance mismatch_regexp: L'exemple doit correspondre à l'expression régulière fournie syntax_error_regexp: La syntaxe de l'expression régulière n'est pas valide - invalid_regexp: "%{expression_reguliere_error_message}" empty_repetition: '« %{value} » doit comporter au moins un champ répétable' empty_drop_down: '« %{value} » doit comporter au moins un choix sélectionnable' # procedure_not_draft: "Cette démarche n’est maintenant plus en brouillon." diff --git a/spec/models/concern/dossier_rebase_concern_spec.rb b/spec/models/concern/dossier_rebase_concern_spec.rb index d43a9c339..3a90ff4b4 100644 --- a/spec/models/concern/dossier_rebase_concern_spec.rb +++ b/spec/models/concern/dossier_rebase_concern_spec.rb @@ -124,6 +124,21 @@ describe DossierRebaseConcern do end end + context 'with type de champ regexp and regexp change' do + let(:procedure) { create(:procedure, types_de_champ_public: [{ mandatory: true }, { type: :expression_reguliere }], types_de_champ_private: [{}]) } + + before do + procedure.draft_revision.find_and_ensure_exclusive_use(type_de_champ.stable_id).update(expression_reguliere: /\d+/) + procedure.publish_revision! + dossier.reload + end + + it 'should be false' do + expect(dossier.pending_changes).not_to be_empty + expect(dossier.can_rebase?).to be_falsey + end + end + context 'with removed type de champ' do before do procedure.draft_revision.remove_type_de_champ(type_de_champ.stable_id) diff --git a/spec/models/dossier_spec.rb b/spec/models/dossier_spec.rb index 30a00691b..e6a332d6c 100644 --- a/spec/models/dossier_spec.rb +++ b/spec/models/dossier_spec.rb @@ -1604,13 +1604,11 @@ describe Dossier, type: :model do before do champ = dossier.champs_public.first champ.value = expression_reguliere_exemple_text - champ.save! - dossier.reload + dossier.save end it 'should not have errors' do - expect(errors).not_to be_empty - expect(errors.first).to be_nil + expect(dossier.errors).to be_empty end end end