Merge pull request #8093 from demarches-simplifiees/clean_invalid_procedures

fix(procedures): valides uniquement le juridique a la création et à la publication
This commit is contained in:
LeSim 2023-01-11 14:18:18 +01:00 committed by GitHub
commit d6cbf738a1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 11 additions and 10 deletions

View file

@ -272,7 +272,9 @@ class Procedure < ApplicationRecord
'types_de_champ/no_empty_block': true, 'types_de_champ/no_empty_block': true,
'types_de_champ/no_empty_drop_down': true, 'types_de_champ/no_empty_drop_down': true,
on: :publication on: :publication
validate :check_juridique
validate :check_juridique, on: [:create, :publication]
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 :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, validates :duree_conservation_dossiers_dans_ds, allow_nil: false,
numericality: { numericality: {

View file

@ -6,12 +6,12 @@
= f.label :libelle do = f.label :libelle do
Titre de la démarche Titre de la démarche
%span.mandatory * %span.mandatory *
= f.text_field :libelle, class: 'form-control', placeholder: 'Titre' = f.text_field :libelle, class: 'form-control', placeholder: 'Titre', required: true
= f.label :description do = f.label :description do
Description Description
%span.mandatory * %span.mandatory *
= f.text_area :description, rows: '6', placeholder: 'Description de la démarche, destinataires, etc. ', class: 'form-control' = f.text_area :description, rows: '6', placeholder: 'Description de la démarche, destinataires, etc. ', class: 'form-control', required: true
%h3.header-subsection Logo de la démarche %h3.header-subsection Logo de la démarche
= render Attachment::EditComponent.new(attached_file: @procedure.logo, view_as: :link) = render Attachment::EditComponent.new(attached_file: @procedure.logo, view_as: :link)

View file

@ -178,20 +178,20 @@ describe Procedure do
end end
context 'juridique' do context 'juridique' do
it { is_expected.not_to allow_value(nil).for(:cadre_juridique) } it { is_expected.not_to allow_value(nil).on(:publication).for(:cadre_juridique) }
it { is_expected.to allow_value('text').for(:cadre_juridique) } it { is_expected.to allow_value('text').on(:publication).for(:cadre_juridique) }
context 'with deliberation' do context 'with deliberation' do
let(:procedure) { build(:procedure, cadre_juridique: nil) } let(:procedure) { build(:procedure, cadre_juridique: nil) }
it { expect(procedure.valid?).to eq(false) } it { expect(procedure.valid?(:publication)).to eq(false) }
context 'when the deliberation is uploaded ' do context 'when the deliberation is uploaded ' do
before do before do
procedure.deliberation = fixture_file_upload('spec/fixtures/files/file.pdf', 'application/pdf') procedure.deliberation = fixture_file_upload('spec/fixtures/files/file.pdf', 'application/pdf')
end end
it { expect(procedure.valid?).to eq(true) } it { expect(procedure.valid?(:publication)).to eq(true) }
end end
context 'when the deliberation is uploaded with an unauthorized format' do context 'when the deliberation is uploaded with an unauthorized format' do
@ -199,14 +199,14 @@ describe Procedure do
procedure.deliberation = fixture_file_upload('spec/fixtures/files/french-flag.gif', 'image/gif') procedure.deliberation = fixture_file_upload('spec/fixtures/files/french-flag.gif', 'image/gif')
end end
it { expect(procedure.valid?).to eq(false) } it { expect(procedure.valid?(:publication)).to eq(false) }
end end
end end
context 'when juridique_required is false' do context 'when juridique_required is false' do
let(:procedure) { build(:procedure, juridique_required: false, cadre_juridique: nil) } let(:procedure) { build(:procedure, juridique_required: false, cadre_juridique: nil) }
it { expect(procedure.valid?).to eq(true) } it { expect(procedure.valid?(:publication)).to eq(true) }
end end
end end

View file

@ -21,7 +21,6 @@ describe 'Creating a new procedure', js: true do
fill_in 'procedure_duree_conservation_dossiers_dans_ds', with: '3' fill_in 'procedure_duree_conservation_dossiers_dans_ds', with: '3'
click_on 'Créer la démarche' click_on 'Créer la démarche'
expect(page).to have_text('Le champ « Libelle » doit être rempli')
fill_in_dummy_procedure_details fill_in_dummy_procedure_details
click_on 'Créer la démarche' click_on 'Créer la démarche'