Merge pull request #4920 from tchak/keep-operation-logs-after-dossiers-removal

Keep operation logs after dossier removal
This commit is contained in:
Paul Chavard 2020-03-24 09:29:03 +01:00 committed by GitHub
commit b2706b9031
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 2 deletions

View file

@ -38,7 +38,7 @@ class Dossier < ApplicationRecord
has_many :previous_followers_instructeurs, -> { distinct }, through: :previous_follows, source: :instructeur has_many :previous_followers_instructeurs, -> { distinct }, through: :previous_follows, source: :instructeur
has_many :avis, inverse_of: :dossier, dependent: :destroy has_many :avis, inverse_of: :dossier, dependent: :destroy
has_many :dossier_operation_logs, dependent: :destroy has_many :dossier_operation_logs, dependent: :nullify
belongs_to :groupe_instructeur belongs_to :groupe_instructeur
has_one :procedure, through: :groupe_instructeur has_one :procedure, through: :groupe_instructeur

View file

@ -12,8 +12,9 @@ class DossierOperationLog < ApplicationRecord
demander_un_avis: 'demander_un_avis' demander_un_avis: 'demander_un_avis'
} }
belongs_to :dossier
has_one_attached :serialized has_one_attached :serialized
belongs_to :dossier, optional: true
belongs_to :bill_signature, optional: true belongs_to :bill_signature, optional: true
def self.create_and_serialize(params) def self.create_and_serialize(params)

View file

@ -1131,4 +1131,17 @@ describe Dossier do
end end
end end
end end
describe 'dossier_operation_log after dossier deletion' do
let(:dossier) { create(:dossier) }
let(:dossier_operation_log) { create(:dossier_operation_log, dossier: dossier) }
it 'should nullify dossier link' do
expect(dossier_operation_log.dossier).to eq(dossier)
expect(DossierOperationLog.count).to eq(1)
dossier.destroy
expect(dossier_operation_log.reload.dossier).to be_nil
expect(DossierOperationLog.count).to eq(1)
end
end
end end