models: require belong_to associations on avis
This commit is contained in:
parent
aefdd5d2a1
commit
32e55a6d37
3 changed files with 8 additions and 3 deletions
|
@ -17,9 +17,9 @@
|
|||
class Avis < ApplicationRecord
|
||||
include EmailSanitizableConcern
|
||||
|
||||
belongs_to :dossier, inverse_of: :avis, touch: true
|
||||
belongs_to :dossier, inverse_of: :avis, touch: true, optional: false
|
||||
belongs_to :instructeur, optional: true
|
||||
belongs_to :claimant, class_name: 'Instructeur'
|
||||
belongs_to :claimant, class_name: 'Instructeur', optional: false
|
||||
|
||||
has_one_attached :piece_justificative_file
|
||||
has_one_attached :introduction_file
|
||||
|
|
|
@ -9,6 +9,11 @@ FactoryBot.define do
|
|||
association :dossier
|
||||
association :claimant, factory: :instructeur
|
||||
|
||||
trait :with_instructeur do
|
||||
email { nil }
|
||||
instructeur { association :instructeur, email: generate(:expert_email) }
|
||||
end
|
||||
|
||||
trait :with_answer do
|
||||
answer { "Mon avis se décompose en deux points :\n- La demande semble pertinente\n- Le demandeur remplit les conditions." }
|
||||
end
|
||||
|
|
|
@ -87,7 +87,7 @@ RSpec.describe Avis, type: :model do
|
|||
|
||||
describe '#try_to_assign_instructeur' do
|
||||
let!(:instructeur) { create(:instructeur) }
|
||||
let(:avis) { Avis.create(claimant: claimant, email: email, dossier: create(:dossier)) }
|
||||
let(:avis) { create(:avis, claimant: claimant, email: email, dossier: create(:dossier)) }
|
||||
|
||||
context 'when the email belongs to a instructeur' do
|
||||
let(:email) { instructeur.email }
|
||||
|
|
Loading…
Reference in a new issue