diff options
Diffstat (limited to 'spec/config')
-rw-r--r-- | spec/config/inject_enterprise_edition_module_spec.rb | 129 | ||||
-rw-r--r-- | spec/config/mail_room_spec.rb | 2 | ||||
-rw-r--r-- | spec/config/object_store_settings_spec.rb | 4 |
3 files changed, 134 insertions, 1 deletions
diff --git a/spec/config/inject_enterprise_edition_module_spec.rb b/spec/config/inject_enterprise_edition_module_spec.rb new file mode 100644 index 00000000000..61b40e46001 --- /dev/null +++ b/spec/config/inject_enterprise_edition_module_spec.rb @@ -0,0 +1,129 @@ +# frozen_string_literal: true + +require 'fast_spec_helper' + +RSpec.describe InjectEnterpriseEditionModule do + let(:extension_name) { 'FF' } + let(:extension_namespace) { Module.new } + let(:fish_name) { 'Fish' } + let(:fish_class) { Class.new } + let(:fish_extension) { Module.new } + + before do + # Make sure we're not relying on which mode we're running under + allow(Gitlab).to receive(:extensions).and_return([extension_name.downcase]) + + # Test on an imagined extension and imagined class + stub_const(fish_name, fish_class) # Fish + allow(fish_class).to receive(:name).and_return(fish_name) + end + + shared_examples 'expand the extension with' do |method| + context 'when extension namespace is set at top-level' do + before do + stub_const(extension_name, extension_namespace) # FF + extension_namespace.const_set(fish_name, fish_extension) # FF::Fish + end + + it "calls #{method} with the extension module" do + expect(fish_class).to receive(method).with(fish_extension) + + fish_class.__send__("#{method}_mod_with", fish_name) + end + end + + context 'when extension namespace is set at another namespace' do + let(:another_namespace) { Module.new } # QA + + before do + another_namespace.const_set(extension_name, extension_namespace) # QA::FF + extension_namespace.const_set(fish_name, fish_extension) # QA::FF::Fish + end + + it "calls #{method} with the extension module from the additional namespace" do + expect(fish_class).to receive(method).with(fish_extension) + + fish_class.__send__("#{method}_mod_with", fish_name, namespace: another_namespace) + end + end + + context 'when extension namespace exists but not the extension' do + before do + stub_const(extension_name, extension_namespace) # FF + end + + it "does not call #{method}" do + expect(fish_class).not_to receive(method).with(fish_extension) + + fish_class.__send__("#{method}_mod_with", fish_name) + end + end + + context 'when extension namespace does not exist' do + it "does not call #{method}" do + expect(fish_class).not_to receive(method).with(fish_extension) + + fish_class.__send__("#{method}_mod_with", fish_name) + end + end + end + + shared_examples 'expand the assumed extension with' do |method| + context 'when extension namespace is set at top-level' do + before do + stub_const(extension_name, extension_namespace) # FF + extension_namespace.const_set(fish_name, fish_extension) # FF::Fish + end + + it "calls #{method} with the extension module" do + expect(fish_class).to receive(method).with(fish_extension) + + fish_class.__send__("#{method}_mod") + end + end + + context 'when extension namespace exists but not the extension' do + before do + stub_const(extension_name, extension_namespace) # FF + end + + it "does not call #{method}" do + expect(fish_class).not_to receive(method).with(fish_extension) + + fish_class.__send__("#{method}_mod") + end + end + + context 'when extension namespace does not exist' do + it "does not call #{method}" do + expect(fish_class).not_to receive(method).with(fish_extension) + + fish_class.__send__("#{method}_mod") + end + end + end + + describe '#prepend_mod_with' do + it_behaves_like 'expand the extension with', :prepend + end + + describe '#extend_mod_with' do + it_behaves_like 'expand the extension with', :extend + end + + describe '#include_mod_with' do + it_behaves_like 'expand the extension with', :include + end + + describe '#prepend_mod' do + it_behaves_like 'expand the assumed extension with', :prepend + end + + describe '#extend_mod' do + it_behaves_like 'expand the assumed extension with', :extend + end + + describe '#include_mod' do + it_behaves_like 'expand the assumed extension with', :include + end +end diff --git a/spec/config/mail_room_spec.rb b/spec/config/mail_room_spec.rb index 6265b54931a..ce514bd8905 100644 --- a/spec/config/mail_room_spec.rb +++ b/spec/config/mail_room_spec.rb @@ -21,7 +21,7 @@ RSpec.describe 'mail_room.yml' do status = result.status raise "Error interpreting #{mailroom_config_path}: #{output}" unless status == 0 - YAML.load(output) + YAML.safe_load(output, permitted_classes: [Symbol]) end before do diff --git a/spec/config/object_store_settings_spec.rb b/spec/config/object_store_settings_spec.rb index 68b37197ca7..33443509e4a 100644 --- a/spec/config/object_store_settings_spec.rb +++ b/spec/config/object_store_settings_spec.rb @@ -74,6 +74,7 @@ RSpec.describe ObjectStoreSettings do expect(settings.artifacts['object_store']['proxy_download']).to be false expect(settings.artifacts['object_store']['remote_directory']).to eq('artifacts') expect(settings.artifacts['object_store']['consolidated_settings']).to be true + expect(settings.artifacts).to eq(settings['artifacts']) expect(settings.lfs['enabled']).to be true expect(settings.lfs['object_store']['enabled']).to be true @@ -83,15 +84,18 @@ RSpec.describe ObjectStoreSettings do expect(settings.lfs['object_store']['proxy_download']).to be true expect(settings.lfs['object_store']['remote_directory']).to eq('lfs-objects') expect(settings.lfs['object_store']['consolidated_settings']).to be true + expect(settings.lfs).to eq(settings['lfs']) expect(settings.pages['enabled']).to be true expect(settings.pages['object_store']['enabled']).to be true expect(settings.pages['object_store']['connection']).to eq(connection) expect(settings.pages['object_store']['remote_directory']).to eq('pages') expect(settings.pages['object_store']['consolidated_settings']).to be true + expect(settings.pages).to eq(settings['pages']) expect(settings.external_diffs['enabled']).to be false expect(settings.external_diffs['object_store']).to be_nil + expect(settings.external_diffs).to eq(settings['external_diffs']) end it 'raises an error when a bucket is missing' do |