2018-01-23 17:15:42 +01:00
|
|
|
|
FactoryBot.define do
|
2015-08-13 15:55:19 +02:00
|
|
|
|
factory :dossier do
|
2018-02-08 17:13:15 +01:00
|
|
|
|
autorisation_donnees true
|
2017-12-04 16:17:15 +01:00
|
|
|
|
state 'brouillon'
|
2016-02-04 14:08:35 +01:00
|
|
|
|
association :user, factory: [:user]
|
|
|
|
|
|
|
|
|
|
before(:create) do |dossier, _evaluator|
|
2018-01-11 19:04:39 +01:00
|
|
|
|
if !dossier.procedure
|
2017-07-18 15:26:33 +02:00
|
|
|
|
procedure = create(:procedure, :published, :with_two_type_de_piece_justificative, :with_type_de_champ, :with_type_de_champ_private)
|
2016-02-02 18:37:38 +01:00
|
|
|
|
dossier.procedure = procedure
|
|
|
|
|
end
|
|
|
|
|
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|
|
2015-08-13 15:55:19 +02:00
|
|
|
|
etablissement = create(:etablissement)
|
|
|
|
|
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
|
|
|
|
|
after(:build) do |dossier, _evaluator|
|
|
|
|
|
dossier.procedure.service = create(:service)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2017-01-03 12:53:27 +01:00
|
|
|
|
trait :for_individual do
|
|
|
|
|
after(:build) do |dossier, _evaluator|
|
2018-06-19 16:01:27 +02:00
|
|
|
|
dossier.individual = create(:individual)
|
2017-01-03 12:53:27 +01:00
|
|
|
|
dossier.save
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2015-11-25 17:05:14 +01:00
|
|
|
|
trait :with_two_quartier_prioritaires do
|
|
|
|
|
after(:build) do |dossier, _evaluator|
|
2016-03-16 15:34:35 +01:00
|
|
|
|
dossier.quartier_prioritaires << create(:quartier_prioritaire)
|
|
|
|
|
dossier.quartier_prioritaires << create(:quartier_prioritaire)
|
2015-11-25 17:05:14 +01:00
|
|
|
|
end
|
|
|
|
|
end
|
2016-01-18 12:03:18 +01:00
|
|
|
|
|
|
|
|
|
trait :with_two_cadastres do
|
|
|
|
|
after(:build) do |dossier, _evaluator|
|
2016-03-16 15:34:35 +01:00
|
|
|
|
dossier.cadastres << create(:cadastre)
|
|
|
|
|
dossier.cadastres << create(:cadastre)
|
|
|
|
|
end
|
|
|
|
|
end
|
2016-01-18 12:03:18 +01:00
|
|
|
|
|
2017-04-12 11:18:28 +02:00
|
|
|
|
trait :archived do
|
|
|
|
|
archived true
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
trait :not_archived do
|
|
|
|
|
archived false
|
|
|
|
|
end
|
|
|
|
|
|
2017-04-17 17:20:32 +02:00
|
|
|
|
trait :with_dossier_link do
|
|
|
|
|
after(:create) do |dossier, _evaluator|
|
|
|
|
|
linked_dossier = create(:dossier)
|
2018-08-28 16:22:34 +02:00
|
|
|
|
type_de_champ = dossier.procedure.types_de_champ.find { |t| t.type_champ == TypeDeChamp.type_champs.fetch(:dossier_link) }
|
2017-04-17 17:20:32 +02:00
|
|
|
|
champ = dossier.champs.find { |c| c.type_de_champ == type_de_champ }
|
|
|
|
|
|
|
|
|
|
champ.value = linked_dossier.id
|
|
|
|
|
champ.save!
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2017-07-17 11:22:12 +02:00
|
|
|
|
trait :followed do
|
|
|
|
|
after(:create) do |dossier, _evaluator|
|
|
|
|
|
g = create(:gestionnaire)
|
|
|
|
|
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|
|
2017-12-14 15:51:45 +01:00
|
|
|
|
dossier.state = 'en_construction'
|
|
|
|
|
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|
|
2017-12-14 15:53:02 +01:00
|
|
|
|
dossier.state = 'en_instruction'
|
2017-12-14 15:51:45 +01:00
|
|
|
|
dossier.en_construction_at = dossier.created_at + 1.minute
|
2018-03-06 13:44:29 +01:00
|
|
|
|
dossier.created_at = dossier.created_at + 2.minutes
|
2017-10-05 15:22:56 +02:00
|
|
|
|
dossier.save!
|
|
|
|
|
end
|
|
|
|
|
end
|
2018-08-10 16:17:19 +02:00
|
|
|
|
|
|
|
|
|
trait :accepte do
|
|
|
|
|
after(:create) do |dossier, _evaluator|
|
|
|
|
|
dossier.state = 'accepte'
|
|
|
|
|
dossier.processed_at = dossier.created_at + 1.minute
|
|
|
|
|
dossier.en_construction_at = dossier.created_at + 2.minutes
|
|
|
|
|
dossier.created_at = dossier.created_at + 3.minutes
|
|
|
|
|
dossier.save!
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
trait :refuse do
|
|
|
|
|
after(:create) do |dossier, _evaluator|
|
|
|
|
|
dossier.state = 'refuse'
|
|
|
|
|
dossier.processed_at = dossier.created_at + 1.minute
|
|
|
|
|
dossier.en_construction_at = dossier.created_at + 2.minutes
|
|
|
|
|
dossier.created_at = dossier.created_at + 3.minutes
|
|
|
|
|
dossier.save!
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
trait :sans_suite do
|
|
|
|
|
after(:create) do |dossier, _evaluator|
|
|
|
|
|
dossier.state = 'sans_suite'
|
|
|
|
|
dossier.processed_at = dossier.created_at + 1.minute
|
|
|
|
|
dossier.en_construction_at = dossier.created_at + 2.minutes
|
|
|
|
|
dossier.created_at = dossier.created_at + 3.minutes
|
|
|
|
|
dossier.save!
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
trait :with_motivation do
|
|
|
|
|
after(:create) do |dossier, _evaluator|
|
|
|
|
|
dossier.motivation = case dossier.state
|
|
|
|
|
when 'refuse'
|
|
|
|
|
'L’entreprise concernée n’est pas agréée.'
|
|
|
|
|
when 'sans_suite'
|
|
|
|
|
'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
|
|
|
|
|
end
|
|
|
|
|
end
|
2015-08-13 15:55:19 +02:00
|
|
|
|
end
|
2015-08-20 17:30:17 +02:00
|
|
|
|
end
|