Commit 1c180843 authored by charlie ablett's avatar charlie ablett

Sync destruction between requirements and issues

Changelog: added
EE: true
parent 3b143c7a
......@@ -20,7 +20,11 @@ module RequirementsManagement
belongs_to :author, inverse_of: :requirements, class_name: 'User'
belongs_to :project, inverse_of: :requirements
belongs_to :requirement_issue, class_name: 'Issue', foreign_key: :issue_id
# deleting an issue would result in deleting requirement record due to cascade delete via foreign key
# but to sync the other way around, we require a temporary `dependent: :destroy`
# See https://gitlab.com/gitlab-org/gitlab/-/issues/323779 for details.
# This will be removed in https://gitlab.com/gitlab-org/gitlab/-/issues/329432
belongs_to :requirement_issue, class_name: 'Issue', foreign_key: :issue_id, dependent: :destroy # rubocop:disable Cop/ActiveRecordDependent
validates :issue_id, uniqueness: true, allow_nil: true
......
......@@ -184,4 +184,21 @@ RSpec.describe RequirementsManagement::Requirement do
end
end
end
describe 'sync with requirement issues' do
let_it_be_with_reload(:requirement) { create(:requirement) }
let_it_be_with_reload(:requirement_issue) { create(:requirement_issue, requirement: requirement) }
context 'when destroying a requirement' do
it 'also destroys the associated requirement issue' do
expect { requirement.destroy! }.to change { Issue.where(issue_type: 'requirement').count }.by(-1)
end
end
context 'when destroying a requirement issue' do
it 'also destroys the associated requirement' do
expect { requirement_issue.destroy! }.to change { RequirementsManagement::Requirement.count }.by(-1)
end
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment