Commit ea5c25bb authored by Stan Hu's avatar Stan Hu

Remove milestones from merge requests when milestones are deleted

Reported by https://github.com/gitlabhq/gitlabhq/issues/9643
parent abaa65ef
...@@ -2,6 +2,7 @@ Please view this file on the master branch, on stable branches it's out of date. ...@@ -2,6 +2,7 @@ Please view this file on the master branch, on stable branches it's out of date.
v 8.0.0 (unreleased) v 8.0.0 (unreleased)
- Fix Markdown links not showing up in dashboard activity feed (Stan Hu) - Fix Markdown links not showing up in dashboard activity feed (Stan Hu)
- Remove milestones from merge requests when milestones are deleted (Stan Hu)
- Fix HTML link that was improperly escaped in new user e-mail (Stan Hu) - Fix HTML link that was improperly escaped in new user e-mail (Stan Hu)
- Fix broken sort in merge request API (Stan Hu) - Fix broken sort in merge request API (Stan Hu)
- Bump rouge to 1.10.1 to remove warning noise and fix other syntax highlighting bugs (Stan Hu) - Bump rouge to 1.10.1 to remove warning noise and fix other syntax highlighting bugs (Stan Hu)
......
...@@ -4,10 +4,15 @@ module Milestones ...@@ -4,10 +4,15 @@ module Milestones
Milestone.transaction do Milestone.transaction do
update_params = { milestone: nil } update_params = { milestone: nil }
milestone.issues.each do |issue| milestone.issues.each do |issue|
Issues::UpdateService.new(project, current_user, update_params).execute(issue) Issues::UpdateService.new(project, current_user, update_params).execute(issue)
end end
milestone.merge_requests.each do |merge_request|
MergeRequests::UpdateService.new(project, current_user, update_params).execute(merge_request)
end
event_service.destroy_milestone(milestone, current_user) event_service.destroy_milestone(milestone, current_user)
Event.for_milestone_id(milestone.id).each do |event| Event.for_milestone_id(milestone.id).each do |event|
......
...@@ -5,6 +5,7 @@ describe Projects::MilestonesController do ...@@ -5,6 +5,7 @@ describe Projects::MilestonesController do
let(:user) { create(:user) } let(:user) { create(:user) }
let(:milestone) { create(:milestone, project: project) } let(:milestone) { create(:milestone, project: project) }
let(:issue) { create(:issue, project: project, milestone: milestone) } let(:issue) { create(:issue, project: project, milestone: milestone) }
let(:merge_request) { create(:merge_request, source_project: project, target_project: project, milestone: milestone) }
before do before do
sign_in(user) sign_in(user)
...@@ -14,6 +15,7 @@ describe Projects::MilestonesController do ...@@ -14,6 +15,7 @@ describe Projects::MilestonesController do
describe "#destroy" do describe "#destroy" do
it "should remove milestone" do it "should remove milestone" do
merge_request.reload
expect(issue.milestone_id).to eq(milestone.id) expect(issue.milestone_id).to eq(milestone.id)
delete :destroy, namespace_id: project.namespace.id, project_id: project.id, id: milestone.id, format: :js delete :destroy, namespace_id: project.namespace.id, project_id: project.id, id: milestone.id, format: :js
...@@ -24,6 +26,10 @@ describe Projects::MilestonesController do ...@@ -24,6 +26,10 @@ describe Projects::MilestonesController do
expect { Milestone.find(milestone.id) }.to raise_exception(ActiveRecord::RecordNotFound) expect { Milestone.find(milestone.id) }.to raise_exception(ActiveRecord::RecordNotFound)
issue.reload issue.reload
expect(issue.milestone_id).to eq(nil) expect(issue.milestone_id).to eq(nil)
merge_request.reload
expect(merge_request.milestone_id).to eq(nil)
# Check system note left for milestone removal # Check system note left for milestone removal
last_note = project.issues.find(issue.id).notes[-1].note last_note = project.issues.find(issue.id).notes[-1].note
expect(last_note).to eq('Milestone removed') expect(last_note).to eq('Milestone removed')
......
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