feat(fork): mark a fork as stale for future deletion, so it can't be reused

This commit is contained in:
Colin Darie 2023-04-27 12:25:30 +02:00
parent 76088d1ee8
commit 218c7d08c2
No known key found for this signature in database
GPG key ID: 4FB865FDBCA4BCC4
2 changed files with 8 additions and 1 deletions

View file

@ -6,7 +6,7 @@ module DossierCloneConcern
has_many :cloned_dossiers, class_name: 'Dossier', foreign_key: :parent_dossier_id, dependent: :nullify, inverse_of: :parent_dossier
belongs_to :editing_fork_origin, class_name: 'Dossier', optional: true
has_many :editing_forks, class_name: 'Dossier', foreign_key: :editing_fork_origin_id, dependent: :destroy, inverse_of: :editing_fork_origin
has_many :editing_forks, -> { where(hidden_by_reason: nil) }, class_name: 'Dossier', foreign_key: :editing_fork_origin_id, dependent: :destroy, inverse_of: :editing_fork_origin
end
def find_or_create_editing_fork(user)
@ -32,6 +32,7 @@ module DossierCloneConcern
def destroy_editing_fork!
if editing_fork?
update!(hidden_by_administration_at: Time.current, hidden_by_reason: :stale_fork)
DestroyRecordLaterJob.perform_later(self)
end
end

View file

@ -86,6 +86,12 @@ RSpec.describe DossierCloneConcern do
it 'update dossier search terms' do
expect { subject }.to have_enqueued_job(DossierUpdateSearchTermsJob).with(dossier)
end
it 'fork is hidden after merge' do
subject
expect(forked_dossier.reload.hidden_by_reason).to eq("stale_fork")
expect(dossier.reload.editing_forks).to be_empty
end
end
context 'with new revision' do