Commit ca923d48 authored by Sean McGivern's avatar Sean McGivern

Create system notes for group milestone changes

parent 149528f4
...@@ -2,11 +2,8 @@ class IssuableBaseService < BaseService ...@@ -2,11 +2,8 @@ class IssuableBaseService < BaseService
private private
def create_milestone_note(issuable) def create_milestone_note(issuable)
milestone = issuable.milestone
return if milestone && milestone.is_group_milestone?
SystemNoteService.change_milestone( SystemNoteService.change_milestone(
issuable, issuable.project, current_user, milestone) issuable, issuable.project, current_user, issuable.milestone)
end end
def create_labels_note(issuable, old_labels) def create_labels_note(issuable, old_labels)
......
...@@ -142,7 +142,8 @@ module SystemNoteService ...@@ -142,7 +142,8 @@ module SystemNoteService
# #
# Returns the created Note object # Returns the created Note object
def change_milestone(noteable, project, author, milestone) def change_milestone(noteable, project, author, milestone)
body = milestone.nil? ? 'removed milestone' : "changed milestone to #{milestone.to_reference(project)}" format = milestone&.is_group_milestone? ? :name : :iid
body = milestone.nil? ? 'removed milestone' : "changed milestone to #{milestone.to_reference(project, format: format)}"
create_note(NoteSummary.new(noteable, project, author, body, action: 'milestone')) create_note(NoteSummary.new(noteable, project, author, body, action: 'milestone'))
end end
......
...@@ -3,7 +3,8 @@ require 'spec_helper' ...@@ -3,7 +3,8 @@ require 'spec_helper'
describe SystemNoteService do describe SystemNoteService do
include Gitlab::Routing include Gitlab::Routing
let(:project) { create(:project) } let(:group) { create(:group) }
let(:project) { create(:project, group: group) }
let(:author) { create(:user) } let(:author) { create(:user) }
let(:noteable) { create(:issue, project: project) } let(:noteable) { create(:issue, project: project) }
let(:issue) { noteable } let(:issue) { noteable }
...@@ -242,25 +243,51 @@ describe SystemNoteService do ...@@ -242,25 +243,51 @@ describe SystemNoteService do
end end
describe '.change_milestone' do describe '.change_milestone' do
subject { described_class.change_milestone(noteable, project, author, milestone) } context 'for a project milestone' do
subject { described_class.change_milestone(noteable, project, author, milestone) }
let(:milestone) { create(:milestone, project: project) } let(:milestone) { create(:milestone, project: project) }
it_behaves_like 'a system note' do it_behaves_like 'a system note' do
let(:action) { 'milestone' } let(:action) { 'milestone' }
end end
context 'when milestone added' do context 'when milestone added' do
it 'sets the note text' do it 'sets the note text' do
expect(subject.note).to eq "changed milestone to #{milestone.to_reference}" expect(subject.note).to eq "changed milestone to #{milestone.to_reference}"
end
end
context 'when milestone removed' do
let(:milestone) { nil }
it 'sets the note text' do
expect(subject.note).to eq 'removed milestone'
end
end end
end end
context 'when milestone removed' do context 'for a group milestone' do
let(:milestone) { nil } subject { described_class.change_milestone(noteable, project, author, milestone) }
it 'sets the note text' do let(:milestone) { create(:milestone, group: group) }
expect(subject.note).to eq 'removed milestone'
it_behaves_like 'a system note' do
let(:action) { 'milestone' }
end
context 'when milestone added' do
it 'sets the note text to use the milestone name' do
expect(subject.note).to eq "changed milestone to #{milestone.to_reference(format: :name)}"
end
end
context 'when milestone removed' do
let(:milestone) { nil }
it 'sets the note text' do
expect(subject.note).to eq 'removed milestone'
end
end end
end end
end end
......
...@@ -21,15 +21,15 @@ shared_examples 'system notes for milestones' do ...@@ -21,15 +21,15 @@ shared_examples 'system notes for milestones' do
create(:group_member, group: group, user: user) create(:group_member, group: group, user: user)
end end
it 'does not create system note' do it 'creates a system note' do
expect do expect do
update_issuable(milestone: group_milestone) update_issuable(milestone: group_milestone)
end.not_to change { Note.system.count } end.to change { Note.system.count }.by(1)
end end
end end
context 'project milestones' do context 'project milestones' do
it 'creates system note' do it 'creates a system note' do
expect do expect do
update_issuable(milestone: create(:milestone)) update_issuable(milestone: create(:milestone))
end.to change { Note.system.count }.by(1) end.to change { Note.system.count }.by(1)
......
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