fix(sva): not compatible with declarative procedure
This commit is contained in:
parent
e1b21f980f
commit
7225f1b023
5 changed files with 21 additions and 0 deletions
|
@ -4,6 +4,7 @@ module ProcedureSVASVRConcern
|
|||
included do
|
||||
scope :sva_svr, -> { where("sva_svr ->> 'decision' IN (?)", ['sva', 'svr']) }
|
||||
validate :sva_svr_immutable_on_published, if: :will_save_change_to_sva_svr?
|
||||
validate :validates_sva_svr_compatible
|
||||
|
||||
def sva_svr_enabled?
|
||||
sva? || svr?
|
||||
|
@ -37,5 +38,13 @@ module ProcedureSVASVRConcern
|
|||
|
||||
errors.add(:sva_svr, :immutable)
|
||||
end
|
||||
|
||||
def validates_sva_svr_compatible
|
||||
return if !sva_svr_enabled?
|
||||
|
||||
if declarative_with_state.present?
|
||||
errors.add(:sva_svr, :declarative_incompatible)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -59,3 +59,4 @@ en:
|
|||
invalid_uri_or_email: "Fill in with an email or a link"
|
||||
sva_svr:
|
||||
immutable: "SVA/SVR configuration can no longer be modified"
|
||||
declarative_incompatible: "SVA/SVR is incompatible with a declarative procedure"
|
||||
|
|
|
@ -67,3 +67,4 @@ fr:
|
|||
future: doit être dans le futur
|
||||
sva_svr:
|
||||
immutable: "La configuration SVA/SVR ne peut plus être modifiée"
|
||||
declarative_incompatible: "Le SVA/SVR est incompatible avec une démarche déclarative"
|
||||
|
|
|
@ -13,6 +13,7 @@ FactoryBot.define do
|
|||
ask_birthday { false }
|
||||
lien_site_web { "https://mon-site.gouv" }
|
||||
path { SecureRandom.uuid }
|
||||
declarative_with_state { nil }
|
||||
sva_svr { {} }
|
||||
|
||||
groupe_instructeurs { [association(:groupe_instructeur, :default, procedure: instance, strategy: :build)] }
|
||||
|
|
|
@ -440,6 +440,15 @@ describe Procedure do
|
|||
expect(procedure).to be_valid
|
||||
end
|
||||
end
|
||||
|
||||
context "with declarative" do
|
||||
let(:procedure) { create(:procedure, declarative_with_state: "accepte") }
|
||||
|
||||
it 'is not valid' do
|
||||
expect(procedure).not_to be_valid
|
||||
expect(procedure.errors[:sva_svr].join).to include('incompatible avec une démarche déclarative')
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue