diff --git a/spec/factories/dossier.rb b/spec/factories/dossier.rb index 7f90b5689..f828ff27f 100644 --- a/spec/factories/dossier.rb +++ b/spec/factories/dossier.rb @@ -4,11 +4,17 @@ FactoryBot.define do state { Dossier.states.fetch(:brouillon) } association :user, factory: [:user] - before(:create) do |dossier, _evaluator| - if !dossier.procedure + transient do + procedure { nil } + end + + after(:build) do |dossier, evaluator| + if evaluator.procedure.present? + procedure = evaluator.procedure + else procedure = create(:procedure, :published, :with_type_de_champ, :with_type_de_champ_private) - dossier.procedure = procedure end + dossier.groupe_instructeur = procedure.defaut_groupe_instructeur end trait :with_entreprise do diff --git a/spec/serializers/individual_serializer_spec.rb b/spec/serializers/individual_serializer_spec.rb index 0617957f3..24ed39302 100644 --- a/spec/serializers/individual_serializer_spec.rb +++ b/spec/serializers/individual_serializer_spec.rb @@ -1,8 +1,8 @@ describe IndividualSerializer do describe '#attributes' do - let(:procedure) { build(:procedure) } - let(:dossier) { build(:dossier, procedure: procedure) } - let(:individual) { build(:individual, gender: 'M.', nom: 'nom', prenom: 'prenom', birthdate: Date.new(2001, 8, 27), dossier: dossier) } + let(:procedure) { create(:procedure) } + let(:dossier) { create(:dossier, procedure: procedure) } + let(:individual) { create(:individual, gender: 'M.', nom: 'nom', prenom: 'prenom', birthdate: Date.new(2001, 8, 27), dossier: dossier) } subject { IndividualSerializer.new(individual).serializable_hash } @@ -12,7 +12,7 @@ describe IndividualSerializer do it { is_expected.not_to have_key(:date_naissance) } context 'when the procedure asks for a birthdate' do - let(:procedure) { build(:procedure, ask_birthday: true) } + before { procedure.update(ask_birthday: true) } it { is_expected.to include(date_naissance: Date.new(2001, 8, 27)) } end diff --git a/spec/services/administrateur_usage_statistics_service_spec.rb b/spec/services/administrateur_usage_statistics_service_spec.rb index 2aaa44ff5..60eb299f0 100644 --- a/spec/services/administrateur_usage_statistics_service_spec.rb +++ b/spec/services/administrateur_usage_statistics_service_spec.rb @@ -90,13 +90,13 @@ describe AdministrateurUsageStatisticsService do end context 'with a procedure archivee' do - let(:procedure) { create(:procedure, aasm_state: 'archivee', dossiers: dossiers) } - let(:dossiers) do + let(:procedure) { create(:procedure, aasm_state: 'archivee') } + let!(:dossiers) do (1..7).flat_map do [ - create(:dossier, :en_construction), - create(:dossier, :en_instruction), - create(:dossier, :accepte) + create(:dossier, :en_construction, procedure: procedure), + create(:dossier, :en_instruction, procedure: procedure), + create(:dossier, :accepte, procedure: procedure) ] end end @@ -141,13 +141,13 @@ describe AdministrateurUsageStatisticsService do end context 'with a procedure en test' do - let(:procedure) { create(:procedure, dossiers: dossiers) } - let(:dossiers) do + let(:procedure) { create(:procedure) } + let!(:dossiers) do (1..7).flat_map do [ - create(:dossier, :en_construction), - create(:dossier, :en_instruction), - create(:dossier, :accepte) + create(:dossier, :en_construction, procedure: procedure), + create(:dossier, :en_instruction, procedure: procedure), + create(:dossier, :accepte, procedure: procedure) ] end end @@ -171,12 +171,12 @@ describe AdministrateurUsageStatisticsService do end context 'with a procedure en prod' do - let(:procedure) { create(:procedure, aasm_state: 'publiee', dossiers: dossiers) } - let(:dossiers) do + let(:procedure) { create(:procedure, aasm_state: 'publiee') } + let!(:dossiers) do [ - create(:dossier, :en_construction), - create(:dossier, :en_instruction), - create(:dossier, :accepte) + create(:dossier, :en_construction, procedure: procedure), + create(:dossier, :en_instruction, procedure: procedure), + create(:dossier, :accepte, procedure: procedure) ] end @@ -199,13 +199,13 @@ describe AdministrateurUsageStatisticsService do end context 'with a procedure en prod and more than 20 dossiers' do - let(:procedure) { create(:procedure, aasm_state: 'publiee', dossiers: dossiers) } - let(:dossiers) do + let(:procedure) { create(:procedure, aasm_state: 'publiee') } + let!(:dossiers) do (1..7).flat_map do [ - create(:dossier, :en_construction), - create(:dossier, :en_instruction), - create(:dossier, :accepte) + create(:dossier, :en_construction, procedure: procedure), + create(:dossier, :en_instruction, procedure: procedure), + create(:dossier, :accepte, procedure: procedure) ] end end