Make sure that there always is at least one administrator per Procedure
This commit is contained in:
parent
8d84dba3f2
commit
df865e71dc
2 changed files with 6 additions and 1 deletions
|
@ -17,7 +17,7 @@ class Procedure < ApplicationRecord
|
|||
|
||||
has_many :assign_to, dependent: :destroy
|
||||
has_many :administrateurs_procedures
|
||||
has_many :administrateurs, through: :administrateurs_procedures
|
||||
has_many :administrateurs, through: :administrateurs_procedures, after_remove: -> (procedure, _admin) { procedure.validate! }
|
||||
has_many :gestionnaires, through: :assign_to
|
||||
|
||||
has_one :initiated_mail, class_name: "Mails::InitiatedMail", dependent: :destroy
|
||||
|
@ -57,6 +57,7 @@ class Procedure < ApplicationRecord
|
|||
|
||||
validates :libelle, presence: true, allow_blank: false, allow_nil: false
|
||||
validates :description, presence: true, allow_blank: false, allow_nil: false
|
||||
validates :administrateurs, presence: true
|
||||
validate :check_juridique
|
||||
validates :path, format: { with: /\A[a-z0-9_\-]{3,50}\z/ }, uniqueness: { scope: :aasm_state, case_sensitive: false }, presence: true, allow_blank: false, allow_nil: true
|
||||
# FIXME: remove duree_conservation_required flag once all procedures are converted to the new style
|
||||
|
|
|
@ -168,6 +168,10 @@ describe Procedure do
|
|||
it { is_expected.to allow_value('URRSAF').for(:organisation) }
|
||||
end
|
||||
|
||||
context 'administrateurs' do
|
||||
it { is_expected.not_to allow_value([]).for(:administrateurs) }
|
||||
end
|
||||
|
||||
context 'juridique' do
|
||||
it { is_expected.not_to allow_value(nil).for(:cadre_juridique) }
|
||||
it { is_expected.to allow_value('text').for(:cadre_juridique) }
|
||||
|
|
Loading…
Reference in a new issue