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
path: root/spec/lib
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2019-12-11 18:07:38 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2019-12-11 18:07:38 +0300
commit4eea104c69e59f6fa53c7bc15b986c69f29b60c8 (patch)
tree2eff1ce7ac4a58de15b1f5980acfdb22c7b92ac0 /spec/lib
parentb86f474bf51e20d2db4cf0895d0a8e0894e31c08 (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/lib')
-rw-r--r--spec/lib/gitlab/ci/build/prerequisite/kubernetes_namespace_spec.rb41
-rw-r--r--spec/lib/gitlab/diff/highlight_cache_spec.rb9
-rw-r--r--spec/lib/gitlab/diff/line_spec.rb44
-rw-r--r--spec/lib/gitlab/discussions_diff/highlight_cache_spec.rb9
4 files changed, 96 insertions, 7 deletions
diff --git a/spec/lib/gitlab/ci/build/prerequisite/kubernetes_namespace_spec.rb b/spec/lib/gitlab/ci/build/prerequisite/kubernetes_namespace_spec.rb
index 74fa2be5930..2493855f851 100644
--- a/spec/lib/gitlab/ci/build/prerequisite/kubernetes_namespace_spec.rb
+++ b/spec/lib/gitlab/ci/build/prerequisite/kubernetes_namespace_spec.rb
@@ -128,6 +128,47 @@ describe Gitlab::Ci::Build::Prerequisite::KubernetesNamespace do
subject
end
+
+ context 'the build has a namespace configured via CI template' do
+ let(:kubernetes_namespace) { double(namespace: existing_namespace) }
+
+ before do
+ allow(build).to receive(:expanded_kubernetes_namespace)
+ .and_return(requested_namespace)
+ end
+
+ context 'the requested namespace matches the default' do
+ let(:requested_namespace) { 'production' }
+ let(:existing_namespace) { requested_namespace }
+
+ it 'creates a namespace' do
+ expect(Clusters::BuildKubernetesNamespaceService)
+ .to receive(:new)
+ .with(cluster, environment: deployment.environment)
+ .and_return(namespace_builder)
+
+ expect(Clusters::Kubernetes::CreateOrUpdateNamespaceService)
+ .to receive(:new)
+ .with(cluster: cluster, kubernetes_namespace: kubernetes_namespace)
+ .and_return(service)
+
+ expect(service).to receive(:execute).once
+
+ subject
+ end
+ end
+
+ context 'the requested namespace differs from the default' do
+ let(:requested_namespace) { 'production' }
+ let(:existing_namespace) { 'other-namespace' }
+
+ it 'does not create a namespace' do
+ expect(Clusters::Kubernetes::CreateOrUpdateNamespaceService).not_to receive(:new)
+
+ subject
+ end
+ end
+ end
end
context 'kubernetes namespace exists (but has no service_account_token)' do
diff --git a/spec/lib/gitlab/diff/highlight_cache_spec.rb b/spec/lib/gitlab/diff/highlight_cache_spec.rb
index 6dabfd0ef2c..7daf086843b 100644
--- a/spec/lib/gitlab/diff/highlight_cache_spec.rb
+++ b/spec/lib/gitlab/diff/highlight_cache_spec.rb
@@ -68,6 +68,15 @@ describe Gitlab::Diff::HighlightCache, :clean_gitlab_redis_cache do
expect(diff_file.highlighted_diff_lines.size).to be > 5
end
+
+ it 'assigns highlighted diff lines which rich_text are HTML-safe' do
+ cache.write_if_empty
+ cache.decorate(diff_file)
+
+ rich_texts = diff_file.highlighted_diff_lines.map(&:rich_text)
+
+ expect(rich_texts).to all(be_html_safe)
+ end
end
describe '#write_if_empty' do
diff --git a/spec/lib/gitlab/diff/line_spec.rb b/spec/lib/gitlab/diff/line_spec.rb
index 29b9951ba4c..7961bec9d57 100644
--- a/spec/lib/gitlab/diff/line_spec.rb
+++ b/spec/lib/gitlab/diff/line_spec.rb
@@ -1,18 +1,48 @@
# frozen_string_literal: true
+require 'spec_helper'
+
describe Gitlab::Diff::Line do
- describe '.init_from_hash' do
+ shared_examples 'line object initialized by hash' do
it 'round-trips correctly with to_hash' do
- line = described_class.new('<input>', 'match', 0, 0, 1,
- parent_file: double(:file),
- line_code: double(:line_code),
- rich_text: '&lt;input&gt;')
-
- expect(described_class.init_from_hash(line.to_hash).to_hash)
+ expect(described_class.safe_init_from_hash(line.to_hash).to_hash)
.to eq(line.to_hash)
end
end
+ let(:line) do
+ described_class.new('<input>', 'match', 0, 0, 1,
+ parent_file: double(:file),
+ line_code: double(:line_code),
+ rich_text: rich_text)
+ end
+
+ describe '.init_from_hash' do
+ let(:rich_text) { '&lt;input&gt;' }
+
+ it_behaves_like 'line object initialized by hash'
+ end
+
+ describe '.safe_init_from_hash' do
+ let(:rich_text) { '<input>' }
+
+ it_behaves_like 'line object initialized by hash'
+
+ it 'ensures rich_text is HTML-safe' do
+ expect(line.rich_text).not_to be_html_safe
+
+ new_line = described_class.safe_init_from_hash(line.to_hash)
+
+ expect(new_line.rich_text).to be_html_safe
+ end
+
+ context 'when given hash has no rich_text' do
+ it_behaves_like 'line object initialized by hash' do
+ let(:rich_text) { nil }
+ end
+ end
+ end
+
context "when setting rich text" do
it 'escapes any HTML special characters in the diff chunk header' do
subject = described_class.new("<input>", "", 0, 0, 0)
diff --git a/spec/lib/gitlab/discussions_diff/highlight_cache_spec.rb b/spec/lib/gitlab/discussions_diff/highlight_cache_spec.rb
index 15ee8c40b55..97d3a49ea90 100644
--- a/spec/lib/gitlab/discussions_diff/highlight_cache_spec.rb
+++ b/spec/lib/gitlab/discussions_diff/highlight_cache_spec.rb
@@ -62,6 +62,15 @@ describe Gitlab::DiscussionsDiff::HighlightCache, :clean_gitlab_redis_cache do
expect(found.second.size).to eq(2)
expect(found.second).to all(be_a(Gitlab::Diff::Line))
end
+
+ it 'returns lines which rich_text are HTML-safe' do
+ described_class.write_multiple(mapping)
+
+ found = described_class.read_multiple(mapping.keys)
+ rich_texts = found.flatten.map(&:rich_text)
+
+ expect(rich_texts).to all(be_html_safe)
+ end
end
describe '#clear_multiple' do