models: require belong_to associations on invite
This commit is contained in:
parent
fe8804f208
commit
802d3804f5
2 changed files with 4 additions and 11 deletions
|
@ -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) }
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue