feat(admin): add initiation procedure for a new admin
This commit is contained in:
parent
46f9148fa4
commit
9c8020b05c
4 changed files with 58 additions and 0 deletions
43
app/models/concerns/initiation_procedure_concern.rb
Normal file
43
app/models/concerns/initiation_procedure_concern.rb
Normal file
|
@ -0,0 +1,43 @@
|
|||
module InitiationProcedureConcern
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
class_methods do
|
||||
def create_initiation_procedure(administrateur)
|
||||
p = Procedure.new(
|
||||
libelle: 'Une première procédure',
|
||||
description: "Une première procédure afin de découvrir les possibilités de #{APPLICATION_NAME}",
|
||||
organisation: 'Dinum',
|
||||
cadre_juridique: "inexistant car c'est un test",
|
||||
duree_conservation_dossiers_dans_ds: 1,
|
||||
for_individual: true,
|
||||
administrateurs: [administrateur]
|
||||
)
|
||||
|
||||
p.draft_revision = p.revisions.build
|
||||
|
||||
p.save!
|
||||
|
||||
p.draft_revision.add_type_de_champ({ type_champ: :text, libelle: 'nouveau champ' })
|
||||
p.defaut_groupe_instructeur.instructeurs << administrateur.instructeur
|
||||
|
||||
service = Service.create(
|
||||
nom: 'Un très bon service',
|
||||
organisme: "d'un excellent organisme",
|
||||
type_organisme: Service.type_organismes.fetch(:autre),
|
||||
email: 'contactez@moi.fr',
|
||||
telephone: '1234',
|
||||
horaires: 'de 9 h à 18 h',
|
||||
adresse: 'adresse',
|
||||
siret: '35600082800018',
|
||||
etablissement_infos: { adresse: "75 rue du Louvre\n75002\nPARIS\nFRANCE" },
|
||||
etablissement_lat: 48.87,
|
||||
etablissement_lng: 2.34,
|
||||
administrateur:
|
||||
)
|
||||
|
||||
p.update(service:)
|
||||
|
||||
p
|
||||
end
|
||||
end
|
||||
end
|
|
@ -62,6 +62,7 @@
|
|||
class Procedure < ApplicationRecord
|
||||
include ProcedureStatsConcern
|
||||
include EncryptableConcern
|
||||
include InitiationProcedureConcern
|
||||
|
||||
include Discard::Model
|
||||
self.discard_column = :hidden_at
|
||||
|
|
|
@ -58,6 +58,7 @@ class SuperAdmin < ApplicationRecord
|
|||
|
||||
if user.valid?
|
||||
user.invite_administrateur!(id)
|
||||
Procedure.create_initiation_procedure(user.administrateur)
|
||||
end
|
||||
|
||||
user
|
||||
|
|
13
spec/models/concern/initiation_procedure_concern_spec.rb
Normal file
13
spec/models/concern/initiation_procedure_concern_spec.rb
Normal file
|
@ -0,0 +1,13 @@
|
|||
describe InitiationProcedureConcern do
|
||||
describe '.create_initiation_procedure' do
|
||||
let(:administrateur) { create(:administrateur) }
|
||||
subject { Procedure.create_initiation_procedure(administrateur) }
|
||||
|
||||
it "returns a new procedure" do
|
||||
expect(subject).to be_valid
|
||||
expect(subject.defaut_groupe_instructeur.instructeurs.count).to eq(1)
|
||||
expect(subject.draft_revision.types_de_champ_public).not_to be_empty
|
||||
expect(subject.service).not_to be_nil
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue