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>2020-07-20 15:26:25 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2020-07-20 15:26:25 +0300
commita09983ae35713f5a2bbb100981116d31ce99826e (patch)
tree2ee2af7bd104d57086db360a7e6d8c9d5d43667a /spec/lib/gitlab/utils
parent18c5ab32b738c0b6ecb4d0df3994000482f34bd8 (diff)
Add latest changes from gitlab-org/gitlab@13-2-stable-ee
Diffstat (limited to 'spec/lib/gitlab/utils')
-rw-r--r--spec/lib/gitlab/utils/deep_size_spec.rb2
-rw-r--r--spec/lib/gitlab/utils/inline_hash_spec.rb2
-rw-r--r--spec/lib/gitlab/utils/json_size_estimator_spec.rb2
-rw-r--r--spec/lib/gitlab/utils/lazy_attributes_spec.rb2
-rw-r--r--spec/lib/gitlab/utils/log_limited_array_spec.rb2
-rw-r--r--spec/lib/gitlab/utils/markdown_spec.rb63
-rw-r--r--spec/lib/gitlab/utils/measuring_spec.rb2
-rw-r--r--spec/lib/gitlab/utils/merge_hash_spec.rb2
-rw-r--r--spec/lib/gitlab/utils/override_spec.rb2
-rw-r--r--spec/lib/gitlab/utils/safe_inline_hash_spec.rb2
-rw-r--r--spec/lib/gitlab/utils/sanitize_node_link_spec.rb2
-rw-r--r--spec/lib/gitlab/utils/strong_memoize_spec.rb2
-rw-r--r--spec/lib/gitlab/utils/usage_data_spec.rb22
13 files changed, 94 insertions, 13 deletions
diff --git a/spec/lib/gitlab/utils/deep_size_spec.rb b/spec/lib/gitlab/utils/deep_size_spec.rb
index 5a155fb6c80..7595fb2c1b0 100644
--- a/spec/lib/gitlab/utils/deep_size_spec.rb
+++ b/spec/lib/gitlab/utils/deep_size_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe Gitlab::Utils::DeepSize do
+RSpec.describe Gitlab::Utils::DeepSize do
let(:data) do
{
a: [1, 2, 3],
diff --git a/spec/lib/gitlab/utils/inline_hash_spec.rb b/spec/lib/gitlab/utils/inline_hash_spec.rb
index 867db0b92a5..d1354a7ae0a 100644
--- a/spec/lib/gitlab/utils/inline_hash_spec.rb
+++ b/spec/lib/gitlab/utils/inline_hash_spec.rb
@@ -2,7 +2,7 @@
require 'fast_spec_helper'
-describe Gitlab::Utils::InlineHash do
+RSpec.describe Gitlab::Utils::InlineHash do
describe '.merge_keys' do
subject { described_class.merge_keys(source) }
diff --git a/spec/lib/gitlab/utils/json_size_estimator_spec.rb b/spec/lib/gitlab/utils/json_size_estimator_spec.rb
index ae24e25558a..5fd66caa5e9 100644
--- a/spec/lib/gitlab/utils/json_size_estimator_spec.rb
+++ b/spec/lib/gitlab/utils/json_size_estimator_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe Gitlab::Utils::JsonSizeEstimator do
+RSpec.describe Gitlab::Utils::JsonSizeEstimator do
RSpec::Matchers.define :match_json_bytesize_of do |expected|
match do |actual|
actual == expected.to_json.bytesize
diff --git a/spec/lib/gitlab/utils/lazy_attributes_spec.rb b/spec/lib/gitlab/utils/lazy_attributes_spec.rb
index c0005c194c4..dfffe70defb 100644
--- a/spec/lib/gitlab/utils/lazy_attributes_spec.rb
+++ b/spec/lib/gitlab/utils/lazy_attributes_spec.rb
@@ -2,7 +2,7 @@
require 'fast_spec_helper'
require 'active_support/concern'
-describe Gitlab::Utils::LazyAttributes do
+RSpec.describe Gitlab::Utils::LazyAttributes do
subject(:klass) do
Class.new do
include Gitlab::Utils::LazyAttributes
diff --git a/spec/lib/gitlab/utils/log_limited_array_spec.rb b/spec/lib/gitlab/utils/log_limited_array_spec.rb
index a236ab37614..a55a176be48 100644
--- a/spec/lib/gitlab/utils/log_limited_array_spec.rb
+++ b/spec/lib/gitlab/utils/log_limited_array_spec.rb
@@ -2,7 +2,7 @@
require 'fast_spec_helper'
-describe Gitlab::Utils::LogLimitedArray do
+RSpec.describe Gitlab::Utils::LogLimitedArray do
describe '.log_limited_array' do
context 'when the argument is not an array' do
it 'returns an empty array' do
diff --git a/spec/lib/gitlab/utils/markdown_spec.rb b/spec/lib/gitlab/utils/markdown_spec.rb
new file mode 100644
index 00000000000..001ff5bc487
--- /dev/null
+++ b/spec/lib/gitlab/utils/markdown_spec.rb
@@ -0,0 +1,63 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe Gitlab::Utils::Markdown do
+ let(:klass) do
+ Class.new do
+ include Gitlab::Utils::Markdown
+ end
+ end
+
+ subject(:object) { klass.new }
+
+ describe '#string_to_anchor' do
+ subject { object.string_to_anchor(string) }
+
+ let(:string) { 'My Header' }
+
+ it 'converts string to anchor' do
+ is_expected.to eq 'my-header'
+ end
+
+ context 'when string has punctuation' do
+ let(:string) { 'My, Header!' }
+
+ it 'removes punctuation' do
+ is_expected.to eq 'my-header'
+ end
+ end
+
+ context 'when string starts and ends with spaces' do
+ let(:string) { ' My Header ' }
+
+ it 'removes extra spaces' do
+ is_expected.to eq 'my-header'
+ end
+ end
+
+ context 'when string has multiple spaces and dashes in the middle' do
+ let(:string) { 'My - - - Header' }
+
+ it 'removes consecutive dashes' do
+ is_expected.to eq 'my-header'
+ end
+ end
+
+ context 'when string contains only digits' do
+ let(:string) { '123' }
+
+ it 'adds anchor prefix' do
+ is_expected.to eq 'anchor-123'
+ end
+ end
+
+ context 'when string is empty' do
+ let(:string) { '' }
+
+ it 'returns an empty string' do
+ is_expected.to eq ''
+ end
+ end
+ end
+end
diff --git a/spec/lib/gitlab/utils/measuring_spec.rb b/spec/lib/gitlab/utils/measuring_spec.rb
index 254f53f7da3..4931ebf26f0 100644
--- a/spec/lib/gitlab/utils/measuring_spec.rb
+++ b/spec/lib/gitlab/utils/measuring_spec.rb
@@ -2,7 +2,7 @@
require 'fast_spec_helper'
-describe Gitlab::Utils::Measuring do
+RSpec.describe Gitlab::Utils::Measuring do
describe '#with_measuring' do
let(:base_log_data) { {} }
let(:result) { "result" }
diff --git a/spec/lib/gitlab/utils/merge_hash_spec.rb b/spec/lib/gitlab/utils/merge_hash_spec.rb
index 72620e549a9..11daa05c9ee 100644
--- a/spec/lib/gitlab/utils/merge_hash_spec.rb
+++ b/spec/lib/gitlab/utils/merge_hash_spec.rb
@@ -1,7 +1,7 @@
# frozen_string_literal: true
require 'spec_helper'
-describe Gitlab::Utils::MergeHash do
+RSpec.describe Gitlab::Utils::MergeHash do
describe '.crush' do
it 'can flatten a hash to each element' do
input = { hello: "world", this: { crushes: ["an entire", "hash"] } }
diff --git a/spec/lib/gitlab/utils/override_spec.rb b/spec/lib/gitlab/utils/override_spec.rb
index e2776efac85..7ba7392df0f 100644
--- a/spec/lib/gitlab/utils/override_spec.rb
+++ b/spec/lib/gitlab/utils/override_spec.rb
@@ -2,7 +2,7 @@
require 'fast_spec_helper'
-describe Gitlab::Utils::Override do
+RSpec.describe Gitlab::Utils::Override do
let(:base) do
Struct.new(:good) do
def self.good
diff --git a/spec/lib/gitlab/utils/safe_inline_hash_spec.rb b/spec/lib/gitlab/utils/safe_inline_hash_spec.rb
index 617845332bc..f7c50140cf7 100644
--- a/spec/lib/gitlab/utils/safe_inline_hash_spec.rb
+++ b/spec/lib/gitlab/utils/safe_inline_hash_spec.rb
@@ -2,7 +2,7 @@
require 'fast_spec_helper'
-describe Gitlab::Utils::SafeInlineHash do
+RSpec.describe Gitlab::Utils::SafeInlineHash do
describe '.merge_keys!' do
let(:source) { { 'foo' => { 'bar' => 'baz' } } }
let(:validator) { instance_double(Gitlab::Utils::DeepSize, valid?: valid) }
diff --git a/spec/lib/gitlab/utils/sanitize_node_link_spec.rb b/spec/lib/gitlab/utils/sanitize_node_link_spec.rb
index dd379f2fe1f..514051b1cc0 100644
--- a/spec/lib/gitlab/utils/sanitize_node_link_spec.rb
+++ b/spec/lib/gitlab/utils/sanitize_node_link_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe Gitlab::Utils::SanitizeNodeLink do
+RSpec.describe Gitlab::Utils::SanitizeNodeLink do
let(:klass) do
struct = Struct.new(:value)
struct.include(described_class)
diff --git a/spec/lib/gitlab/utils/strong_memoize_spec.rb b/spec/lib/gitlab/utils/strong_memoize_spec.rb
index 624e799c5e9..d9fa2e516e1 100644
--- a/spec/lib/gitlab/utils/strong_memoize_spec.rb
+++ b/spec/lib/gitlab/utils/strong_memoize_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe Gitlab::Utils::StrongMemoize do
+RSpec.describe Gitlab::Utils::StrongMemoize do
let(:klass) do
struct = Struct.new(:value) do
def method_name
diff --git a/spec/lib/gitlab/utils/usage_data_spec.rb b/spec/lib/gitlab/utils/usage_data_spec.rb
index 7de615384c5..7940c9af6ff 100644
--- a/spec/lib/gitlab/utils/usage_data_spec.rb
+++ b/spec/lib/gitlab/utils/usage_data_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe Gitlab::Utils::UsageData do
+RSpec.describe Gitlab::Utils::UsageData do
describe '#count' do
let(:relation) { double(:relation) }
@@ -88,13 +88,21 @@ describe Gitlab::Utils::UsageData do
end
context 'when Prometheus is disabled' do
- it 'returns nil' do
+ before do
expect(Gitlab::Prometheus::Internal).to receive(:prometheus_enabled?).and_return(false)
+ end
+ it 'returns nil by default' do
result = described_class.with_prometheus_client { |client| client }
expect(result).to be nil
end
+
+ it 'returns fallback if provided' do
+ result = described_class.with_prometheus_client(fallback: []) { |client| client }
+
+ expect(result).to eq([])
+ end
end
end
@@ -108,4 +116,14 @@ describe Gitlab::Utils::UsageData do
expect(duration).to eq(2)
end
end
+
+ describe '#with_finished_at' do
+ it 'adds a timestamp to the hash yielded by the block' do
+ freeze_time do
+ result = described_class.with_finished_at(:current_time) { { a: 1 } }
+
+ expect(result).to eq(a: 1, current_time: Time.now)
+ end
+ end
+ end
end