From aefdd5d2a1b50bca3f6f71e7ab6451af7526286c Mon Sep 17 00:00:00 2001 From: Pierre de La Morinerie Date: Mon, 20 Jul 2020 16:30:29 +0200 Subject: [PATCH] models: require belong_to associations on attestation_template --- app/models/attestation_template.rb | 2 +- spec/factories/attestation_template.rb | 2 ++ spec/factories/dossier.rb | 4 ++-- spec/models/dossier_spec.rb | 2 +- 4 files changed, 6 insertions(+), 4 deletions(-) diff --git a/app/models/attestation_template.rb b/app/models/attestation_template.rb index af5f19b86..6f440d1fd 100644 --- a/app/models/attestation_template.rb +++ b/app/models/attestation_template.rb @@ -15,7 +15,7 @@ class AttestationTemplate < ApplicationRecord include ActionView::Helpers::NumberHelper include TagsSubstitutionConcern - belongs_to :procedure + belongs_to :procedure, optional: false has_one_attached :logo has_one_attached :signature diff --git a/spec/factories/attestation_template.rb b/spec/factories/attestation_template.rb index 6e6110363..eb3e98727 100644 --- a/spec/factories/attestation_template.rb +++ b/spec/factories/attestation_template.rb @@ -4,6 +4,8 @@ FactoryBot.define do body { 'body' } footer { 'footer' } activated { true } + + association :procedure end trait :with_files do diff --git a/spec/factories/dossier.rb b/spec/factories/dossier.rb index 51c2995e7..c84a46d95 100644 --- a/spec/factories/dossier.rb +++ b/spec/factories/dossier.rb @@ -183,9 +183,9 @@ FactoryBot.define do end trait :with_attestation do - after(:create) do |dossier, _evaluator| + after(:build) do |dossier, _evaluator| if dossier.procedure.attestation_template.blank? - dossier.procedure.attestation_template = create(:attestation_template) + dossier.procedure.attestation_template = build(:attestation_template) end dossier.attestation = dossier.build_attestation end diff --git a/spec/models/dossier_spec.rb b/spec/models/dossier_spec.rb index 732209a4b..e699b4d13 100644 --- a/spec/models/dossier_spec.rb +++ b/spec/models/dossier_spec.rb @@ -563,7 +563,7 @@ describe Dossier do # - with a dash in the champ libelle / tag let(:title) { "voici --specified champ-in-title-- un --unspecified champ-in-title-- beau --specified annotation privée-in-title-- titre --unspecified annotation privée-in-title-- non --numéro du dossier--" } let(:body) { "voici --specified champ-in-body-- un --unspecified champ-in-body-- beau --specified annotation privée-in-body-- body --unspecified annotation privée-in-body-- non ?" } - let(:attestation_template) { create(:attestation_template, title: title, body: body, activated: activated) } + let(:attestation_template) { build(:attestation_template, title: title, body: body, activated: activated) } context "which is disabled" do let(:activated) { false }