diff --git a/app/models/procedure.rb b/app/models/procedure.rb index 99482064b..9e7121655 100644 --- a/app/models/procedure.rb +++ b/app/models/procedure.rb @@ -245,7 +245,7 @@ class Procedure < ApplicationRecord validates :description, presence: true, allow_blank: false, allow_nil: false validates :administrateurs, presence: true validates :lien_site_web, presence: true, if: :publiee? - validates :draft_revision, + validates :draft_types_de_champ, 'revisions/no_empty_repetition': true, 'revisions/no_empty_drop_down': true, if: :validate_for_publication? diff --git a/app/validators/revisions/no_empty_drop_down_validator.rb b/app/validators/revisions/no_empty_drop_down_validator.rb index 86e257e34..4917a2006 100644 --- a/app/validators/revisions/no_empty_drop_down_validator.rb +++ b/app/validators/revisions/no_empty_drop_down_validator.rb @@ -1,10 +1,6 @@ class Revisions::NoEmptyDropDownValidator < ActiveModel::EachValidator - def validate_each(procedure, attribute, revision) - return if revision.nil? - - tdcs = revision.types_de_champ + revision.types_de_champ_private - drop_downs = tdcs.filter(&:drop_down_list?) - drop_downs.each do |drop_down| + def validate_each(procedure, attribute, types_de_champ) + types_de_champ.filter(&:drop_down_list?).each do |drop_down| validate_drop_down_not_empty(procedure, attribute, drop_down) end end diff --git a/app/validators/revisions/no_empty_repetition_validator.rb b/app/validators/revisions/no_empty_repetition_validator.rb index ba8bf85c7..5bc3de49a 100644 --- a/app/validators/revisions/no_empty_repetition_validator.rb +++ b/app/validators/revisions/no_empty_repetition_validator.rb @@ -1,10 +1,6 @@ class Revisions::NoEmptyRepetitionValidator < ActiveModel::EachValidator - def validate_each(procedure, attribute, revision) - return if revision.nil? - - revision_tdcs = revision.types_de_champ + revision.types_de_champ_private - repetitions = revision_tdcs.filter(&:repetition?) - repetitions.each do |repetition| + def validate_each(procedure, attribute, types_de_champ) + types_de_champ.filter(&:repetition?).each do |repetition| validate_repetition_not_empty(procedure, attribute, repetition) end end diff --git a/app/views/administrateurs/procedures/show.html.haml b/app/views/administrateurs/procedures/show.html.haml index 3c5059cfb..dae702a7e 100644 --- a/app/views/administrateurs/procedures/show.html.haml +++ b/app/views/administrateurs/procedures/show.html.haml @@ -53,7 +53,7 @@ - if !@procedure.locked? || @procedure.feature_enabled?(:procedure_revisions) - @procedure.validate(:publication) - - error_messages = @procedure.errors.messages_for(:draft_revision).to_sentence + - error_messages = @procedure.errors.messages_for(:draft_types_de_champ).to_sentence = link_to champs_admin_procedure_path(@procedure), class: 'card-admin', title: error_messages do - if @procedure.draft_types_de_champ.count == 0 diff --git a/config/locales/fr.yml b/config/locales/fr.yml index 51c6641fd..4c230ae37 100644 --- a/config/locales/fr.yml +++ b/config/locales/fr.yml @@ -328,8 +328,8 @@ fr: connexion: "Erreur lors de la connexion à France Connect." forbidden_html: "Seul-e-s les usagers peuvent se connecter via France Connect. En tant qu’instructeur ou administrateur, nous vous invitons à réininitialiser votre mot de passe." procedure_archived: "Cette démarche en ligne a été close, il n’est plus possible de déposer de dossier." - empty_repetition: 'Le bloc répétable « %{value} » doit comporter au moins un champ' - empty_drop_down: 'La liste de choix « %{value} » doit comporter au moins un choix sélectionnable' + 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." cadastres_empty: one: "Aucune parcelle cadastrale sur la zone sélectionnée" diff --git a/config/locales/models/procedure/fr.yml b/config/locales/models/procedure/fr.yml index 332e3114b..054155a50 100644 --- a/config/locales/models/procedure/fr.yml +++ b/config/locales/models/procedure/fr.yml @@ -23,5 +23,5 @@ fr: attributes: api_particulier_token: invalid: 'n’a pas le bon format' - draft_revision: - format: '%{message}' + draft_types_de_champ: + format: 'Le champ %{message}' diff --git a/spec/models/procedure_spec.rb b/spec/models/procedure_spec.rb index d940f07a3..7c36a8d40 100644 --- a/spec/models/procedure_spec.rb +++ b/spec/models/procedure_spec.rb @@ -302,17 +302,17 @@ describe Procedure do describe 'draft_revision' do let(:repetition) { build(:type_de_champ_repetition, libelle: 'Enfants') } let(:text_field) { build(:type_de_champ_text) } - let(:invalid_repetition_error_message) { 'Le bloc répétable « Enfants » doit comporter au moins un champ' } + let(:invalid_repetition_error_message) { 'Le champ « Enfants » doit comporter au moins un champ répétable' } let(:drop_down) { build(:type_de_champ_drop_down_list, :without_selectable_values, libelle: 'Civilité') } - let(:invalid_drop_down_error_message) { 'La liste de choix « Civilité » doit comporter au moins un choix sélectionnable' } + let(:invalid_drop_down_error_message) { 'Le champ « Civilité » doit comporter au moins un choix sélectionnable' } let(:procedure) { create(:procedure, types_de_champ: [repetition, drop_down]) } context 'on a draft procedure' do it 'doesn’t validate the draft revision' do procedure.validate - expect(procedure.errors[:draft_revision]).not_to be_present + expect(procedure.errors[:draft_types_de_champ]).not_to be_present end end @@ -321,35 +321,35 @@ describe Procedure do it 'validates that no repetition type de champ is empty' do procedure.validate - expect(procedure.errors.full_messages_for(:draft_revision)).to include(invalid_repetition_error_message) + expect(procedure.errors.full_messages_for(:draft_types_de_champ)).to include(invalid_repetition_error_message) text_field.revision = repetition.revision text_field.order_place = repetition.types_de_champ.size - procedure.draft_revision.types_de_champ.find(&:repetition?).types_de_champ << text_field + procedure.draft_types_de_champ.find(&:repetition?).types_de_champ << text_field procedure.validate - expect(procedure.errors.full_messages_for(:draft_revision)).not_to include(invalid_repetition_error_message) + expect(procedure.errors.full_messages_for(:draft_types_de_champ)).not_to include(invalid_repetition_error_message) end it 'validates that no drop-down type de champ is empty' do procedure.validate - expect(procedure.errors.full_messages_for(:draft_revision)).to include(invalid_drop_down_error_message) + expect(procedure.errors.full_messages_for(:draft_types_de_champ)).to include(invalid_drop_down_error_message) drop_down.update!(drop_down_list_value: "--title--\r\nsome value") procedure.reload.validate - expect(procedure.errors.full_messages_for(:draft_revision)).not_to include(invalid_drop_down_error_message) + expect(procedure.errors.full_messages_for(:draft_types_de_champ)).not_to include(invalid_drop_down_error_message) end end context 'when validating for publication' do it 'validates that no repetition type de champ is empty' do procedure.validate(:publication) - expect(procedure.errors.full_messages_for(:draft_revision)).to include(invalid_repetition_error_message) + expect(procedure.errors.full_messages_for(:draft_types_de_champ)).to include(invalid_repetition_error_message) end it 'validates that no drop-down type de champ is empty' do procedure.validate(:publication) - expect(procedure.errors.full_messages_for(:draft_revision)).to include(invalid_drop_down_error_message) + expect(procedure.errors.full_messages_for(:draft_types_de_champ)).to include(invalid_drop_down_error_message) end end end diff --git a/spec/system/administrateurs/procedure_publish_spec.rb b/spec/system/administrateurs/procedure_publish_spec.rb index dc8f6c14a..e27c4cf78 100644 --- a/spec/system/administrateurs/procedure_publish_spec.rb +++ b/spec/system/administrateurs/procedure_publish_spec.rb @@ -47,7 +47,7 @@ describe 'Publishing a procedure', js: true do end context 'when the procedure has invalid champs' do - let(:empty_repetition) { build(:type_de_champ_repetition, types_de_champ: []) } + let(:empty_repetition) { build(:type_de_champ_repetition, types_de_champ: [], libelle: 'Enfants') } let!(:procedure) do create(:procedure, :with_path, @@ -59,7 +59,7 @@ describe 'Publishing a procedure', js: true do scenario 'an error message prevents the publication' do expect(page).to have_content('Des problèmes empêchent la publication de la démarche') - expect(page).to have_content("Le bloc répétable « #{empty_repetition.libelle} » doit comporter au moins un champ") + expect(page).to have_content("Le champ « Enfants » doit comporter au moins un champ répétable") expect(find_field('procedure_path').value).to eq procedure.path fill_in 'lien_site_web', with: 'http://some.website'