procedure publiee must have one zone at least
This commit is contained in:
parent
2985295a00
commit
bdcb451d3c
6 changed files with 28 additions and 10 deletions
|
@ -131,7 +131,11 @@ module Administrateurs
|
||||||
|
|
||||||
if !@procedure.update(procedure_params)
|
if !@procedure.update(procedure_params)
|
||||||
flash.now.alert = @procedure.errors.full_messages
|
flash.now.alert = @procedure.errors.full_messages
|
||||||
render 'edit'
|
if @procedure.errors[:zones].present?
|
||||||
|
render 'zones'
|
||||||
|
else
|
||||||
|
render 'edit'
|
||||||
|
end
|
||||||
elsif @procedure.brouillon?
|
elsif @procedure.brouillon?
|
||||||
reset_procedure
|
reset_procedure
|
||||||
flash.notice = 'Démarche modifiée. Tous les dossiers de cette démarche ont été supprimés.'
|
flash.notice = 'Démarche modifiée. Tous les dossiers de cette démarche ont été supprimés.'
|
||||||
|
|
|
@ -289,6 +289,7 @@ class Procedure < ApplicationRecord
|
||||||
|
|
||||||
validates :lien_dpo, email_or_link: true, allow_nil: true
|
validates :lien_dpo, email_or_link: true, allow_nil: true
|
||||||
validates_with MonAvisEmbedValidator
|
validates_with MonAvisEmbedValidator
|
||||||
|
validates :zones, presence: true, if: -> record { record.publiee? && Flipper.enabled?(:zonage) }
|
||||||
|
|
||||||
FILE_MAX_SIZE = 20.megabytes
|
FILE_MAX_SIZE = 20.megabytes
|
||||||
validates :notice, content_type: [
|
validates :notice, content_type: [
|
||||||
|
|
|
@ -334,6 +334,19 @@ describe Administrateurs::ProceduresController, type: :controller do
|
||||||
|
|
||||||
it { expect(subject.for_individual).not_to eq procedure_params[:for_individual] }
|
it { expect(subject.for_individual).not_to eq procedure_params[:for_individual] }
|
||||||
end
|
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
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -13,7 +13,6 @@ FactoryBot.define do
|
||||||
ask_birthday { false }
|
ask_birthday { false }
|
||||||
lien_site_web { "https://mon-site.gouv" }
|
lien_site_web { "https://mon-site.gouv" }
|
||||||
path { SecureRandom.uuid }
|
path { SecureRandom.uuid }
|
||||||
association :zone
|
|
||||||
|
|
||||||
groupe_instructeurs { [association(:groupe_instructeur, :default, procedure: instance, strategy: :build)] }
|
groupe_instructeurs { [association(:groupe_instructeur, :default, procedure: instance, strategy: :build)] }
|
||||||
administrateurs { administrateur.present? ? [administrateur] : [association(:administrateur)] }
|
administrateurs { administrateur.present? ? [administrateur] : [association(:administrateur)] }
|
||||||
|
@ -282,6 +281,7 @@ FactoryBot.define do
|
||||||
published_at { Time.zone.now }
|
published_at { Time.zone.now }
|
||||||
unpublished_at { nil }
|
unpublished_at { nil }
|
||||||
closed_at { nil }
|
closed_at { nil }
|
||||||
|
zones { [association(:zone, strategy: :build)] }
|
||||||
end
|
end
|
||||||
|
|
||||||
trait :closed do
|
trait :closed do
|
||||||
|
|
|
@ -1484,7 +1484,7 @@ describe Dossier do
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "champs_for_export" do
|
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(: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(: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) } }
|
let(:datetime_type_de_champ) { procedure.types_de_champ.find { |type_de_champ| type_de_champ.type_champ == TypeDeChamp.type_champs.fetch(:datetime) } }
|
||||||
|
|
|
@ -704,7 +704,7 @@ describe Procedure do
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '#publish!' do
|
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 }
|
let(:now) { Time.zone.now.beginning_of_minute }
|
||||||
|
|
||||||
context 'when publishing a new procedure' do
|
context 'when publishing a new procedure' do
|
||||||
|
@ -757,7 +757,7 @@ describe Procedure do
|
||||||
let(:canonical_procedure) { create(:procedure, :published) }
|
let(:canonical_procedure) { create(:procedure, :published) }
|
||||||
let(:administrateur) { canonical_procedure.administrateurs.first }
|
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 }
|
let(:now) { Time.zone.now.beginning_of_minute }
|
||||||
|
|
||||||
context 'when publishing over a previous canonical procedure' do
|
context 'when publishing over a previous canonical procedure' do
|
||||||
|
@ -1063,7 +1063,7 @@ describe Procedure do
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'suggested_path' do
|
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) }
|
subject { procedure.suggested_path(procedure.administrateurs.first) }
|
||||||
|
|
||||||
|
@ -1079,7 +1079,7 @@ describe Procedure do
|
||||||
|
|
||||||
context 'when the suggestion conflicts with one procedure' do
|
context 'when the suggestion conflicts with one procedure' do
|
||||||
before 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
|
end
|
||||||
|
|
||||||
it { is_expected.to eq 'inscription-au-college-2' }
|
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
|
context 'when the suggestion conflicts with several procedures' do
|
||||||
before do
|
before do
|
||||||
create(:procedure, aasm_state: :publiee, path: 'inscription-au-college')
|
create(:procedure, aasm_state: :publiee, path: 'inscription-au-college', zones: [create(:zone)])
|
||||||
create(:procedure, aasm_state: :publiee, path: 'inscription-au-college-2')
|
create(:procedure, aasm_state: :publiee, path: 'inscription-au-college-2', zones: [create(:zone)])
|
||||||
end
|
end
|
||||||
|
|
||||||
it { is_expected.to eq 'inscription-au-college-3' }
|
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
|
context 'when the suggestion conflicts with another procedure of the same admin' do
|
||||||
before 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
|
end
|
||||||
|
|
||||||
it { is_expected.to eq 'inscription-au-college' }
|
it { is_expected.to eq 'inscription-au-college' }
|
||||||
|
|
Loading…
Reference in a new issue