diff --git a/app/models/procedure.rb b/app/models/procedure.rb index 9e7121655..e23adeb0c 100644 --- a/app/models/procedure.rb +++ b/app/models/procedure.rb @@ -249,6 +249,10 @@ class Procedure < ApplicationRecord 'revisions/no_empty_repetition': true, 'revisions/no_empty_drop_down': true, if: :validate_for_publication? + validates :draft_types_de_champ_private, + 'revisions/no_empty_repetition': true, + 'revisions/no_empty_drop_down': true, + if: :validate_for_publication? validate :check_juridique validates :path, presence: true, format: { with: /\A[a-z0-9_\-]{3,200}\z/ }, uniqueness: { scope: [:path, :closed_at, :hidden_at, :unpublished_at], case_sensitive: false } validates :duree_conservation_dossiers_dans_ds, allow_nil: false, numericality: { only_integer: true, greater_than_or_equal_to: 1, less_than_or_equal_to: MAX_DUREE_CONSERVATION } diff --git a/app/views/administrateurs/procedures/show.html.haml b/app/views/administrateurs/procedures/show.html.haml index dae702a7e..c0985cf4e 100644 --- a/app/views/administrateurs/procedures/show.html.haml +++ b/app/views/administrateurs/procedures/show.html.haml @@ -171,11 +171,18 @@ %p.button Modifier - if !@procedure.locked? || @procedure.feature_enabled?(:procedure_revisions) - = link_to annotations_admin_procedure_path(@procedure), class: 'card-admin' do + - @procedure.validate(:publication) + - error_messages = @procedure.errors.messages_for(:draft_types_de_champ_private).to_sentence + + = link_to annotations_admin_procedure_path(@procedure), class: 'card-admin', title: error_messages do - if @procedure.draft_types_de_champ_private.present? %div %span.icon.accept %p.card-admin-status-accept Validé + - elsif error_messages.present? + %div + %span.icon.refuse + %p.card-admin-status-error À modifier - else %div %span.icon.clock diff --git a/config/locales/models/procedure/fr.yml b/config/locales/models/procedure/fr.yml index 054155a50..752936742 100644 --- a/config/locales/models/procedure/fr.yml +++ b/config/locales/models/procedure/fr.yml @@ -25,3 +25,5 @@ fr: invalid: 'n’a pas le bon format' draft_types_de_champ: format: 'Le champ %{message}' + draft_types_de_champ_private: + format: 'L’annotation privée %{message}' diff --git a/spec/models/procedure_spec.rb b/spec/models/procedure_spec.rb index 7c36a8d40..7e208bb62 100644 --- a/spec/models/procedure_spec.rb +++ b/spec/models/procedure_spec.rb @@ -352,6 +352,23 @@ describe Procedure do expect(procedure.errors.full_messages_for(:draft_types_de_champ)).to include(invalid_drop_down_error_message) end end + + context 'when the champ is private' do + let(:procedure) { create(:procedure, types_de_champ_private: [repetition, drop_down]) } + + let(:invalid_repetition_error_message) { 'L’annotation privée « Enfants » doit comporter au moins un champ répétable' } + let(:invalid_drop_down_error_message) { 'L’annotation privée « Civilité » doit comporter au moins un choix sélectionnable' } + + it 'validates that no repetition type de champ is empty' do + procedure.validate(:publication) + expect(procedure.errors.full_messages_for(:draft_types_de_champ_private)).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_types_de_champ_private)).to include(invalid_drop_down_error_message) + end + end end end diff --git a/spec/system/administrateurs/procedure_publish_spec.rb b/spec/system/administrateurs/procedure_publish_spec.rb index e27c4cf78..21e6192c2 100644 --- a/spec/system/administrateurs/procedure_publish_spec.rb +++ b/spec/system/administrateurs/procedure_publish_spec.rb @@ -48,18 +48,22 @@ describe 'Publishing a procedure', js: true do context 'when the procedure has invalid champs' do let(:empty_repetition) { build(:type_de_champ_repetition, types_de_champ: [], libelle: 'Enfants') } + let(:empty_drop_down) { build(:type_de_champ_drop_down_list, :without_selectable_values, libelle: 'Civilité') } + let!(:procedure) do create(:procedure, :with_path, :with_service, instructeurs: instructeurs, administrateur: administrateur, - types_de_champ: [empty_repetition]) + types_de_champ: [empty_repetition], + types_de_champ_private: [empty_drop_down]) end 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 champ « Enfants » doit comporter au moins un champ répétable") + expect(page).to have_content("L’annotation privée « Civilité » doit comporter au moins un choix sélectionnable") expect(find_field('procedure_path').value).to eq procedure.path fill_in 'lien_site_web', with: 'http://some.website'