diff options
author | Heinrich Lee Yu <heinrich@gitlab.com> | 2018-12-17 07:35:59 +0300 |
---|---|---|
committer | Heinrich Lee Yu <heinrich@gitlab.com> | 2018-12-18 03:36:56 +0300 |
commit | 9d1090d49b3077a4a785d2f624e60686d0a863e3 (patch) | |
tree | 03c48ab832392694cc19be337e591fae718d8bd1 /spec/services/issuable | |
parent | 8b4602041cf2c4a8738a4796d78720017249249f (diff) |
Run CommonSystemNotesService on issuable create
Adds system notes for labels, milestone and due date on create
Diffstat (limited to 'spec/services/issuable')
-rw-r--r-- | spec/services/issuable/common_system_notes_service_spec.rb | 47 |
1 files changed, 45 insertions, 2 deletions
diff --git a/spec/services/issuable/common_system_notes_service_spec.rb b/spec/services/issuable/common_system_notes_service_spec.rb index fa1a421d528..fa5d5ebac5c 100644 --- a/spec/services/issuable/common_system_notes_service_spec.rb +++ b/spec/services/issuable/common_system_notes_service_spec.rb @@ -5,7 +5,7 @@ describe Issuable::CommonSystemNotesService do let(:project) { create(:project) } let(:issuable) { create(:issue) } - describe '#execute' do + 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' it_behaves_like 'system note creation', { discussion_locked: true }, 'locked this issue' @@ -20,7 +20,7 @@ describe Issuable::CommonSystemNotesService do end it 'creates a resource label event' do - described_class.new(project, user).execute(issuable, []) + described_class.new(project, user).execute(issuable, old_labels: []) event = issuable.reload.resource_label_events.last expect(event).not_to be_nil @@ -68,4 +68,47 @@ describe Issuable::CommonSystemNotesService do end end end + + context 'on issuable create' do + let(:issuable) { build(:issue) } + + 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 + + it 'creates a system note for milestone set' do + issuable.milestone = create(:milestone, project: project) + issuable.save + + expect { subject }.to change { issuable.notes.count }.from(0).to(1) + expect(issuable.notes.last.note).to match('changed milestone') + 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 end |