diff options
Diffstat (limited to 'spec/lib/gitlab/utils')
-rw-r--r-- | spec/lib/gitlab/utils/markdown_spec.rb | 44 | ||||
-rw-r--r-- | spec/lib/gitlab/utils/override_spec.rb | 67 | ||||
-rw-r--r-- | spec/lib/gitlab/utils/usage_data_spec.rb | 10 |
3 files changed, 94 insertions, 27 deletions
diff --git a/spec/lib/gitlab/utils/markdown_spec.rb b/spec/lib/gitlab/utils/markdown_spec.rb index 93d91f7ed90..acc5bd47c8c 100644 --- a/spec/lib/gitlab/utils/markdown_spec.rb +++ b/spec/lib/gitlab/utils/markdown_spec.rb @@ -53,33 +53,23 @@ RSpec.describe Gitlab::Utils::Markdown do end context 'when string has a product suffix' do - let(:string) { 'My Header (ULTIMATE)' } - - it 'ignores a product suffix' do - is_expected.to eq 'my-header' - end - - context 'with only modifier' do - let(:string) { 'My Header (STARTER ONLY)' } - - it 'ignores a product suffix' do - is_expected.to eq 'my-header' - end - end - - context 'with "*" around a product suffix' do - let(:string) { 'My Header **(STARTER)**' } - - it 'ignores a product suffix' do - is_expected.to eq 'my-header' - end - end - - context 'with "*" around a product suffix and only modifier' do - let(:string) { 'My Header **(STARTER ONLY)**' } - - it 'ignores a product suffix' do - is_expected.to eq 'my-header' + %w[CORE STARTER PREMIUM ULTIMATE FREE BRONZE SILVER GOLD].each do |tier| + ['', ' ONLY', ' SELF', ' SASS'].each do |modifier| + context "#{tier}#{modifier}" do + let(:string) { "My Header (#{tier}#{modifier})" } + + it 'ignores a product suffix' do + is_expected.to eq 'my-header' + end + + context 'with "*" around a product suffix' do + let(:string) { "My Header **(#{tier}#{modifier})**" } + + it 'ignores a product suffix' do + is_expected.to eq 'my-header' + end + end + end end end end diff --git a/spec/lib/gitlab/utils/override_spec.rb b/spec/lib/gitlab/utils/override_spec.rb index 7ba7392df0f..a5e53c1dfc1 100644 --- a/spec/lib/gitlab/utils/override_spec.rb +++ b/spec/lib/gitlab/utils/override_spec.rb @@ -2,6 +2,9 @@ require 'fast_spec_helper' +# Patching ActiveSupport::Concern +require_relative '../../../../config/initializers/0_as_concern' + RSpec.describe Gitlab::Utils::Override do let(:base) do Struct.new(:good) do @@ -164,6 +167,70 @@ RSpec.describe Gitlab::Utils::Override do it_behaves_like 'checking as intended, nothing was overridden' end + + context 'when ActiveSupport::Concern and class_methods are used' do + # We need to give module names before using Override + let(:base) { stub_const('Base', Module.new) } + let(:extension) { stub_const('Extension', Module.new) } + + def define_base(method_name:) + base.module_eval do + extend ActiveSupport::Concern + + class_methods do + define_method(method_name) do + :f + end + end + end + end + + def define_extension(method_name:) + extension.module_eval do + extend ActiveSupport::Concern + + class_methods do + extend Gitlab::Utils::Override + + override method_name + define_method(method_name) do + :g + end + end + end + end + + context 'when it is defining a overriding method' do + before do + define_base(method_name: :f) + define_extension(method_name: :f) + + base.prepend(extension) + end + + it 'verifies' do + expect(base.f).to eq(:g) + + described_class.verify! + end + end + + context 'when it is not defining a overriding method' do + before do + define_base(method_name: :f) + define_extension(method_name: :g) + + base.prepend(extension) + end + + it 'raises NotImplementedError' do + expect(base.f).to eq(:f) + + expect { described_class.verify! } + .to raise_error(NotImplementedError) + end + end + end end context 'when STATIC_VERIFICATION is not set' do diff --git a/spec/lib/gitlab/utils/usage_data_spec.rb b/spec/lib/gitlab/utils/usage_data_spec.rb index dfc381d0ef2..e964e695828 100644 --- a/spec/lib/gitlab/utils/usage_data_spec.rb +++ b/spec/lib/gitlab/utils/usage_data_spec.rb @@ -58,6 +58,16 @@ RSpec.describe Gitlab::Utils::UsageData do expect(described_class.estimate_batch_distinct_count(relation, 'column')).to eq(5) end + it 'yield provided block with PostgresHll::Buckets' do + buckets = Gitlab::Database::PostgresHll::Buckets.new + + allow_next_instance_of(Gitlab::Database::PostgresHll::BatchDistinctCounter) do |instance| + allow(instance).to receive(:execute).and_return(buckets) + end + + expect { |block| described_class.estimate_batch_distinct_count(relation, 'column', &block) }.to yield_with_args(buckets) + end + context 'quasi integration test for different counting parameters' do # HyperLogLog http://algo.inria.fr/flajolet/Publications/FlFuGaMe07.pdf algorithm # used in estimate_batch_distinct_count produce probabilistic |