diff options
Diffstat (limited to 'spec/lib/gitlab/pages/cache_control_spec.rb')
-rw-r--r-- | spec/lib/gitlab/pages/cache_control_spec.rb | 55 |
1 files changed, 24 insertions, 31 deletions
diff --git a/spec/lib/gitlab/pages/cache_control_spec.rb b/spec/lib/gitlab/pages/cache_control_spec.rb index d46124e0e16..dd15aa87441 100644 --- a/spec/lib/gitlab/pages/cache_control_spec.rb +++ b/spec/lib/gitlab/pages/cache_control_spec.rb @@ -3,20 +3,23 @@ require 'spec_helper' RSpec.describe Gitlab::Pages::CacheControl, feature_category: :pages do - describe '.for_namespace' do - subject(:cache_control) { described_class.for_namespace(1) } + RSpec.shared_examples 'cache_control' do |type| + it { expect(subject.cache_key).to match(/pages_domain_for_#{type}_1_*/) } - it { expect(subject.cache_key).to match(/pages_domain_for_namespace_1_*/) } + describe '#clear_cache', :use_clean_rails_redis_caching do + before do + Rails.cache.write("pages_domain_for_#{type}_1", ['settings-hash']) + Rails.cache.write("pages_domain_for_#{type}_1_settings-hash", 'payload') + end - describe '#clear_cache' do it 'clears the cache' do expect(Rails.cache) .to receive(:delete_multi) .with( array_including( [ - "pages_domain_for_namespace_1", - /pages_domain_for_namespace_1_*/ + "pages_domain_for_#{type}_1", + "pages_domain_for_#{type}_1_settings-hash" ] )) @@ -25,63 +28,53 @@ RSpec.describe Gitlab::Pages::CacheControl, feature_category: :pages do end end - describe '.for_project' do - subject(:cache_control) { described_class.for_project(1) } + describe '.for_namespace' do + subject(:cache_control) { described_class.for_namespace(1) } - it { expect(subject.cache_key).to match(/pages_domain_for_project_1_*/) } + it_behaves_like 'cache_control', 'namespace' + end - describe '#clear_cache' do - it 'clears the cache' do - expect(Rails.cache) - .to receive(:delete_multi) - .with( - array_including( - [ - "pages_domain_for_project_1", - /pages_domain_for_project_1_*/ - ] - )) + describe '.for_domain' do + subject(:cache_control) { described_class.for_domain(1) } - subject.clear_cache - end - end + it_behaves_like 'cache_control', 'domain' end describe '#cache_key' do it 'does not change the pages config' do - expect { described_class.new(type: :project, id: 1).cache_key } + expect { described_class.new(type: :domain, id: 1).cache_key } .not_to change(Gitlab.config, :pages) end it 'is based on pages settings' do access_control = Gitlab.config.pages.access_control - cache_key = described_class.new(type: :project, id: 1).cache_key + cache_key = described_class.new(type: :domain, id: 1).cache_key stub_config(pages: { access_control: !access_control }) - expect(described_class.new(type: :project, id: 1).cache_key).not_to eq(cache_key) + expect(described_class.new(type: :domain, id: 1).cache_key).not_to eq(cache_key) end it 'is based on the force_pages_access_control settings' do force_pages_access_control = ::Gitlab::CurrentSettings.force_pages_access_control - cache_key = described_class.new(type: :project, id: 1).cache_key + cache_key = described_class.new(type: :domain, id: 1).cache_key ::Gitlab::CurrentSettings.force_pages_access_control = !force_pages_access_control - expect(described_class.new(type: :project, id: 1).cache_key).not_to eq(cache_key) + expect(described_class.new(type: :domain, id: 1).cache_key).not_to eq(cache_key) end it 'caches the application settings hash' do expect(Rails.cache) .to receive(:write) - .with("pages_domain_for_project_1", kind_of(Set)) + .with('pages_domain_for_domain_1', kind_of(Set)) - described_class.new(type: :project, id: 1).cache_key + described_class.new(type: :domain, id: 1).cache_key end end it 'fails with invalid type' do expect { described_class.new(type: :unknown, id: nil) } - .to raise_error(ArgumentError, "type must be :namespace or :project") + .to raise_error(ArgumentError, 'type must be :namespace or :domain') end end |