From 792ba73643de37f58404464b21ab4a16d1ef1ea1 Mon Sep 17 00:00:00 2001 From: Pierre de La Morinerie Date: Tue, 7 Jan 2020 17:50:49 +0100 Subject: [PATCH] factories: ensure that dossiers `with_entreprise` are consistent --- spec/controllers/api/v2/graphql_controller_spec.rb | 4 ++-- spec/factories/dossier.rb | 3 +++ spec/views/users/dossiers/brouillon.html.haml_spec.rb | 4 ++-- spec/views/users/dossiers/identite.html.haml_spec.rb | 4 ++-- 4 files changed, 9 insertions(+), 6 deletions(-) diff --git a/spec/controllers/api/v2/graphql_controller_spec.rb b/spec/controllers/api/v2/graphql_controller_spec.rb index 1177464eb..6c7d7e7f8 100644 --- a/spec/controllers/api/v2/graphql_controller_spec.rb +++ b/spec/controllers/api/v2/graphql_controller_spec.rb @@ -288,8 +288,8 @@ describe API::V2::GraphqlController do end context "with entreprise" do - let(:procedure) { create(:procedure, :published, administrateurs: [admin]) } - let(:dossier) { create(:dossier, :en_construction, :with_entreprise, procedure: procedure) } + let(:procedure_for_entreprise) { create(:procedure, :published, administrateurs: [admin]) } + let(:dossier) { create(:dossier, :en_construction, :with_entreprise, procedure: procedure_for_entreprise) } let(:query) do "{ diff --git a/spec/factories/dossier.rb b/spec/factories/dossier.rb index 504405f08..c0b563521 100644 --- a/spec/factories/dossier.rb +++ b/spec/factories/dossier.rb @@ -25,6 +25,9 @@ FactoryBot.define do trait :with_entreprise do after(:build) do |dossier, _evaluator| + if dossier.procedure.for_individual? + raise 'Inconsistent factory: attempting to create a dossier :with_entreprise on a procedure that is `for_individual?`' + end etablissement = create(:etablissement) dossier.etablissement = etablissement end diff --git a/spec/views/users/dossiers/brouillon.html.haml_spec.rb b/spec/views/users/dossiers/brouillon.html.haml_spec.rb index dc13af78a..1d66d554f 100644 --- a/spec/views/users/dossiers/brouillon.html.haml_spec.rb +++ b/spec/views/users/dossiers/brouillon.html.haml_spec.rb @@ -1,8 +1,8 @@ require 'spec_helper' describe 'users/dossiers/brouillon.html.haml', type: :view do - let(:procedure) { create(:procedure, :with_type_de_champ, :with_notice, :with_service, for_individual: true) } - let(:dossier) { create(:dossier, :with_entreprise, state: Dossier.states.fetch(:brouillon), procedure: procedure) } + let(:procedure) { create(:procedure, :with_type_de_champ, :with_notice, :with_service) } + let(:dossier) { create(:dossier, state: Dossier.states.fetch(:brouillon), procedure: procedure) } let(:footer) { view.content_for(:footer) } before do diff --git a/spec/views/users/dossiers/identite.html.haml_spec.rb b/spec/views/users/dossiers/identite.html.haml_spec.rb index b5d954c67..2f01ef41c 100644 --- a/spec/views/users/dossiers/identite.html.haml_spec.rb +++ b/spec/views/users/dossiers/identite.html.haml_spec.rb @@ -1,8 +1,8 @@ require 'spec_helper' describe 'users/dossiers/identite.html.haml', type: :view do - let(:procedure) { create(:simple_procedure, for_individual: true) } - let(:dossier) { create(:dossier, :with_entreprise, :with_service, state: Dossier.states.fetch(:brouillon), procedure: procedure) } + let(:procedure) { create(:simple_procedure, :for_individual) } + let(:dossier) { create(:dossier, :with_service, state: Dossier.states.fetch(:brouillon), procedure: procedure) } before do sign_in dossier.user