2019-04-11 08:17:24 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-11-01 13:35:14 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-24 11:08:50 -04:00
|
|
|
RSpec.describe Issuable::CommonSystemNotesService do
|
2020-02-19 13:09:10 -05:00
|
|
|
let_it_be(:project) { create(:project) }
|
|
|
|
let_it_be(:user) { create(:user) }
|
|
|
|
|
2019-01-14 05:46:39 -05:00
|
|
|
let(:issuable) { create(:issue, project: project) }
|
2017-11-01 13:35:14 -04:00
|
|
|
|
2018-12-16 23:35:59 -05:00
|
|
|
context 'on issuable update' do
|
2017-11-01 13:35:14 -04:00
|
|
|
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-09-07 09:39:20 -04:00
|
|
|
let(:label) { create(:label, project: project) }
|
|
|
|
|
2017-11-01 13:35:14 -04:00
|
|
|
before do
|
|
|
|
issuable.labels << label
|
2020-09-21 08:09:34 -04:00
|
|
|
issuable.save!
|
2017-11-01 13:35:14 -04:00
|
|
|
end
|
|
|
|
|
2018-09-07 09:39:20 -04:00
|
|
|
it 'creates a resource label event' do
|
2021-05-11 23:10:21 -04:00
|
|
|
described_class.new(project: project, current_user: user).execute(issuable, old_labels: [])
|
2018-09-07 09:39:20 -04:00
|
|
|
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
|
2017-11-01 13:35:14 -04:00
|
|
|
end
|
|
|
|
|
2020-07-15 20:09:17 -04:00
|
|
|
context 'with merge requests Draft note' do
|
|
|
|
context 'adding Draft note' do
|
2017-11-21 14:25:37 -05:00
|
|
|
let(:issuable) { create(:merge_request, title: "merge request") }
|
|
|
|
|
2020-10-26 11:08:40 -04:00
|
|
|
it_behaves_like 'system note creation', { title: "Draft: merge request" }, 'marked this merge request as **draft**'
|
2017-11-21 14:25:37 -05:00
|
|
|
|
|
|
|
context 'and changing title' do
|
|
|
|
before do
|
2020-07-15 20:09:17 -04:00
|
|
|
issuable.update_attribute(:title, "Draft: changed title")
|
2017-11-21 14:25:37 -05:00
|
|
|
end
|
|
|
|
|
2020-10-26 11:08:40 -04:00
|
|
|
it_behaves_like 'draft notes creation', 'draft'
|
2017-11-21 14:25:37 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-07-15 20:09:17 -04:00
|
|
|
context 'removing Draft note' do
|
|
|
|
let(:issuable) { create(:merge_request, title: "Draft: merge request") }
|
2017-11-21 14:25:37 -05:00
|
|
|
|
2020-10-26 11:08:40 -04:00
|
|
|
it_behaves_like 'system note creation', { title: "merge request" }, 'marked this merge request as **ready**'
|
2017-11-21 14:25:37 -05:00
|
|
|
|
|
|
|
context 'and changing title' do
|
|
|
|
before do
|
|
|
|
issuable.update_attribute(:title, "changed title")
|
|
|
|
end
|
|
|
|
|
2020-10-26 11:08:40 -04:00
|
|
|
it_behaves_like 'draft notes creation', 'ready'
|
2017-11-21 14:25:37 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2017-11-01 13:35:14 -04:00
|
|
|
end
|
2018-12-16 23:35:59 -05:00
|
|
|
|
|
|
|
context 'on issuable create' do
|
2019-01-14 05:46:39 -05:00
|
|
|
let(:issuable) { build(:issue, project: project) }
|
2018-12-16 23:35:59 -05:00
|
|
|
|
2021-05-11 23:10:21 -04:00
|
|
|
subject { described_class.new(project: project, current_user: user).execute(issuable, old_labels: [], is_update: false) }
|
2018-12-16 23:35:59 -05:00
|
|
|
|
|
|
|
it 'does not create system note for title and description' do
|
2020-09-21 08:09:34 -04:00
|
|
|
issuable.save!
|
2018-12-16 23:35:59 -05:00
|
|
|
|
|
|
|
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
|
2020-09-21 08:09:34 -04:00
|
|
|
issuable.save!
|
2018-12-16 23:35:59 -05:00
|
|
|
|
|
|
|
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-09-03 02:08:22 -04:00
|
|
|
context 'when changing milestones' do
|
2020-02-19 13:09:10 -05:00
|
|
|
let_it_be(:milestone) { create(:milestone, project: project) }
|
|
|
|
let_it_be(:issuable) { create(:issue, project: project, milestone: milestone) }
|
|
|
|
|
|
|
|
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
|
2018-12-16 23:35:59 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'creates a system note for due_date set' do
|
|
|
|
issuable.due_date = Date.today
|
2020-09-21 08:09:34 -04:00
|
|
|
issuable.save!
|
2018-12-16 23:35:59 -05:00
|
|
|
|
|
|
|
expect { subject }.to change { issuable.notes.count }.from(0).to(1)
|
|
|
|
expect(issuable.notes.last.note).to match('changed due date')
|
|
|
|
end
|
|
|
|
end
|
2017-11-01 13:35:14 -04:00
|
|
|
end
|