cannot publish a procedure if no zones

This commit is contained in:
Christophe Robillard 2022-09-27 19:46:50 +02:00 committed by krichtof
parent bdcb451d3c
commit 272c8cae09
3 changed files with 78 additions and 5 deletions

View file

@ -629,6 +629,10 @@ class Procedure < ApplicationRecord
result << :instructeurs
end
if missing_zones?
result << :zones
end
result
end
@ -661,6 +665,14 @@ class Procedure < ApplicationRecord
!AssignTo.exists?(groupe_instructeur: groupe_instructeurs)
end
def missing_zones?
if Flipper.enabled?(:zonage)
zones.empty?
else
false
end
end
def revised?
feature_enabled?(:procedure_revisions) && revisions.size > 2
end

View file

@ -74,13 +74,14 @@
- else
.alert.alert-info
Pour pouvoir tester cette démarche, vous devez dabord lui affecter
Pour pouvoir tester cette démarche, vous devez dabord lui affecter :
%ul
- if @procedure.missing_zones?
%li= link_to("une ou plusieurs zones", zones_admin_procedure_path(id: @procedure.id))
- if @procedure.missing_instructeurs?
= link_to("des instructeurs", admin_procedure_groupe_instructeur_path(@procedure, @procedure.defaut_groupe_instructeur))
- if @procedure.missing_instructeurs? && @procedure.service.nil?
et
%li= link_to("des instructeurs", admin_procedure_groupe_instructeur_path(@procedure, @procedure.defaut_groupe_instructeur))
- if @procedure.service.nil?
= link_to("un service", admin_services_path(procedure_id: @procedure))
%li= link_to("un service", admin_services_path(procedure_id: @procedure))
\.
- else
- if @procedure.missing_steps.include?(:service)

View file

@ -1231,6 +1231,66 @@ describe Procedure do
end
end
describe '.missing_zones?' do
before do
Flipper.enable :zonage
end
after do
Flipper.disable :zonage
end
let(:procedure) { create(:procedure, zones: []) }
subject { procedure.missing_zones? }
it { is_expected.to be true }
context 'when a procedure has zones' do
let(:zone) { create(:zone) }
before { procedure.zones << zone }
it { is_expected.to be false }
end
end
describe '.missing_steps' do
before do
Flipper.enable :zonage
end
after do
Flipper.disable :zonage
end
subject { procedure.missing_steps.include?(step) }
context 'without zone' do
let(:procedure) { create(:procedure, zones: []) }
let(:step) { :zones }
it { is_expected.to be_truthy }
end
context 'with zone' do
let(:procedure) { create(:procedure, zones: [create(:zone)]) }
let(:step) { :zones }
it { is_expected.to be_falsey }
end
context 'without service' do
let(:procedure) { create(:procedure, service: nil) }
let(:step) { :service }
it { is_expected.to be_truthy }
end
context 'with service' do
let(:procedure) { create(:procedure) }
let(:step) { :service }
it { is_expected.to be_truthy }
end
end
describe "#destroy" do
let(:procedure) { create(:procedure, :closed, :with_type_de_champ, :with_bulk_message) }