Merge pull request #6204 from tchak/fix_nullable_user

Dossier without user should be valid
This commit is contained in:
Paul Chavard 2021-05-11 17:59:54 +02:00 committed by GitHub
commit 61f49619ba
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 3 deletions

View file

@ -87,7 +87,7 @@ class Dossier < ApplicationRecord
belongs_to :groupe_instructeur, optional: true belongs_to :groupe_instructeur, optional: true
belongs_to :revision, class_name: 'ProcedureRevision', optional: false belongs_to :revision, class_name: 'ProcedureRevision', optional: false
belongs_to :user, optional: false belongs_to :user, optional: true
has_one :procedure, through: :revision has_one :procedure, through: :revision
has_many :types_de_champ, through: :revision has_many :types_de_champ, through: :revision
@ -349,7 +349,7 @@ class Dossier < ApplicationRecord
after_save :send_web_hook after_save :send_web_hook
after_create_commit :send_draft_notification_email after_create_commit :send_draft_notification_email
validates :user, presence: true validates :user, presence: true, if: -> { deleted_user_email_never_send.nil? }
validates :individual, presence: true, if: -> { revision.procedure.for_individual? } validates :individual, presence: true, if: -> { revision.procedure.for_individual? }
validates :groupe_instructeur, presence: true, if: -> { !brouillon? } validates :groupe_instructeur, presence: true, if: -> { !brouillon? }

View file

@ -332,7 +332,7 @@ describe User, type: :model do
end end
end end
context 'with dossiers with processing strted' do context 'with dossiers with processing started' do
let!(:dossier_en_instruction) { create(:dossier, :en_instruction, user: user) } let!(:dossier_en_instruction) { create(:dossier, :en_instruction, user: user) }
let!(:dossier_termine) { create(:dossier, :accepte, user: user) } let!(:dossier_termine) { create(:dossier, :accepte, user: user) }
@ -347,6 +347,7 @@ describe User, type: :model do
expect(dossier_termine.reload).to be_present expect(dossier_termine.reload).to be_present
expect(dossier_termine.user).to be_nil expect(dossier_termine.user).to be_nil
expect(dossier_termine.user_email_for(:display)).to eq(user.email) expect(dossier_termine.user_email_for(:display)).to eq(user.email)
expect(dossier_termine.valid?).to be_truthy
expect { dossier_termine.user_email_for(:notification) }.to raise_error(RuntimeError) expect { dossier_termine.user_email_for(:notification) }.to raise_error(RuntimeError)
expect(User.find_by(id: user.id)).to be_nil expect(User.find_by(id: user.id)).to be_nil