2019-07-31 22:56:46 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe Issuable::CommonSystemNotesService do
|
2020-04-08 14:13:33 +05:30
|
|
|
let_it_be(:project) { create(:project) }
|
|
|
|
let_it_be(:user) { create(:user) }
|
|
|
|
|
2019-03-13 22:55:13 +05:30
|
|
|
let(:issuable) { create(:issue, project: project) }
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2019-02-15 15:39:39 +05:30
|
|
|
context 'on issuable update' do
|
2018-03-17 18:26:18 +05:30
|
|
|
it_behaves_like 'system note creation', { title: 'New title' }, 'changed title'
|
|
|
|
it_behaves_like 'system note creation', { description: 'New description' }, 'changed the description'
|
|
|
|
it_behaves_like 'system note creation', { discussion_locked: true }, 'locked this issue'
|
|
|
|
it_behaves_like 'system note creation', { time_estimate: 5 }, 'changed time estimate'
|
|
|
|
|
|
|
|
context 'when new label is added' do
|
2018-11-20 20:47:30 +05:30
|
|
|
let(:label) { create(:label, project: project) }
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
before do
|
|
|
|
issuable.labels << label
|
2018-11-20 20:47:30 +05:30
|
|
|
issuable.save
|
2018-03-17 18:26:18 +05:30
|
|
|
end
|
|
|
|
|
2018-11-20 20:47:30 +05:30
|
|
|
it 'creates a resource label event' do
|
2019-02-15 15:39:39 +05:30
|
|
|
described_class.new(project, user).execute(issuable, old_labels: [])
|
2018-11-20 20:47:30 +05:30
|
|
|
event = issuable.reload.resource_label_events.last
|
|
|
|
|
|
|
|
expect(event).not_to be_nil
|
|
|
|
expect(event.label_id).to eq label.id
|
|
|
|
expect(event.user_id).to eq user.id
|
|
|
|
end
|
2018-03-17 18:26:18 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
context 'when new milestone is assigned' do
|
|
|
|
before do
|
|
|
|
milestone = create(:milestone, project: project)
|
|
|
|
issuable.milestone_id = milestone.id
|
2020-04-08 14:13:33 +05:30
|
|
|
|
|
|
|
stub_feature_flags(track_resource_milestone_change_events: false)
|
2018-03-17 18:26:18 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it_behaves_like 'system note creation', {}, 'changed milestone'
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with merge requests WIP note' do
|
|
|
|
context 'adding WIP note' do
|
|
|
|
let(:issuable) { create(:merge_request, title: "merge request") }
|
|
|
|
|
|
|
|
it_behaves_like 'system note creation', { title: "WIP merge request" }, 'marked as a **Work In Progress**'
|
|
|
|
|
|
|
|
context 'and changing title' do
|
|
|
|
before do
|
|
|
|
issuable.update_attribute(:title, "WIP changed title")
|
|
|
|
end
|
|
|
|
|
|
|
|
it_behaves_like 'WIP notes creation', 'marked'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'removing WIP note' do
|
|
|
|
let(:issuable) { create(:merge_request, title: "WIP merge request") }
|
|
|
|
|
|
|
|
it_behaves_like 'system note creation', { title: "merge request" }, 'unmarked as a **Work In Progress**'
|
|
|
|
|
|
|
|
context 'and changing title' do
|
|
|
|
before do
|
|
|
|
issuable.update_attribute(:title, "changed title")
|
|
|
|
end
|
|
|
|
|
|
|
|
it_behaves_like 'WIP notes creation', 'unmarked'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2019-02-15 15:39:39 +05:30
|
|
|
|
|
|
|
context 'on issuable create' do
|
2019-03-13 22:55:13 +05:30
|
|
|
let(:issuable) { build(:issue, project: project) }
|
2019-02-15 15:39:39 +05:30
|
|
|
|
|
|
|
subject { described_class.new(project, user).execute(issuable, old_labels: [], is_update: false) }
|
|
|
|
|
|
|
|
it 'does not create system note for title and description' do
|
|
|
|
issuable.save
|
|
|
|
|
|
|
|
expect { subject }.not_to change { issuable.notes.count }
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'creates a resource label event for labels added' do
|
|
|
|
label = create(:label, project: project)
|
|
|
|
|
|
|
|
issuable.labels << label
|
|
|
|
issuable.save
|
|
|
|
|
|
|
|
expect { subject }.to change { issuable.resource_label_events.count }.from(0).to(1)
|
|
|
|
|
|
|
|
event = issuable.reload.resource_label_events.last
|
|
|
|
|
|
|
|
expect(event).not_to be_nil
|
|
|
|
expect(event.label_id).to eq label.id
|
|
|
|
expect(event.user_id).to eq user.id
|
|
|
|
end
|
|
|
|
|
2020-04-08 14:13:33 +05:30
|
|
|
context 'when milestone change event tracking is disabled' do
|
|
|
|
before do
|
|
|
|
stub_feature_flags(track_resource_milestone_change_events: false)
|
2019-02-15 15:39:39 +05:30
|
|
|
|
2020-04-08 14:13:33 +05:30
|
|
|
issuable.milestone = create(:milestone, project: project)
|
|
|
|
issuable.save
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'creates a system note for milestone set' do
|
|
|
|
expect { subject }.to change { issuable.notes.count }.from(0).to(1)
|
|
|
|
expect(issuable.notes.last.note).to match('changed milestone')
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not create a milestone change event' do
|
|
|
|
expect { subject }.not_to change { ResourceMilestoneEvent.count }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when milestone change event tracking is enabled' do
|
|
|
|
let_it_be(:milestone) { create(:milestone, project: project) }
|
|
|
|
let_it_be(:issuable) { create(:issue, project: project, milestone: milestone) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
stub_feature_flags(track_resource_milestone_change_events: true)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not create a system note for milestone set' do
|
|
|
|
expect { subject }.not_to change { issuable.notes.count }
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'creates a milestone change event' do
|
|
|
|
expect { subject }.to change { ResourceMilestoneEvent.count }.from(0).to(1)
|
|
|
|
end
|
2019-02-15 15:39:39 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it 'creates a system note for due_date set' do
|
|
|
|
issuable.due_date = Date.today
|
|
|
|
issuable.save
|
|
|
|
|
|
|
|
expect { subject }.to change { issuable.notes.count }.from(0).to(1)
|
|
|
|
expect(issuable.notes.last.note).to match('changed due date')
|
|
|
|
end
|
|
|
|
end
|
2018-03-17 18:26:18 +05:30
|
|
|
end
|