Dossier Factory: link procedure by defaut_groupe_instructeur

Oblige to create procedure or dossier to access groupe_instructeur
This commit is contained in:
simon lehericey 2019-08-26 15:27:43 +02:00
parent 74096b6b3a
commit 6cbdba2665
3 changed files with 33 additions and 27 deletions

View file

@ -4,11 +4,17 @@ FactoryBot.define do
state { Dossier.states.fetch(:brouillon) } state { Dossier.states.fetch(:brouillon) }
association :user, factory: [:user] association :user, factory: [:user]
before(:create) do |dossier, _evaluator| transient do
if !dossier.procedure procedure { nil }
procedure = create(:procedure, :published, :with_type_de_champ, :with_type_de_champ_private)
dossier.procedure = procedure
end 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)
end
dossier.groupe_instructeur = procedure.defaut_groupe_instructeur
end end
trait :with_entreprise do trait :with_entreprise do

View file

@ -1,8 +1,8 @@
describe IndividualSerializer do describe IndividualSerializer do
describe '#attributes' do describe '#attributes' do
let(:procedure) { build(:procedure) } let(:procedure) { create(:procedure) }
let(:dossier) { build(:dossier, procedure: procedure) } let(:dossier) { create(:dossier, procedure: procedure) }
let(:individual) { build(:individual, gender: 'M.', nom: 'nom', prenom: 'prenom', birthdate: Date.new(2001, 8, 27), dossier: dossier) } let(:individual) { create(:individual, gender: 'M.', nom: 'nom', prenom: 'prenom', birthdate: Date.new(2001, 8, 27), dossier: dossier) }
subject { IndividualSerializer.new(individual).serializable_hash } subject { IndividualSerializer.new(individual).serializable_hash }
@ -12,7 +12,7 @@ describe IndividualSerializer do
it { is_expected.not_to have_key(:date_naissance) } it { is_expected.not_to have_key(:date_naissance) }
context 'when the procedure asks for a birthdate' do 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)) } it { is_expected.to include(date_naissance: Date.new(2001, 8, 27)) }
end end

View file

@ -90,13 +90,13 @@ describe AdministrateurUsageStatisticsService do
end end
context 'with a procedure archivee' do context 'with a procedure archivee' do
let(:procedure) { create(:procedure, aasm_state: 'archivee', dossiers: dossiers) } let(:procedure) { create(:procedure, aasm_state: 'archivee') }
let(:dossiers) do let!(:dossiers) do
(1..7).flat_map do (1..7).flat_map do
[ [
create(:dossier, :en_construction), create(:dossier, :en_construction, procedure: procedure),
create(:dossier, :en_instruction), create(:dossier, :en_instruction, procedure: procedure),
create(:dossier, :accepte) create(:dossier, :accepte, procedure: procedure)
] ]
end end
end end
@ -141,13 +141,13 @@ describe AdministrateurUsageStatisticsService do
end end
context 'with a procedure en test' do context 'with a procedure en test' do
let(:procedure) { create(:procedure, dossiers: dossiers) } let(:procedure) { create(:procedure) }
let(:dossiers) do let!(:dossiers) do
(1..7).flat_map do (1..7).flat_map do
[ [
create(:dossier, :en_construction), create(:dossier, :en_construction, procedure: procedure),
create(:dossier, :en_instruction), create(:dossier, :en_instruction, procedure: procedure),
create(:dossier, :accepte) create(:dossier, :accepte, procedure: procedure)
] ]
end end
end end
@ -171,12 +171,12 @@ describe AdministrateurUsageStatisticsService do
end end
context 'with a procedure en prod' do context 'with a procedure en prod' do
let(:procedure) { create(:procedure, aasm_state: 'publiee', dossiers: dossiers) } let(:procedure) { create(:procedure, aasm_state: 'publiee') }
let(:dossiers) do let!(:dossiers) do
[ [
create(:dossier, :en_construction), create(:dossier, :en_construction, procedure: procedure),
create(:dossier, :en_instruction), create(:dossier, :en_instruction, procedure: procedure),
create(:dossier, :accepte) create(:dossier, :accepte, procedure: procedure)
] ]
end end
@ -199,13 +199,13 @@ describe AdministrateurUsageStatisticsService do
end end
context 'with a procedure en prod and more than 20 dossiers' do context 'with a procedure en prod and more than 20 dossiers' do
let(:procedure) { create(:procedure, aasm_state: 'publiee', dossiers: dossiers) } let(:procedure) { create(:procedure, aasm_state: 'publiee') }
let(:dossiers) do let!(:dossiers) do
(1..7).flat_map do (1..7).flat_map do
[ [
create(:dossier, :en_construction), create(:dossier, :en_construction, procedure: procedure),
create(:dossier, :en_instruction), create(:dossier, :en_instruction, procedure: procedure),
create(:dossier, :accepte) create(:dossier, :accepte, procedure: procedure)
] ]
end end
end end