2018-01-23 17:15:42 +01:00
|
|
|
FactoryBot.define do
|
2016-06-24 16:41:44 +02:00
|
|
|
sequence(:published_path) { |n| "fake_path#{n}" }
|
2015-09-21 17:59:03 +02:00
|
|
|
factory :procedure do
|
2017-04-12 11:18:28 +02:00
|
|
|
sequence(:libelle) { |n| "Procedure #{n}" }
|
2018-09-04 16:46:48 +02:00
|
|
|
description { "Demande de subvention à l'intention des associations" }
|
2020-02-10 12:52:06 +01:00
|
|
|
organisation { "Orga DINUM" }
|
|
|
|
direction { "direction DINUM" }
|
2018-09-04 16:46:48 +02:00
|
|
|
cadre_juridique { "un cadre juridique important" }
|
|
|
|
published_at { nil }
|
|
|
|
duree_conservation_dossiers_dans_ds { 3 }
|
|
|
|
duree_conservation_dossiers_hors_ds { 6 }
|
2019-01-07 12:17:11 +01:00
|
|
|
ask_birthday { false }
|
2019-07-11 16:07:00 +02:00
|
|
|
lien_site_web { "https://mon-site.gouv" }
|
2019-09-17 15:55:35 +02:00
|
|
|
path { SecureRandom.uuid }
|
2015-09-21 17:59:03 +02:00
|
|
|
|
2019-02-26 16:57:04 +01:00
|
|
|
transient do
|
2020-03-05 11:03:39 +01:00
|
|
|
administrateur { }
|
2019-08-21 14:25:21 +02:00
|
|
|
instructeurs { [] }
|
2019-02-26 16:57:04 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
after(:build) do |procedure, evaluator|
|
|
|
|
if evaluator.administrateur
|
|
|
|
procedure.administrateurs = [evaluator.administrateur]
|
|
|
|
elsif procedure.administrateurs.empty?
|
|
|
|
procedure.administrateurs = [create(:administrateur)]
|
|
|
|
end
|
2019-01-29 11:49:28 +01:00
|
|
|
end
|
|
|
|
|
2019-08-21 14:25:21 +02:00
|
|
|
after(:create) do |procedure, evaluator|
|
|
|
|
evaluator.instructeurs.each { |i| i.assign_to_procedure(procedure) }
|
|
|
|
end
|
|
|
|
|
2018-07-03 20:18:06 +02:00
|
|
|
factory :procedure_with_dossiers do
|
|
|
|
transient do
|
2018-09-04 16:46:48 +02:00
|
|
|
dossiers_count { 1 }
|
2018-07-03 20:18:06 +02:00
|
|
|
end
|
|
|
|
|
2019-08-26 15:31:44 +02:00
|
|
|
after(:create) do |procedure, evaluator|
|
|
|
|
user = create(:user)
|
|
|
|
evaluator.dossiers_count.times do
|
|
|
|
dossier = procedure.new_dossier
|
|
|
|
dossier.user = user
|
|
|
|
dossier.save!
|
|
|
|
end
|
2018-07-03 20:18:06 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-09-24 15:54:46 +02:00
|
|
|
factory :simple_procedure do
|
|
|
|
after(:build) do |procedure, _evaluator|
|
|
|
|
procedure.for_individual = true
|
2020-07-20 15:50:21 +02:00
|
|
|
procedure.types_de_champ << build(:type_de_champ, libelle: 'Texte obligatoire', mandatory: true)
|
2019-07-30 16:54:43 +02:00
|
|
|
procedure.path = generate(:published_path)
|
|
|
|
procedure.publish!
|
2018-09-24 15:54:46 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-03-27 12:32:38 +01:00
|
|
|
trait :with_logo do
|
2020-06-30 17:53:54 +02:00
|
|
|
logo { Rack::Test::UploadedFile.new('spec/fixtures/files/logo_test_procedure.png', 'image/png') }
|
2019-08-22 11:12:35 +02:00
|
|
|
end
|
2019-03-27 12:32:38 +01:00
|
|
|
|
2018-08-13 17:49:15 +02:00
|
|
|
trait :with_path do
|
2018-10-25 17:40:23 +02:00
|
|
|
path { generate(:published_path) }
|
2018-08-13 17:49:15 +02:00
|
|
|
end
|
|
|
|
|
2018-06-19 16:23:43 +02:00
|
|
|
trait :with_service do
|
|
|
|
after(:build) do |procedure, _evaluator|
|
|
|
|
procedure.service = create(:service)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-08-06 11:02:54 +02:00
|
|
|
trait :with_instructeur do
|
2019-08-21 14:09:56 +02:00
|
|
|
after(:create) do |procedure, _evaluator|
|
|
|
|
procedure.defaut_groupe_instructeur.instructeurs << create(:instructeur)
|
2018-11-26 21:25:50 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-10-15 10:29:07 +02:00
|
|
|
trait :routee do
|
|
|
|
after(:create) do |procedure, _evaluator|
|
|
|
|
procedure.groupe_instructeurs.create(label: '2nd groupe')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-12-19 17:15:59 +01:00
|
|
|
trait :for_individual do
|
|
|
|
after(:build) do |procedure, _evaluator|
|
|
|
|
procedure.for_individual = true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-05-20 16:50:48 +02:00
|
|
|
trait :with_auto_archive do
|
|
|
|
auto_archive_on { Time.zone.today + 20 }
|
|
|
|
end
|
|
|
|
|
2015-11-05 11:21:44 +01:00
|
|
|
trait :with_type_de_champ do
|
2017-05-26 17:22:54 +02:00
|
|
|
transient do
|
2018-09-04 16:46:48 +02:00
|
|
|
types_de_champ_count { 1 }
|
2017-05-26 17:22:54 +02:00
|
|
|
end
|
2015-10-27 17:31:08 +01:00
|
|
|
|
2017-05-26 17:22:54 +02:00
|
|
|
after(:build) do |procedure, evaluator|
|
|
|
|
evaluator.types_de_champ_count.times do
|
2020-07-20 15:50:21 +02:00
|
|
|
type_de_champ = build(:type_de_champ)
|
2017-05-26 17:22:54 +02:00
|
|
|
|
|
|
|
procedure.types_de_champ << type_de_champ
|
|
|
|
end
|
2015-10-27 17:31:08 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-08-03 18:19:56 +02:00
|
|
|
trait :with_type_de_champ_private do
|
2017-10-02 17:03:38 +02:00
|
|
|
transient do
|
2018-09-04 16:46:48 +02:00
|
|
|
types_de_champ_private_count { 1 }
|
2017-10-02 17:03:38 +02:00
|
|
|
end
|
2016-08-03 18:19:56 +02:00
|
|
|
|
2017-10-02 17:03:38 +02:00
|
|
|
after(:build) do |procedure, evaluator|
|
|
|
|
evaluator.types_de_champ_private_count.times do
|
2020-07-20 15:50:21 +02:00
|
|
|
type_de_champ = build(:type_de_champ, :private)
|
2017-10-02 17:03:38 +02:00
|
|
|
|
|
|
|
procedure.types_de_champ_private << type_de_champ
|
|
|
|
end
|
2016-08-03 18:19:56 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-03-15 17:17:56 +01:00
|
|
|
trait :with_type_de_champ_mandatory do
|
|
|
|
after(:build) do |procedure, _evaluator|
|
2020-07-20 15:50:21 +02:00
|
|
|
type_de_champ = build(:type_de_champ, mandatory: true)
|
2016-03-15 17:17:56 +01:00
|
|
|
|
|
|
|
procedure.types_de_champ << type_de_champ
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-06-22 11:25:41 +02:00
|
|
|
trait :with_datetime do
|
|
|
|
after(:build) do |procedure, _evaluator|
|
2020-07-20 15:50:21 +02:00
|
|
|
type_de_champ = build(:type_de_champ_datetime, mandatory: true)
|
2016-06-22 11:25:41 +02:00
|
|
|
|
|
|
|
procedure.types_de_champ << type_de_champ
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-04-17 17:20:32 +02:00
|
|
|
trait :with_dossier_link do
|
|
|
|
after(:build) do |procedure, _evaluator|
|
2020-07-20 15:50:21 +02:00
|
|
|
type_de_champ = build(:type_de_champ_dossier_link)
|
2017-04-17 17:20:32 +02:00
|
|
|
|
|
|
|
procedure.types_de_champ << type_de_champ
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-06-26 11:00:36 +02:00
|
|
|
trait :with_yes_no do
|
|
|
|
after(:build) do |procedure, _evaluator|
|
2020-07-20 15:50:21 +02:00
|
|
|
type_de_champ = build(:type_de_champ_yes_no)
|
2017-06-26 11:00:36 +02:00
|
|
|
|
|
|
|
procedure.types_de_champ << type_de_champ
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-05-29 18:28:27 +02:00
|
|
|
trait :with_piece_justificative do
|
|
|
|
after(:build) do |procedure, _evaluator|
|
2020-07-20 15:50:21 +02:00
|
|
|
type_de_champ = build(:type_de_champ_piece_justificative)
|
|
|
|
|
2019-05-29 18:28:27 +02:00
|
|
|
procedure.types_de_champ << type_de_champ
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-02-07 15:35:09 +01:00
|
|
|
trait :with_repetition do
|
|
|
|
after(:build) do |procedure, _evaluator|
|
2020-07-20 15:50:21 +02:00
|
|
|
type_de_champ = build(:type_de_champ_repetition)
|
2020-02-07 15:35:09 +01:00
|
|
|
procedure.types_de_champ << type_de_champ
|
|
|
|
|
2020-07-20 15:50:21 +02:00
|
|
|
type_de_champ.types_de_champ << build(:type_de_champ, libelle: 'sub type de champ')
|
2020-02-07 15:35:09 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-02-20 13:25:32 +01:00
|
|
|
trait :with_number do
|
|
|
|
after(:build) do |procedure, _evaluator|
|
2020-07-20 15:50:21 +02:00
|
|
|
type_de_champ = build(:type_de_champ_number)
|
2020-02-20 13:25:32 +01:00
|
|
|
|
|
|
|
procedure.types_de_champ << type_de_champ
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-06-09 17:49:38 +02:00
|
|
|
trait :published do
|
2018-05-17 15:42:51 +02:00
|
|
|
after(:build) do |procedure, _evaluator|
|
2019-07-30 16:54:43 +02:00
|
|
|
procedure.path = generate(:published_path)
|
|
|
|
procedure.publish!
|
2016-06-09 17:49:38 +02:00
|
|
|
end
|
|
|
|
end
|
2017-07-04 13:52:08 +02:00
|
|
|
|
2019-11-14 09:43:45 +01:00
|
|
|
trait :closed do
|
2017-07-04 13:52:08 +02:00
|
|
|
after(:build) do |procedure, _evaluator|
|
2019-07-30 16:54:43 +02:00
|
|
|
procedure.path = generate(:published_path)
|
|
|
|
procedure.publish!
|
2019-11-14 09:43:45 +01:00
|
|
|
procedure.close!
|
2018-12-03 13:57:59 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-12-04 15:45:06 +01:00
|
|
|
trait :unpublished do
|
|
|
|
after(:build) do |procedure, _evaluator|
|
|
|
|
procedure.path = generate(:published_path)
|
|
|
|
procedure.publish!
|
|
|
|
procedure.unpublish!
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-02-05 16:09:03 +01:00
|
|
|
trait :discarded do
|
2020-03-26 09:08:52 +01:00
|
|
|
hidden_at { Time.zone.now }
|
2017-07-04 13:52:08 +02:00
|
|
|
end
|
2018-02-21 18:32:07 +01:00
|
|
|
|
2018-05-30 14:21:17 +02:00
|
|
|
trait :whitelisted do
|
|
|
|
after(:build) do |procedure, _evaluator|
|
2018-10-25 15:07:15 +02:00
|
|
|
procedure.update(whitelisted_at: Time.zone.now)
|
2018-05-30 14:21:17 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-04-26 14:36:27 +02:00
|
|
|
trait :with_notice do
|
|
|
|
after(:create) do |procedure, _evaluator|
|
|
|
|
procedure.notice.attach(
|
|
|
|
io: StringIO.new('Hello World'),
|
2018-05-31 11:00:22 +02:00
|
|
|
filename: 'hello.txt'
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
trait :with_deliberation do
|
|
|
|
after(:create) do |procedure, _evaluator|
|
|
|
|
procedure.deliberation.attach(
|
|
|
|
io: StringIO.new('Hello World'),
|
2018-04-26 14:36:27 +02:00
|
|
|
filename: 'hello.txt'
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-02-21 18:32:07 +01:00
|
|
|
trait :with_all_champs_mandatory do
|
|
|
|
after(:build) do |procedure, _evaluator|
|
2018-11-22 00:14:16 +01:00
|
|
|
procedure.types_de_champ = TypeDeChamp.type_champs.map.with_index do |(libelle, type_champ), index|
|
|
|
|
if libelle == 'drop_down_list'
|
|
|
|
libelle = 'simple_drop_down_list'
|
|
|
|
end
|
|
|
|
build(:"type_de_champ_#{type_champ}", mandatory: true, libelle: libelle, order_place: index)
|
|
|
|
end
|
2020-06-24 10:55:53 +02:00
|
|
|
procedure.types_de_champ << build(:type_de_champ_drop_down_list, :long, mandatory: true, libelle: 'simple_choice_drop_down_list_long')
|
|
|
|
procedure.types_de_champ << build(:type_de_champ_multiple_drop_down_list, :long, mandatory: true, libelle: 'multiple_choice_drop_down_list_long')
|
2018-11-22 00:14:16 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
trait :with_all_champs do
|
|
|
|
after(:build) do |procedure, _evaluator|
|
|
|
|
procedure.types_de_champ = TypeDeChamp.type_champs.map.with_index do |(libelle, type_champ), index|
|
|
|
|
if libelle == 'drop_down_list'
|
|
|
|
libelle = 'simple_drop_down_list'
|
|
|
|
end
|
|
|
|
build(:"type_de_champ_#{type_champ}", libelle: libelle, order_place: index)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
trait :with_all_annotations do
|
|
|
|
after(:build) do |procedure, _evaluator|
|
|
|
|
procedure.types_de_champ_private = TypeDeChamp.type_champs.map.with_index do |(libelle, type_champ), index|
|
|
|
|
if libelle == 'drop_down_list'
|
|
|
|
libelle = 'simple_drop_down_list'
|
|
|
|
end
|
|
|
|
build(:"type_de_champ_#{type_champ}", private: true, libelle: libelle, order_place: index)
|
|
|
|
end
|
2018-02-21 18:32:07 +01:00
|
|
|
end
|
|
|
|
end
|
2015-09-21 17:59:03 +02:00
|
|
|
end
|
|
|
|
end
|