procedure publiee must have one zone at least

This commit is contained in:
Christophe Robillard 2022-09-27 19:22:42 +02:00 committed by krichtof
parent 2985295a00
commit bdcb451d3c
6 changed files with 28 additions and 10 deletions

View file

@ -131,7 +131,11 @@ module Administrateurs
if !@procedure.update(procedure_params)
flash.now.alert = @procedure.errors.full_messages
render 'edit'
if @procedure.errors[:zones].present?
render 'zones'
else
render 'edit'
end
elsif @procedure.brouillon?
reset_procedure
flash.notice = 'Démarche modifiée. Tous les dossiers de cette démarche ont été supprimés.'

View file

@ -289,6 +289,7 @@ class Procedure < ApplicationRecord
validates :lien_dpo, email_or_link: true, allow_nil: true
validates_with MonAvisEmbedValidator
validates :zones, presence: true, if: -> record { record.publiee? && Flipper.enabled?(:zonage) }
FILE_MAX_SIZE = 20.megabytes
validates :notice, content_type: [

View file

@ -334,6 +334,19 @@ describe Administrateurs::ProceduresController, type: :controller do
it { expect(subject.for_individual).not_to eq procedure_params[:for_individual] }
end
context 'when zones are empty' do
before do
Flipper.enable(:zonage)
end
after do
Flipper.disable(:zonage)
end
let(:zone_ids) { [""] }
it { is_expected.to render_template :zones }
end
end
end
end

View file

@ -13,7 +13,6 @@ FactoryBot.define do
ask_birthday { false }
lien_site_web { "https://mon-site.gouv" }
path { SecureRandom.uuid }
association :zone
groupe_instructeurs { [association(:groupe_instructeur, :default, procedure: instance, strategy: :build)] }
administrateurs { administrateur.present? ? [administrateur] : [association(:administrateur)] }
@ -282,6 +281,7 @@ FactoryBot.define do
published_at { Time.zone.now }
unpublished_at { nil }
closed_at { nil }
zones { [association(:zone, strategy: :build)] }
end
trait :closed do

View file

@ -1484,7 +1484,7 @@ describe Dossier do
end
describe "champs_for_export" do
let(:procedure) { create(:procedure, :with_type_de_champ, :with_datetime, :with_yes_no, :with_explication, :with_commune, :with_repetition) }
let(:procedure) { create(:procedure, :with_type_de_champ, :with_datetime, :with_yes_no, :with_explication, :with_commune, :with_repetition, zones: [create(:zone)]) }
let(:text_type_de_champ) { procedure.types_de_champ.find { |type_de_champ| type_de_champ.type_champ == TypeDeChamp.type_champs.fetch(:text) } }
let(:yes_no_type_de_champ) { procedure.types_de_champ.find { |type_de_champ| type_de_champ.type_champ == TypeDeChamp.type_champs.fetch(:yes_no) } }
let(:datetime_type_de_champ) { procedure.types_de_champ.find { |type_de_champ| type_de_champ.type_champ == TypeDeChamp.type_champs.fetch(:datetime) } }

View file

@ -704,7 +704,7 @@ describe Procedure do
end
describe '#publish!' do
let(:procedure) { create(:procedure, path: 'example-path') }
let(:procedure) { create(:procedure, path: 'example-path', zones: [create(:zone)]) }
let(:now) { Time.zone.now.beginning_of_minute }
context 'when publishing a new procedure' do
@ -757,7 +757,7 @@ describe Procedure do
let(:canonical_procedure) { create(:procedure, :published) }
let(:administrateur) { canonical_procedure.administrateurs.first }
let(:procedure) { create(:procedure, administrateurs: [administrateur]) }
let(:procedure) { create(:procedure, administrateurs: [administrateur], zones: [create(:zone)]) }
let(:now) { Time.zone.now.beginning_of_minute }
context 'when publishing over a previous canonical procedure' do
@ -1063,7 +1063,7 @@ describe Procedure do
end
describe 'suggested_path' do
let(:procedure) { create(:procedure, aasm_state: :publiee, libelle: 'Inscription au Collège') }
let(:procedure) { create(:procedure, aasm_state: :publiee, libelle: 'Inscription au Collège', zones: [create(:zone)]) }
subject { procedure.suggested_path(procedure.administrateurs.first) }
@ -1079,7 +1079,7 @@ describe Procedure do
context 'when the suggestion conflicts with one procedure' do
before do
create(:procedure, aasm_state: :publiee, path: 'inscription-au-college')
create(:procedure, aasm_state: :publiee, path: 'inscription-au-college', zones: [create(:zone)])
end
it { is_expected.to eq 'inscription-au-college-2' }
@ -1087,8 +1087,8 @@ describe Procedure do
context 'when the suggestion conflicts with several procedures' do
before do
create(:procedure, aasm_state: :publiee, path: 'inscription-au-college')
create(:procedure, aasm_state: :publiee, path: 'inscription-au-college-2')
create(:procedure, aasm_state: :publiee, path: 'inscription-au-college', zones: [create(:zone)])
create(:procedure, aasm_state: :publiee, path: 'inscription-au-college-2', zones: [create(:zone)])
end
it { is_expected.to eq 'inscription-au-college-3' }
@ -1096,7 +1096,7 @@ describe Procedure do
context 'when the suggestion conflicts with another procedure of the same admin' do
before do
create(:procedure, aasm_state: :publiee, path: 'inscription-au-college', administrateurs: procedure.administrateurs)
create(:procedure, aasm_state: :publiee, path: 'inscription-au-college', administrateurs: procedure.administrateurs, zones: [create(:zone)])
end
it { is_expected.to eq 'inscription-au-college' }