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.
This commit is contained in:
parent
a56dc0f653
commit
ec6ec6f4aa
2 changed files with 11 additions and 20 deletions
|
@ -1,27 +1,16 @@
|
||||||
FactoryBot.define do
|
FactoryBot.define do
|
||||||
|
sequence(:expert_email) { |n| "expert#{n}@expert.com" }
|
||||||
|
|
||||||
factory :avis do
|
factory :avis do
|
||||||
|
email { generate(:expert_email) }
|
||||||
introduction { 'Bonjour, merci de me donner votre avis sur ce dossier' }
|
introduction { 'Bonjour, merci de me donner votre avis sur ce dossier' }
|
||||||
|
confidentiel { false }
|
||||||
|
|
||||||
before(:create) do |avis, _evaluator|
|
association :dossier
|
||||||
if !avis.instructeur
|
association :claimant, factory: :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
|
|
||||||
|
|
||||||
trait :with_answer do
|
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
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,9 +1,11 @@
|
||||||
describe 'instructeurs/avis/instruction.html.haml', type: :view do
|
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
|
before do
|
||||||
assign(:avis, avis)
|
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)
|
allow(view).to receive(:current_instructeur).and_return(avis.instructeur)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue