demarches-normaliennes/spec/factories/dossier.rb

93 lines
2.5 KiB
Ruby
Raw Normal View History

FactoryGirl.define do
factory :dossier do
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|
unless dossier.procedure
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
trait :with_entreprise do
2015-08-20 16:25:54 +02:00
after(:build) do |dossier, _evaluator|
etablissement = create(:etablissement)
entreprise = create(:entreprise, etablissement: etablissement)
dossier.entreprise = entreprise
dossier.etablissement = etablissement
end
end
2017-01-03 12:53:27 +01:00
trait :for_individual do
after(:build) do |dossier, _evaluator|
dossier.individual = create :individual
dossier.save
end
end
trait :with_two_quartier_prioritaires do
after(:build) do |dossier, _evaluator|
dossier.quartier_prioritaires << create(:quartier_prioritaire)
dossier.quartier_prioritaires << create(:quartier_prioritaire)
end
end
2016-01-18 12:03:18 +01:00
trait :with_two_cadastres do
after(:build) do |dossier, _evaluator|
dossier.cadastres << create(:cadastre)
dossier.cadastres << create(:cadastre)
end
end
2016-01-18 12:03:18 +01:00
trait :with_cerfa_upload do
after(:build) do |dossier, _evaluator|
dossier.cerfa << create(:cerfa)
2016-01-18 12:03:18 +01:00
end
end
trait :archived do
archived true
end
trait :not_archived do
archived false
end
trait :with_dossier_link do
after(:create) do |dossier, _evaluator|
linked_dossier = create(:dossier)
type_de_champ = dossier.procedure.types_de_champ.find { |t| t.type_champ == 'dossier_link' }
champ = dossier.champs.find { |c| c.type_de_champ == type_de_champ }
champ.value = linked_dossier.id
champ.save!
end
end
trait :followed do
after(:create) do |dossier, _evaluator|
g = create(:gestionnaire)
g.followed_dossiers << dossier
end
end
trait :en_construction do
2017-10-05 10:50:44 +02:00
after(:create) do |dossier, _evaluator|
dossier.state = 'en_construction'
dossier.en_construction_at = dossier.created_at + 1.minute
2017-10-05 10:50:44 +02:00
dossier.save!
end
end
trait :en_instruction do
after(:create) do |dossier, _evaluator|
dossier.state = 'en_instruction'
dossier.en_construction_at = dossier.created_at + 1.minute
dossier.created_at = dossier.created_at + 2.minute
dossier.save!
end
end
end
2015-08-20 17:30:17 +02:00
end