2018-01-23 17:15:42 +01:00
|
|
|
|
FactoryBot.define do
|
2015-08-13 15:55:19 +02:00
|
|
|
|
factory :dossier do
|
2018-09-04 16:46:48 +02:00
|
|
|
|
autorisation_donnees { true }
|
|
|
|
|
state { Dossier.states.fetch(:brouillon) }
|
2020-07-20 16:38:59 +02:00
|
|
|
|
association :user
|
2016-02-04 14:08:35 +01:00
|
|
|
|
|
2019-08-26 15:27:43 +02:00
|
|
|
|
transient do
|
|
|
|
|
procedure { nil }
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
after(:build) do |dossier, evaluator|
|
|
|
|
|
if evaluator.procedure.present?
|
|
|
|
|
procedure = evaluator.procedure
|
|
|
|
|
else
|
2019-07-25 15:57:00 +02:00
|
|
|
|
procedure = create(:procedure, :published, :with_type_de_champ, :with_type_de_champ_private)
|
2016-02-02 18:37:38 +01:00
|
|
|
|
end
|
2019-09-12 17:21:43 +02:00
|
|
|
|
|
2020-01-07 17:59:11 +01:00
|
|
|
|
# Assign the procedure to the dossier through the groupe_instructeur
|
2019-09-12 17:21:43 +02:00
|
|
|
|
if dossier.groupe_instructeur.nil?
|
|
|
|
|
dossier.groupe_instructeur = procedure.defaut_groupe_instructeur
|
|
|
|
|
end
|
2020-01-07 17:59:11 +01:00
|
|
|
|
|
|
|
|
|
dossier.build_default_individual
|
2016-02-02 18:37:38 +01:00
|
|
|
|
end
|
2016-02-04 14:08:35 +01:00
|
|
|
|
|
2015-08-13 15:55:19 +02:00
|
|
|
|
trait :with_entreprise do
|
2015-08-20 16:25:54 +02:00
|
|
|
|
after(:build) do |dossier, _evaluator|
|
2020-01-07 17:50:49 +01:00
|
|
|
|
if dossier.procedure.for_individual?
|
|
|
|
|
raise 'Inconsistent factory: attempting to create a dossier :with_entreprise on a procedure that is `for_individual?`'
|
|
|
|
|
end
|
2020-07-06 11:41:18 +02:00
|
|
|
|
etablissement = create(:etablissement, :with_exercices, :with_effectif_mensuel)
|
2015-08-13 15:55:19 +02:00
|
|
|
|
dossier.etablissement = etablissement
|
|
|
|
|
end
|
|
|
|
|
end
|
2015-09-21 17:59:03 +02:00
|
|
|
|
|
2018-06-19 16:23:43 +02:00
|
|
|
|
trait :with_service do
|
2019-04-11 12:23:40 +02:00
|
|
|
|
after(:create) do |dossier, _evaluator|
|
2018-06-19 16:23:43 +02:00
|
|
|
|
dossier.procedure.service = create(:service)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2020-01-07 17:47:22 +01:00
|
|
|
|
trait :with_individual do
|
2020-01-08 10:45:05 +01:00
|
|
|
|
after(:build) do |dossier, evaluator|
|
|
|
|
|
# If the procedure was implicitely created by the factory,
|
|
|
|
|
# mark it automatically as for_individual.
|
|
|
|
|
if evaluator.procedure.nil?
|
|
|
|
|
dossier.procedure.update(for_individual: true)
|
|
|
|
|
end
|
2020-01-07 17:45:39 +01:00
|
|
|
|
if !dossier.procedure.for_individual?
|
|
|
|
|
raise 'Inconsistent factory: attempting to create a dossier :with_individual on a procedure that is not `for_individual?`'
|
|
|
|
|
end
|
2020-07-20 16:53:25 +02:00
|
|
|
|
dossier.individual = build(:individual, dossier: dossier)
|
2017-01-03 12:53:27 +01:00
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2017-04-12 11:18:28 +02:00
|
|
|
|
trait :archived do
|
2018-09-04 16:46:48 +02:00
|
|
|
|
archived { true }
|
2017-04-12 11:18:28 +02:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
trait :not_archived do
|
2018-09-04 16:46:48 +02:00
|
|
|
|
archived { false }
|
2017-04-12 11:18:28 +02:00
|
|
|
|
end
|
|
|
|
|
|
2020-02-05 16:09:03 +01:00
|
|
|
|
trait :discarded do
|
2019-08-01 14:46:47 +02:00
|
|
|
|
hidden_at { Time.zone.now }
|
|
|
|
|
end
|
|
|
|
|
|
2017-04-17 17:20:32 +02:00
|
|
|
|
trait :with_dossier_link do
|
|
|
|
|
after(:create) do |dossier, _evaluator|
|
2019-08-21 09:09:20 +02:00
|
|
|
|
# create linked dossier
|
2020-02-05 17:38:24 +01:00
|
|
|
|
linked_dossier = create(:dossier, :en_construction)
|
2017-04-17 17:20:32 +02:00
|
|
|
|
|
2019-08-21 09:09:20 +02:00
|
|
|
|
# find first type de champ dossier_link
|
|
|
|
|
type_de_champ = dossier.procedure.types_de_champ.find do |t|
|
|
|
|
|
t.type_champ == TypeDeChamp.type_champs.fetch(:dossier_link)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
# if type de champ does not exist create it
|
|
|
|
|
if !type_de_champ
|
|
|
|
|
type_de_champ = create(:type_de_champ_dossier_link, procedure: dossier.procedure)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
# find champ with the type de champ
|
|
|
|
|
champ = dossier.reload.champs.find do |c|
|
|
|
|
|
c.type_de_champ == type_de_champ
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
# if champ does not exist create it
|
|
|
|
|
if !champ
|
|
|
|
|
champ = create(:champ_dossier_link, dossier: dossier, type_de_champ: type_de_champ)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
# set champ value with linked dossier
|
2017-04-17 17:20:32 +02:00
|
|
|
|
champ.value = linked_dossier.id
|
|
|
|
|
champ.save!
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2018-09-05 16:17:26 +02:00
|
|
|
|
trait :with_commentaires do
|
|
|
|
|
after(:create) do |dossier, _evaluator|
|
|
|
|
|
dossier.commentaires += create_list(:commentaire, 2)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2017-07-17 11:22:12 +02:00
|
|
|
|
trait :followed do
|
|
|
|
|
after(:create) do |dossier, _evaluator|
|
2019-08-06 11:02:54 +02:00
|
|
|
|
g = create(:instructeur)
|
2017-07-17 11:22:12 +02:00
|
|
|
|
g.followed_dossiers << dossier
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2017-12-14 15:51:45 +01:00
|
|
|
|
trait :en_construction do
|
2017-10-05 10:50:44 +02:00
|
|
|
|
after(:create) do |dossier, _evaluator|
|
2018-08-28 14:10:55 +02:00
|
|
|
|
dossier.state = Dossier.states.fetch(:en_construction)
|
2018-08-31 12:29:11 +02:00
|
|
|
|
dossier.en_construction_at ||= dossier.created_at + 1.minute
|
2017-10-05 10:50:44 +02:00
|
|
|
|
dossier.save!
|
|
|
|
|
end
|
2017-01-30 15:17:45 +01:00
|
|
|
|
end
|
2017-10-05 15:22:56 +02:00
|
|
|
|
|
2017-12-14 15:53:02 +01:00
|
|
|
|
trait :en_instruction do
|
2017-10-05 15:22:56 +02:00
|
|
|
|
after(:create) do |dossier, _evaluator|
|
2018-08-28 14:10:55 +02:00
|
|
|
|
dossier.state = Dossier.states.fetch(:en_instruction)
|
2018-08-31 12:29:11 +02:00
|
|
|
|
dossier.en_construction_at ||= dossier.created_at + 1.minute
|
|
|
|
|
dossier.en_instruction_at ||= dossier.en_construction_at + 1.minute
|
2017-10-05 15:22:56 +02:00
|
|
|
|
dossier.save!
|
|
|
|
|
end
|
|
|
|
|
end
|
2018-08-10 16:17:19 +02:00
|
|
|
|
|
|
|
|
|
trait :accepte do
|
2020-07-02 11:02:50 +02:00
|
|
|
|
transient do
|
|
|
|
|
motivation { nil }
|
2020-07-06 16:58:08 +02:00
|
|
|
|
processed_at { nil }
|
2020-07-02 11:02:50 +02:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
after(:create) do |dossier, evaluator|
|
2018-08-28 14:10:55 +02:00
|
|
|
|
dossier.state = Dossier.states.fetch(:accepte)
|
2020-07-06 16:58:08 +02:00
|
|
|
|
processed_at = evaluator.processed_at
|
|
|
|
|
if processed_at.present?
|
|
|
|
|
dossier.en_construction_at ||= processed_at - 2.minutes
|
|
|
|
|
dossier.en_instruction_at ||= processed_at - 1.minute
|
|
|
|
|
dossier.traitements.build(state: Dossier.states.fetch(:accepte), processed_at: processed_at, motivation: evaluator.motivation)
|
|
|
|
|
else
|
|
|
|
|
dossier.en_construction_at ||= dossier.created_at + 1.minute
|
|
|
|
|
dossier.en_instruction_at ||= dossier.en_construction_at + 1.minute
|
|
|
|
|
dossier.traitements.build(state: Dossier.states.fetch(:accepte), processed_at: dossier.en_instruction_at + 1.minute, motivation: evaluator.motivation)
|
|
|
|
|
end
|
2018-08-10 16:17:19 +02:00
|
|
|
|
dossier.save!
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
trait :refuse do
|
|
|
|
|
after(:create) do |dossier, _evaluator|
|
2018-08-28 14:10:55 +02:00
|
|
|
|
dossier.state = Dossier.states.fetch(:refuse)
|
2018-08-31 12:29:11 +02:00
|
|
|
|
dossier.en_construction_at ||= dossier.created_at + 1.minute
|
|
|
|
|
dossier.en_instruction_at ||= dossier.en_construction_at + 1.minute
|
2020-07-02 11:02:50 +02:00
|
|
|
|
dossier.traitements.build(state: Dossier.states.fetch(:refuse), processed_at: dossier.en_instruction_at + 1.minute)
|
2018-08-10 16:17:19 +02:00
|
|
|
|
dossier.save!
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
trait :sans_suite do
|
|
|
|
|
after(:create) do |dossier, _evaluator|
|
2018-08-28 14:10:55 +02:00
|
|
|
|
dossier.state = Dossier.states.fetch(:sans_suite)
|
2018-08-31 12:29:11 +02:00
|
|
|
|
dossier.en_construction_at ||= dossier.created_at + 1.minute
|
|
|
|
|
dossier.en_instruction_at ||= dossier.en_construction_at + 1.minute
|
2020-07-02 11:02:50 +02:00
|
|
|
|
dossier.traitements.build(state: Dossier.states.fetch(:sans_suite), processed_at: dossier.en_instruction_at + 1.minute)
|
2018-08-10 16:17:19 +02:00
|
|
|
|
dossier.save!
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
trait :with_motivation do
|
|
|
|
|
after(:create) do |dossier, _evaluator|
|
2020-07-02 11:02:50 +02:00
|
|
|
|
motivation = case dossier.state
|
2018-08-28 14:10:55 +02:00
|
|
|
|
when Dossier.states.fetch(:refuse)
|
2018-08-10 16:17:19 +02:00
|
|
|
|
'L’entreprise concernée n’est pas agréée.'
|
2018-08-28 14:10:55 +02:00
|
|
|
|
when Dossier.states.fetch(:sans_suite)
|
2018-08-10 16:17:19 +02:00
|
|
|
|
'Le département n’est pas éligible. Veuillez remplir un nouveau dossier auprès de la DDT du 93.'
|
|
|
|
|
else
|
|
|
|
|
'Vous avez validé les conditions.'
|
|
|
|
|
end
|
2020-07-02 11:02:50 +02:00
|
|
|
|
dossier.traitements.last.update!(motivation: motivation)
|
2018-08-10 16:17:19 +02:00
|
|
|
|
end
|
|
|
|
|
end
|
2018-09-17 14:45:40 +02:00
|
|
|
|
|
|
|
|
|
trait :with_attestation do
|
2020-07-20 16:30:29 +02:00
|
|
|
|
after(:build) do |dossier, _evaluator|
|
2018-09-17 14:45:40 +02:00
|
|
|
|
if dossier.procedure.attestation_template.blank?
|
2020-07-20 16:30:29 +02:00
|
|
|
|
dossier.procedure.attestation_template = build(:attestation_template)
|
2018-09-17 14:45:40 +02:00
|
|
|
|
end
|
|
|
|
|
dossier.attestation = dossier.build_attestation
|
|
|
|
|
end
|
|
|
|
|
end
|
2018-11-22 00:14:16 +01:00
|
|
|
|
|
2019-10-15 12:42:51 +02:00
|
|
|
|
trait :with_justificatif do
|
|
|
|
|
after(:create) do |dossier, _evaluator|
|
|
|
|
|
dossier.justificatif_motivation.attach(
|
|
|
|
|
io: StringIO.new('Hello World'),
|
|
|
|
|
filename: 'hello.txt'
|
|
|
|
|
)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2018-11-22 00:14:16 +01:00
|
|
|
|
trait :with_all_champs do
|
|
|
|
|
after(:create) do |dossier, _evaluator|
|
|
|
|
|
dossier.champs = dossier.procedure.types_de_champ.map do |type_de_champ|
|
|
|
|
|
build(:"champ_#{type_de_champ.type_champ}", type_de_champ: type_de_champ)
|
|
|
|
|
end
|
|
|
|
|
dossier.save!
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
trait :with_all_annotations do
|
|
|
|
|
after(:create) do |dossier, _evaluator|
|
|
|
|
|
dossier.champs = dossier.procedure.types_de_champ.map do |type_de_champ|
|
|
|
|
|
build(:"champ_#{type_de_champ.type_champ}", type_de_champ: type_de_champ)
|
|
|
|
|
end
|
|
|
|
|
dossier.save!
|
|
|
|
|
end
|
|
|
|
|
end
|
2015-08-13 15:55:19 +02:00
|
|
|
|
end
|
2015-08-20 17:30:17 +02:00
|
|
|
|
end
|