diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-12-19 14:01:45 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-12-19 14:01:45 +0300 |
commit | 9297025d0b7ddf095eb618dfaaab2ff8f2018d8b (patch) | |
tree | 865198c01d1824a9b098127baa3ab980c9cd2c06 /spec/models/pages/virtual_domain_spec.rb | |
parent | 6372471f43ee03c05a7c1f8b0c6ac6b8a7431dbe (diff) |
Add latest changes from gitlab-org/gitlab@16-7-stable-eev16.7.0-rc42
Diffstat (limited to 'spec/models/pages/virtual_domain_spec.rb')
-rw-r--r-- | spec/models/pages/virtual_domain_spec.rb | 92 |
1 files changed, 57 insertions, 35 deletions
diff --git a/spec/models/pages/virtual_domain_spec.rb b/spec/models/pages/virtual_domain_spec.rb index 02e3fd67f2d..5925b662ee8 100644 --- a/spec/models/pages/virtual_domain_spec.rb +++ b/spec/models/pages/virtual_domain_spec.rb @@ -3,9 +3,30 @@ require 'spec_helper' RSpec.describe Pages::VirtualDomain, feature_category: :pages do + let(:domain) { nil } + let(:trim_prefix) { nil } + + let_it_be(:group) { create(:group, path: 'mygroup') } + let_it_be(:project_a) { create(:project, group: group) } + let_it_be(:project_a_main_deployment) { create(:pages_deployment, project: project_a, path_prefix: nil) } + let_it_be(:project_a_versioned_deployment) { create(:pages_deployment, project: project_a, path_prefix: 'v1') } + let_it_be(:project_b) { create(:project, group: group) } + let_it_be(:project_b_main_deployment) { create(:pages_deployment, project: project_b, path_prefix: nil) } + let_it_be(:project_b_versioned_deployment) { create(:pages_deployment, project: project_b, path_prefix: 'v1') } + let_it_be(:project_c) { create(:project, group: group) } + let_it_be(:project_c_main_deployment) { create(:pages_deployment, project: project_c, path_prefix: nil) } + let_it_be(:project_c_versioned_deployment) { create(:pages_deployment, project: project_c, path_prefix: 'v1') } + + before_all do + # Those deployments are created to ensure that deactivated deployments won't be returned on the queries + deleted_at = 1.hour.ago + create(:pages_deployment, project: project_a, path_prefix: 'v2', deleted_at: deleted_at) + create(:pages_deployment, project: project_b, path_prefix: 'v2', deleted_at: deleted_at) + create(:pages_deployment, project: project_c, path_prefix: 'v2', deleted_at: deleted_at) + end + describe '#certificate and #key pair' do - let(:domain) { nil } - let(:project) { instance_double(Project) } + let(:project) { project_a } subject(:virtual_domain) { described_class.new(projects: [project], domain: domain) } @@ -25,51 +46,52 @@ RSpec.describe Pages::VirtualDomain, feature_category: :pages do end describe '#lookup_paths' do - let(:domain) { nil } - let(:trim_prefix) { nil } - let(:project_a) { instance_double(Project) } - let(:project_b) { instance_double(Project) } - let(:project_c) { instance_double(Project) } - let(:pages_lookup_path_a) { instance_double(Pages::LookupPath, prefix: 'aaa', source: { type: 'zip', path: 'https://example.com' }) } - let(:pages_lookup_path_b) { instance_double(Pages::LookupPath, prefix: 'bbb', source: { type: 'zip', path: 'https://example.com' }) } - let(:pages_lookup_path_without_source) { instance_double(Pages::LookupPath, prefix: 'ccc', source: nil) } + let(:project_list) { [project_a, project_b, project_c] } subject(:virtual_domain) do described_class.new(projects: project_list, domain: domain, trim_prefix: trim_prefix) end - before do - allow(Pages::LookupPath) - .to receive(:new) - .with(project_a, domain: domain, trim_prefix: trim_prefix) - .and_return(pages_lookup_path_a) - - allow(Pages::LookupPath) - .to receive(:new) - .with(project_b, domain: domain, trim_prefix: trim_prefix) - .and_return(pages_lookup_path_b) - - allow(Pages::LookupPath) - .to receive(:new) - .with(project_c, domain: domain, trim_prefix: trim_prefix) - .and_return(pages_lookup_path_without_source) - end + context 'when pages multiple versions is disabled' do + before do + allow(::Gitlab::Pages) + .to receive(:multiple_versions_enabled_for?) + .and_return(false) + end - context 'when there is pages domain provided' do - let(:domain) { instance_double(PagesDomain) } - let(:project_list) { [project_a, project_b, project_c] } + it 'returns only the main deployments for each project' do + global_ids = virtual_domain.lookup_paths.map do |lookup_path| + lookup_path.source[:global_id] + end - it 'returns collection of projects pages lookup paths sorted by prefix in reverse' do - expect(virtual_domain.lookup_paths).to eq([pages_lookup_path_b, pages_lookup_path_a]) + expect(global_ids).to match_array([ + project_a_main_deployment.to_gid.to_s, + project_b_main_deployment.to_gid.to_s, + project_c_main_deployment.to_gid.to_s + ]) end end - context 'when there is trim_prefix provided' do - let(:trim_prefix) { 'group/' } - let(:project_list) { [project_a, project_b] } + context 'when pages multiple versions is enabled' do + before do + allow(::Gitlab::Pages) + .to receive(:multiple_versions_enabled_for?) + .and_return(true) + end it 'returns collection of projects pages lookup paths sorted by prefix in reverse' do - expect(virtual_domain.lookup_paths).to eq([pages_lookup_path_b, pages_lookup_path_a]) + global_ids = virtual_domain.lookup_paths.map do |lookup_path| + lookup_path.source[:global_id] + end + + expect(global_ids).to match_array([ + project_a_main_deployment.to_gid.to_s, + project_a_versioned_deployment.to_gid.to_s, + project_b_main_deployment.to_gid.to_s, + project_b_versioned_deployment.to_gid.to_s, + project_c_main_deployment.to_gid.to_s, + project_c_versioned_deployment.to_gid.to_s + ]) end end end |