2022-08-13 15:12:31 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
2023-03-04 22:38:38 +05:30
|
|
|
RSpec.describe Gitlab::Pages::CacheControl, feature_category: :pages do
|
2022-08-13 15:12:31 +05:30
|
|
|
describe '.for_namespace' do
|
2022-11-25 23:54:43 +05:30
|
|
|
subject(:cache_control) { described_class.for_namespace(1) }
|
2022-08-13 15:12:31 +05:30
|
|
|
|
2022-11-25 23:54:43 +05:30
|
|
|
it { expect(subject.cache_key).to match(/pages_domain_for_namespace_1_*/) }
|
2022-08-13 15:12:31 +05:30
|
|
|
|
|
|
|
describe '#clear_cache' do
|
|
|
|
it 'clears the cache' do
|
|
|
|
expect(Rails.cache)
|
2023-03-04 22:38:38 +05:30
|
|
|
.to receive(:delete_multi)
|
|
|
|
.with(
|
|
|
|
array_including(
|
|
|
|
[
|
|
|
|
"pages_domain_for_namespace_1",
|
|
|
|
/pages_domain_for_namespace_1_*/
|
|
|
|
]
|
|
|
|
))
|
2022-08-13 15:12:31 +05:30
|
|
|
|
|
|
|
subject.clear_cache
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '.for_project' do
|
2022-11-25 23:54:43 +05:30
|
|
|
subject(:cache_control) { described_class.for_project(1) }
|
2022-08-13 15:12:31 +05:30
|
|
|
|
2022-11-25 23:54:43 +05:30
|
|
|
it { expect(subject.cache_key).to match(/pages_domain_for_project_1_*/) }
|
2022-08-13 15:12:31 +05:30
|
|
|
|
|
|
|
describe '#clear_cache' do
|
|
|
|
it 'clears the cache' do
|
|
|
|
expect(Rails.cache)
|
2023-03-04 22:38:38 +05:30
|
|
|
.to receive(:delete_multi)
|
|
|
|
.with(
|
|
|
|
array_including(
|
|
|
|
[
|
|
|
|
"pages_domain_for_project_1",
|
|
|
|
/pages_domain_for_project_1_*/
|
|
|
|
]
|
|
|
|
))
|
2022-08-13 15:12:31 +05:30
|
|
|
|
|
|
|
subject.clear_cache
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2022-11-25 23:54:43 +05:30
|
|
|
|
|
|
|
describe '#cache_key' do
|
|
|
|
it 'does not change the pages config' do
|
|
|
|
expect { described_class.new(type: :project, 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
|
|
|
|
|
|
|
|
stub_config(pages: { access_control: !access_control })
|
|
|
|
|
|
|
|
expect(described_class.new(type: :project, 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
|
|
|
|
|
|
|
|
::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)
|
|
|
|
end
|
2023-03-04 22:38:38 +05:30
|
|
|
|
|
|
|
it 'caches the application settings hash' do
|
|
|
|
expect(Rails.cache)
|
|
|
|
.to receive(:write)
|
|
|
|
.with("pages_domain_for_project_1", kind_of(Set))
|
|
|
|
|
|
|
|
described_class.new(type: :project, id: 1).cache_key
|
|
|
|
end
|
2022-11-25 23:54:43 +05:30
|
|
|
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")
|
|
|
|
end
|
2022-08-13 15:12:31 +05:30
|
|
|
end
|