summaryrefslogtreecommitdiff
path: root/spec/services/system_note_service_spec.rb
diff options
context:
space:
mode:
authorPawel Chojnacki <pawel@chojnacki.ws>2017-04-03 20:50:23 +0200
committerPawel Chojnacki <pawel@chojnacki.ws>2017-04-03 20:50:23 +0200
commit034780644df565228d8f44d4b9eca10d01ae1de4 (patch)
treedf9d4f44cc588ec0cc228212f9fd515dcdf68533 /spec/services/system_note_service_spec.rb
parent2651f0b2bf19eb611942651ef3170081c144c1f7 (diff)
parent97c49b8426c62b5b398ed9a2bf863d859a4b7e55 (diff)
downloadgitlab-ce-034780644df565228d8f44d4b9eca10d01ae1de4.tar.gz
Merge remote-tracking branch 'upstream/master' into 26944-add_per_deployment_metrics26944-add_per_deployment_metrics
Diffstat (limited to 'spec/services/system_note_service_spec.rb')
-rw-r--r--spec/services/system_note_service_spec.rb169
1 files changed, 144 insertions, 25 deletions
diff --git a/spec/services/system_note_service_spec.rb b/spec/services/system_note_service_spec.rb
index d7bf4c39cc0..90cde705b85 100644
--- a/spec/services/system_note_service_spec.rb
+++ b/spec/services/system_note_service_spec.rb
@@ -8,12 +8,15 @@ describe SystemNoteService, services: true do
let(:noteable) { create(:issue, project: project) }
shared_examples_for 'a system note' do
+ let(:expected_noteable) { noteable }
+ let(:commit_count) { nil }
+
it 'is valid' do
expect(subject).to be_valid
end
it 'sets the noteable model' do
- expect(subject.noteable).to eq noteable
+ expect(subject.noteable).to eq expected_noteable
end
it 'sets the project' do
@@ -27,6 +30,19 @@ describe SystemNoteService, services: true do
it 'is a system note' do
expect(subject).to be_system
end
+
+ context 'metadata' do
+ it 'creates a new system note metadata record' do
+ expect { subject }.to change{ SystemNoteMetadata.count }.from(0).to(1)
+ end
+
+ it 'creates a record correctly' do
+ metadata = subject.system_note_metadata
+
+ expect(metadata.commit_count).to eq(commit_count)
+ expect(metadata.action).to eq(action)
+ end
+ end
end
describe '.add_commits' do
@@ -38,7 +54,10 @@ describe SystemNoteService, services: true do
let(:old_commits) { [] }
let(:oldrev) { nil }
- it_behaves_like 'a system note'
+ it_behaves_like 'a system note' do
+ let(:commit_count) { new_commits.size }
+ let(:action) { 'commit' }
+ end
describe 'note body' do
let(:note_lines) { subject.note.split("\n").reject(&:blank?) }
@@ -117,7 +136,9 @@ describe SystemNoteService, services: true do
let(:assignee) { create(:user) }
- it_behaves_like 'a system note'
+ it_behaves_like 'a system note' do
+ let(:action) { 'assignee' }
+ end
context 'when assignee added' do
it 'sets the note text' do
@@ -141,7 +162,9 @@ describe SystemNoteService, services: true do
let(:added) { [] }
let(:removed) { [] }
- it_behaves_like 'a system note'
+ it_behaves_like 'a system note' do
+ let(:action) { 'label' }
+ end
context 'with added labels' do
let(:added) { labels }
@@ -176,7 +199,9 @@ describe SystemNoteService, services: true do
let(:milestone) { create(:milestone, project: project) }
- it_behaves_like 'a system note'
+ it_behaves_like 'a system note' do
+ let(:action) { 'milestone' }
+ end
context 'when milestone added' do
it 'sets the note text' do
@@ -199,7 +224,9 @@ describe SystemNoteService, services: true do
let(:status) { 'new_status' }
let(:source) { nil }
- it_behaves_like 'a system note'
+ it_behaves_like 'a system note' do
+ let(:action) { 'status' }
+ end
context 'with a source' do
let(:source) { double('commit', gfm_reference: 'commit 123456') }
@@ -225,7 +252,9 @@ describe SystemNoteService, services: true do
subject { described_class.merge_when_pipeline_succeeds(noteable, project, author, noteable.diff_head_commit) }
- it_behaves_like 'a system note'
+ it_behaves_like 'a system note' do
+ let(:action) { 'merge' }
+ end
it "posts the 'merge when pipeline succeeds' system note" do
expect(subject.note).to match(/enabled an automatic merge when the pipeline for (\w+\/\w+@)?\h{40} succeeds/)
@@ -240,7 +269,9 @@ describe SystemNoteService, services: true do
subject { described_class.cancel_merge_when_pipeline_succeeds(noteable, project, author) }
- it_behaves_like 'a system note'
+ it_behaves_like 'a system note' do
+ let(:action) { 'merge' }
+ end
it "posts the 'merge when pipeline succeeds' system note" do
expect(subject.note).to eq "canceled the automatic merge"
@@ -253,7 +284,9 @@ describe SystemNoteService, services: true do
subject { described_class.change_title(noteable, project, author, 'Old title') }
context 'when noteable responds to `title`' do
- it_behaves_like 'a system note'
+ it_behaves_like 'a system note' do
+ let(:action) { 'title' }
+ end
it 'sets the note text' do
expect(subject.note).
@@ -266,7 +299,9 @@ describe SystemNoteService, services: true do
subject { described_class.change_issue_confidentiality(noteable, project, author) }
context 'when noteable responds to `confidential`' do
- it_behaves_like 'a system note'
+ it_behaves_like 'a system note' do
+ let(:action) { 'confidentiality' }
+ end
it 'sets the note text' do
expect(subject.note).to eq 'made the issue visible to everyone'
@@ -281,7 +316,9 @@ describe SystemNoteService, services: true do
let(:old_branch) { 'old_branch'}
let(:new_branch) { 'new_branch'}
- it_behaves_like 'a system note'
+ it_behaves_like 'a system note' do
+ let(:action) { 'branch' }
+ end
context 'when target branch name changed' do
it 'sets the note text' do
@@ -295,7 +332,9 @@ describe SystemNoteService, services: true do
let(:project) { create(:project, :repository) }
- it_behaves_like 'a system note'
+ it_behaves_like 'a system note' do
+ let(:action) { 'branch' }
+ end
context 'when source branch deleted' do
it 'sets the note text' do
@@ -309,7 +348,9 @@ describe SystemNoteService, services: true do
let(:project) { create(:project, :repository) }
- it_behaves_like 'a system note'
+ it_behaves_like 'a system note' do
+ let(:action) { 'branch' }
+ end
context 'when a branch is created from the new branch button' do
it 'sets the note text' do
@@ -323,7 +364,9 @@ describe SystemNoteService, services: true do
let(:mentioner) { create(:issue, project: project) }
- it_behaves_like 'a system note'
+ it_behaves_like 'a system note' do
+ let(:action) { 'cross_reference' }
+ end
context 'when cross-reference disallowed' do
before do
@@ -333,6 +376,10 @@ describe SystemNoteService, services: true do
it 'returns nil' do
expect(subject).to be_nil
end
+
+ it 'does not create a system note metadata record' do
+ expect { subject }.not_to change{ SystemNoteMetadata.count }
+ end
end
context 'when cross-reference allowed' do
@@ -340,6 +387,10 @@ describe SystemNoteService, services: true do
expect(described_class).to receive(:cross_reference_disallowed?).and_return(false)
end
+ it_behaves_like 'a system note' do
+ let(:action) { 'cross_reference' }
+ end
+
describe 'note_body' do
context 'cross-project' do
let(:project2) { create(:project, :repository) }
@@ -552,6 +603,9 @@ describe SystemNoteService, services: true do
let(:direction) { :to }
it_behaves_like 'cross project mentionable'
+ it_behaves_like 'a system note' do
+ let(:action) { 'moved' }
+ end
it 'notifies about noteable being moved to' do
expect(subject.note).to match('moved to')
@@ -562,6 +616,9 @@ describe SystemNoteService, services: true do
let(:direction) { :from }
it_behaves_like 'cross project mentionable'
+ it_behaves_like 'a system note' do
+ let(:action) { 'moved' }
+ end
it 'notifies about noteable being moved from' do
expect(subject.note).to match('moved from')
@@ -732,33 +789,34 @@ describe SystemNoteService, services: true do
let(:merge_request) { discussion.noteable }
let(:project) { merge_request.source_project }
let(:issue) { create(:issue, project: project) }
- let(:user) { create(:user) }
def reloaded_merge_request
MergeRequest.find(merge_request.id)
end
- before do
- project.team << [user, :developer]
+ subject { described_class.discussion_continued_in_issue(discussion, project, author, issue) }
+
+ it_behaves_like 'a system note' do
+ let(:expected_noteable) { discussion.first_note.noteable }
+ let(:action) { 'discussion' }
end
it 'creates a new note in the discussion' do
# we need to completely rebuild the merge request object, or the `@discussions` on the merge request are not reloaded.
- expect { SystemNoteService.discussion_continued_in_issue(discussion, project, user, issue) }.
- to change { reloaded_merge_request.discussions.first.notes.size }.by(1)
+ expect { subject }.to change { reloaded_merge_request.discussions.first.notes.size }.by(1)
end
it 'mentions the created issue in the system note' do
- note = SystemNoteService.discussion_continued_in_issue(discussion, project, user, issue)
-
- expect(note.note).to include(issue.to_reference)
+ expect(subject.note).to include(issue.to_reference)
end
end
describe '.change_time_estimate' do
subject { described_class.change_time_estimate(noteable, project, author) }
- it_behaves_like 'a system note'
+ it_behaves_like 'a system note' do
+ let(:action) { 'time_tracking' }
+ end
context 'with a time estimate' do
it 'sets the note text' do
@@ -788,7 +846,9 @@ describe SystemNoteService, services: true do
described_class.change_time_spent(noteable, project, author)
end
- it_behaves_like 'a system note'
+ it_behaves_like 'a system note' do
+ let(:action) { 'time_tracking' }
+ end
context 'when time was added' do
it 'sets the note text' do
@@ -820,6 +880,34 @@ describe SystemNoteService, services: true do
end
end
+ describe '.remove_merge_request_wip' do
+ let(:noteable) { create(:issue, project: project, title: 'WIP: Lorem ipsum') }
+
+ subject { described_class.remove_merge_request_wip(noteable, project, author) }
+
+ it_behaves_like 'a system note' do
+ let(:action) { 'title' }
+ end
+
+ it 'sets the note text' do
+ expect(subject.note).to eq 'unmarked as a **Work In Progress**'
+ end
+ end
+
+ describe '.add_merge_request_wip' do
+ let(:noteable) { create(:issue, project: project, title: 'Lorem ipsum') }
+
+ subject { described_class.add_merge_request_wip(noteable, project, author) }
+
+ it_behaves_like 'a system note' do
+ let(:action) { 'title' }
+ end
+
+ it 'sets the note text' do
+ expect(subject.note).to eq 'marked as a **Work In Progress**'
+ end
+ end
+
describe '.add_merge_request_wip_from_commit' do
let(:project) { create(:project, :repository) }
let(:noteable) do
@@ -835,7 +923,9 @@ describe SystemNoteService, services: true do
)
end
- it_behaves_like 'a system note'
+ it_behaves_like 'a system note' do
+ let(:action) { 'title' }
+ end
it "posts the 'marked as a Work In Progress from commit' system note" do
expect(subject.note).to match(
@@ -843,4 +933,33 @@ describe SystemNoteService, services: true do
)
end
end
+
+ describe '.change_task_status' do
+ let(:noteable) { create(:issue, project: project) }
+ let(:task) { double(:task, complete?: true, source: 'task') }
+
+ subject { described_class.change_task_status(noteable, project, author, task) }
+
+ it_behaves_like 'a system note' do
+ let(:action) { 'task' }
+ end
+
+ it "posts the 'marked as a Work In Progress from commit' system note" do
+ expect(subject.note).to eq("marked the task **task** as completed")
+ end
+ end
+
+ describe '.resolve_all_discussions' do
+ let(:noteable) { create(:merge_request, source_project: project, target_project: project) }
+
+ subject { described_class.resolve_all_discussions(noteable, project, author) }
+
+ it_behaves_like 'a system note' do
+ let(:action) { 'discussion' }
+ end
+
+ it 'sets the note text' do
+ expect(subject.note).to eq 'resolved all discussions'
+ end
+ end
end