models: require belong_to associations on invite

This commit is contained in:
Pierre de La Morinerie 2020-07-20 16:56:23 +02:00
parent fe8804f208
commit 802d3804f5
2 changed files with 4 additions and 11 deletions

View file

@ -14,7 +14,7 @@
class Invite < ApplicationRecord
include EmailSanitizableConcern
belongs_to :dossier
belongs_to :dossier, optional: false
belongs_to :user, optional: true
before_validation -> { sanitize_email(:email) }

View file

@ -1,24 +1,17 @@
FactoryBot.define do
factory :invite do
email { 'plop@octo.com' }
user { nil }
association :dossier
after(:build) do |invite, _evaluator|
if invite.dossier.nil?
invite.dossier = create(:dossier)
end
if invite.user.present?
invite.email = invite.user.email
end
end
trait :with_user do
after(:build) do |invite, _evaluator|
if invite.user.nil?
invite.user = create(:user)
invite.email = invite.user.email
end
end
association :user
end
end
end