models: require belong_to associations on attestation_template

This commit is contained in:
Pierre de La Morinerie 2020-07-20 16:30:29 +02:00
parent 1ea4c2aa36
commit aefdd5d2a1
4 changed files with 6 additions and 4 deletions

View file

@ -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

View file

@ -4,6 +4,8 @@ FactoryBot.define do
body { 'body' }
footer { 'footer' }
activated { true }
association :procedure
end
trait :with_files do

View file

@ -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

View file

@ -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 }