Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2019-10-03 15:06:00 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2019-10-03 15:06:00 +0300
commit927cfbfe63dd3dc64df9d341d7c4328a2fe3597f (patch)
treecaa1dc128491ed9dbfdcd40737db429f4b066707 /spec/services/system_notes
parent2b67531b0fd7c94cb1d8618166c4193f40ea5a1f (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/services/system_notes')
-rw-r--r--spec/services/system_notes/base_service_spec.rb44
-rw-r--r--spec/services/system_notes/commit_service_spec.rb117
2 files changed, 161 insertions, 0 deletions
diff --git a/spec/services/system_notes/base_service_spec.rb b/spec/services/system_notes/base_service_spec.rb
new file mode 100644
index 00000000000..96788b05829
--- /dev/null
+++ b/spec/services/system_notes/base_service_spec.rb
@@ -0,0 +1,44 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+describe SystemNotes::BaseService do
+ let(:noteable) { double }
+ let(:project) { double }
+ let(:author) { double }
+
+ let(:base_service) { described_class.new(noteable: noteable, project: project, author: author) }
+
+ describe '#noteable' do
+ subject { base_service.noteable }
+
+ it { is_expected.to eq(noteable) }
+
+ it 'returns nil if no arguments are given' do
+ instance = described_class.new
+ expect(instance.noteable).to be_nil
+ end
+ end
+
+ describe '#project' do
+ subject { base_service.project }
+
+ it { is_expected.to eq(project) }
+
+ it 'returns nil if no arguments are given' do
+ instance = described_class.new
+ expect(instance.project).to be_nil
+ end
+ end
+
+ describe '#author' do
+ subject { base_service.author }
+
+ it { is_expected.to eq(author) }
+
+ it 'returns nil if no arguments are given' do
+ instance = described_class.new
+ expect(instance.author).to be_nil
+ end
+ end
+end
diff --git a/spec/services/system_notes/commit_service_spec.rb b/spec/services/system_notes/commit_service_spec.rb
new file mode 100644
index 00000000000..4d4403be59a
--- /dev/null
+++ b/spec/services/system_notes/commit_service_spec.rb
@@ -0,0 +1,117 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+describe SystemNotes::CommitService do
+ set(:group) { create(:group) }
+ set(:project) { create(:project, :repository, group: group) }
+ set(:author) { create(:user) }
+
+ let(:commit_service) { described_class.new(noteable: noteable, project: project, author: author) }
+
+ describe '#add_commits' do
+ subject { commit_service.add_commits(new_commits, old_commits, oldrev) }
+
+ let(:noteable) { create(:merge_request, source_project: project, target_project: project) }
+ let(:new_commits) { noteable.commits }
+ let(:old_commits) { [] }
+ let(:oldrev) { nil }
+
+ 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?) }
+
+ describe 'comparison diff link line' do
+ it 'adds the comparison text' do
+ expect(note_lines[2]).to match "[Compare with previous version]"
+ end
+ end
+
+ context 'without existing commits' do
+ it 'adds a message header' do
+ expect(note_lines[0]).to eq "added #{new_commits.size} commits"
+ end
+
+ it 'adds a message for each commit' do
+ decoded_note_content = HTMLEntities.new.decode(subject.note)
+
+ new_commits.each do |commit|
+ expect(decoded_note_content).to include("<li>#{commit.short_id} - #{commit.title}</li>")
+ end
+ end
+ end
+
+ describe 'summary line for existing commits' do
+ let(:summary_line) { note_lines[1] }
+
+ context 'with one existing commit' do
+ let(:old_commits) { [noteable.commits.last] }
+
+ it 'includes the existing commit' do
+ expect(summary_line).to start_with("<ul><li>#{old_commits.first.short_id} - 1 commit from branch <code>feature</code>")
+ end
+ end
+
+ context 'with multiple existing commits' do
+ let(:old_commits) { noteable.commits[3..-1] }
+
+ context 'with oldrev' do
+ let(:oldrev) { noteable.commits[2].id }
+
+ it 'includes a commit range and count' do
+ expect(summary_line)
+ .to start_with("<ul><li>#{Commit.truncate_sha(oldrev)}...#{old_commits.last.short_id} - 26 commits from branch <code>feature</code>")
+ end
+ end
+
+ context 'without oldrev' do
+ it 'includes a commit range and count' do
+ expect(summary_line)
+ .to start_with("<ul><li>#{old_commits[0].short_id}..#{old_commits[-1].short_id} - 26 commits from branch <code>feature</code>")
+ end
+ end
+
+ context 'on a fork' do
+ before do
+ expect(noteable).to receive(:for_fork?).and_return(true)
+ end
+
+ it 'includes the project namespace' do
+ expect(summary_line).to include("<code>#{noteable.target_project_namespace}:feature</code>")
+ end
+ end
+ end
+ end
+ end
+ end
+
+ describe '#tag_commit' do
+ let(:noteable) { project.commit }
+ let(:tag_name) { 'v1.2.3' }
+
+ subject { commit_service.tag_commit(tag_name) }
+
+ it_behaves_like 'a system note' do
+ let(:action) { 'tag' }
+ end
+
+ it 'sets the note text' do
+ link = "/#{project.full_path}/-/tags/#{tag_name}"
+
+ expect(subject.note).to eq "tagged commit #{noteable.sha} to [`#{tag_name}`](#{link})"
+ end
+ end
+
+ describe '#new_commit_summary' do
+ it 'escapes HTML titles' do
+ commit = double(title: '<pre>This is a test</pre>', short_id: '12345678')
+ escaped = '&lt;pre&gt;This is a test&lt;/pre&gt;'
+
+ expect(described_class.new.new_commit_summary([commit])).to all(match(/- #{escaped}/))
+ end
+ end
+end