From ec6ec6f4aa892f0ac6237c22494dd0c10f3a2eff Mon Sep 17 00:00:00 2001 From: Pierre de La Morinerie Date: Mon, 21 Oct 2019 09:45:03 +0000 Subject: [PATCH] specs: improve avis factory The instructeur, dossier and claimant where created regardless of wether they already existed or not. With this commit: - Associations are declarated in a more idiomatic way - They are correctly not created if they are provided when creating the object. --- spec/factories/avis.rb | 25 ++++++------------- .../avis/instruction.html.haml_spec.rb | 6 +++-- 2 files changed, 11 insertions(+), 20 deletions(-) diff --git a/spec/factories/avis.rb b/spec/factories/avis.rb index aeec523d3..fedf3c6c7 100644 --- a/spec/factories/avis.rb +++ b/spec/factories/avis.rb @@ -1,27 +1,16 @@ FactoryBot.define do + sequence(:expert_email) { |n| "expert#{n}@expert.com" } + factory :avis do + email { generate(:expert_email) } introduction { 'Bonjour, merci de me donner votre avis sur ce dossier' } + confidentiel { false } - before(:create) do |avis, _evaluator| - if !avis.instructeur - avis.instructeur = create :instructeur - end - end - - before(:create) do |avis, _evaluator| - if !avis.dossier - avis.dossier = create :dossier - end - end - - before(:create) do |avis, _evaluator| - if !avis.claimant - avis.claimant = create :instructeur - end - end + association :dossier + association :claimant, factory: :instructeur trait :with_answer do - answer { "Mon avis se décompose en deux points :\n- La demande semble pertinente\n- Le demandeur remplit les conditions." } + answer { "Mon avis se décompose en deux points :\n- La demande semble pertinente\n- Le demandeur remplit les conditions." } end end end diff --git a/spec/views/instructeur/avis/instruction.html.haml_spec.rb b/spec/views/instructeur/avis/instruction.html.haml_spec.rb index 5d5800b4b..411d93f6c 100644 --- a/spec/views/instructeur/avis/instruction.html.haml_spec.rb +++ b/spec/views/instructeur/avis/instruction.html.haml_spec.rb @@ -1,9 +1,11 @@ describe 'instructeurs/avis/instruction.html.haml', type: :view do - let(:avis) { create(:avis, confidentiel: confidentiel) } + let(:expert) { create(:instructeur) } + let(:avis) { create(:avis, confidentiel: confidentiel, email: expert.email) } before do assign(:avis, avis) - @dossier = create(:dossier, :accepte) + assign(:new_avis, Avis.new) + assign(:dossier, avis.dossier) allow(view).to receive(:current_instructeur).and_return(avis.instructeur) end