From b39512ed755239198a9c294b6a45e65c05900235 Mon Sep 17 00:00:00 2001 From: GitLab Bot Date: Thu, 18 Aug 2022 08:17:02 +0000 Subject: Add latest changes from gitlab-org/gitlab@15-3-stable-ee --- .../issuable/common_system_notes_service_spec.rb | 45 +++++++++++++++++++--- 1 file changed, 39 insertions(+), 6 deletions(-) (limited to 'spec/services/issuable') diff --git a/spec/services/issuable/common_system_notes_service_spec.rb b/spec/services/issuable/common_system_notes_service_spec.rb index 1426ef2a1f6..0d2b8a4ac3c 100644 --- a/spec/services/issuable/common_system_notes_service_spec.rb +++ b/spec/services/issuable/common_system_notes_service_spec.rb @@ -8,6 +8,37 @@ RSpec.describe Issuable::CommonSystemNotesService do let(:issuable) { create(:issue, project: project) } + shared_examples 'system note for issuable date changes' do + it 'creates a system note for due_date set' do + issuable.update!(due_date: Date.today) + + expect { subject }.to change(issuable.notes, :count).from(0).to(1) + expect(issuable.notes.last.note).to match('changed due date to') + end + + it 'creates a system note for start_date set' do + issuable.update!(start_date: Date.today) + + expect { subject }.to change(issuable.notes, :count).from(0).to(1) + expect(issuable.notes.last.note).to match('changed start date to') + end + + it 'creates a note when both start and due date are changed' do + issuable.update!(start_date: Date.today, due_date: 1.week.from_now) + + expect { subject }.to change { issuable.notes.count }.from(0).to(1) + expect(issuable.notes.last.note).to match(/changed start date to.+and changed due date to/) + end + + it 'does not call SystemNoteService if no dates are changed' do + issuable.update!(title: 'new title') + + expect(SystemNoteService).not_to receive(:change_start_date_or_due_date) + + subject + end + end + context 'on issuable update' do it_behaves_like 'system note creation', { title: 'New title' }, 'changed title' it_behaves_like 'system note creation', { description: 'New description' }, 'changed the description' @@ -61,6 +92,12 @@ RSpec.describe Issuable::CommonSystemNotesService do end end end + + context 'when changing dates' do + it_behaves_like 'system note for issuable date changes' do + subject { described_class.new(project: project, current_user: user).execute(issuable) } + end + end end context 'on issuable create' do @@ -102,12 +139,8 @@ RSpec.describe Issuable::CommonSystemNotesService do end 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') + context 'when changing dates' do + it_behaves_like 'system note for issuable date changes' end end end -- cgit v1.2.3