Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'spec/services/projects')
-rw-r--r--spec/services/projects/batch_open_issues_count_service_spec.rb45
-rw-r--r--spec/services/projects/create_service_spec.rb24
-rw-r--r--spec/services/projects/fork_service_spec.rb4
-rw-r--r--spec/services/projects/group_links/destroy_service_spec.rb60
-rw-r--r--spec/services/projects/open_issues_count_service_spec.rb109
-rw-r--r--spec/services/projects/operations/update_service_spec.rb4
-rw-r--r--spec/services/projects/transfer_service_spec.rb33
-rw-r--r--spec/services/projects/update_pages_service_spec.rb158
-rw-r--r--spec/services/projects/update_service_spec.rb24
9 files changed, 182 insertions, 279 deletions
diff --git a/spec/services/projects/batch_open_issues_count_service_spec.rb b/spec/services/projects/batch_open_issues_count_service_spec.rb
index 82d50604309..17bd5f7a37b 100644
--- a/spec/services/projects/batch_open_issues_count_service_spec.rb
+++ b/spec/services/projects/batch_open_issues_count_service_spec.rb
@@ -5,52 +5,49 @@ require 'spec_helper'
RSpec.describe Projects::BatchOpenIssuesCountService do
let!(:project_1) { create(:project) }
let!(:project_2) { create(:project) }
+ let!(:banned_user) { create(:user, :banned) }
let(:subject) { described_class.new([project_1, project_2]) }
- describe '#refresh_cache', :use_clean_rails_memory_store_caching do
+ describe '#refresh_cache_and_retrieve_data', :use_clean_rails_memory_store_caching do
before do
create(:issue, project: project_1)
create(:issue, project: project_1, confidential: true)
-
+ create(:issue, project: project_1, author: banned_user)
create(:issue, project: project_2)
create(:issue, project: project_2, confidential: true)
+ create(:issue, project: project_2, author: banned_user)
end
- context 'when cache is clean' do
+ context 'when cache is clean', :aggregate_failures do
it 'refreshes cache keys correctly' do
- subject.refresh_cache
+ expect(get_cache_key(project_1)).to eq(nil)
+ expect(get_cache_key(project_2)).to eq(nil)
- # It does not update total issues cache
- expect(Rails.cache.read(get_cache_key(subject, project_1))).to eq(nil)
- expect(Rails.cache.read(get_cache_key(subject, project_2))).to eq(nil)
+ subject.count_service.new(project_1).refresh_cache
+ subject.count_service.new(project_2).refresh_cache
- expect(Rails.cache.read(get_cache_key(subject, project_1, true))).to eq(1)
- expect(Rails.cache.read(get_cache_key(subject, project_1, true))).to eq(1)
- end
- end
-
- context 'when issues count is already cached' do
- before do
- create(:issue, project: project_2)
- subject.refresh_cache
- end
+ expect(get_cache_key(project_1)).to eq(1)
+ expect(get_cache_key(project_2)).to eq(1)
- it 'does update cache again' do
- expect(Rails.cache).not_to receive(:write)
+ expect(get_cache_key(project_1, true)).to eq(2)
+ expect(get_cache_key(project_2, true)).to eq(2)
- subject.refresh_cache
+ expect(get_cache_key(project_1, true, true)).to eq(3)
+ expect(get_cache_key(project_2, true, true)).to eq(3)
end
end
end
- def get_cache_key(subject, project, public_key = false)
+ def get_cache_key(project, with_confidential = false, with_hidden = false)
service = subject.count_service.new(project)
- if public_key
- service.cache_key(service.class::PUBLIC_COUNT_KEY)
+ if with_confidential && with_hidden
+ Rails.cache.read(service.cache_key(service.class::TOTAL_COUNT_KEY))
+ elsif with_confidential
+ Rails.cache.read(service.cache_key(service.class::TOTAL_COUNT_WITHOUT_HIDDEN_KEY))
else
- service.cache_key(service.class::TOTAL_COUNT_KEY)
+ Rails.cache.read(service.cache_key(service.class::PUBLIC_COUNT_WITHOUT_HIDDEN_KEY))
end
end
end
diff --git a/spec/services/projects/create_service_spec.rb b/spec/services/projects/create_service_spec.rb
index c3928563125..e15d9341fd1 100644
--- a/spec/services/projects/create_service_spec.rb
+++ b/spec/services/projects/create_service_spec.rb
@@ -86,7 +86,7 @@ RSpec.describe Projects::CreateService, '#execute' do
subject(:project) { create_project(user, opts) }
context "with 'topics' parameter" do
- let(:opts) { { topics: 'topics' } }
+ let(:opts) { { name: 'topic-project', topics: 'topics' } }
it 'keeps them as specified' do
expect(project.topic_list).to eq(%w[topics])
@@ -94,7 +94,7 @@ RSpec.describe Projects::CreateService, '#execute' do
end
context "with 'topic_list' parameter" do
- let(:opts) { { topic_list: 'topic_list' } }
+ let(:opts) { { name: 'topic-project', topic_list: 'topic_list' } }
it 'keeps them as specified' do
expect(project.topic_list).to eq(%w[topic_list])
@@ -102,7 +102,7 @@ RSpec.describe Projects::CreateService, '#execute' do
end
context "with 'tag_list' parameter (deprecated)" do
- let(:opts) { { tag_list: 'tag_list' } }
+ let(:opts) { { name: 'topic-project', tag_list: 'tag_list' } }
it 'keeps them as specified' do
expect(project.topic_list).to eq(%w[tag_list])
@@ -346,6 +346,12 @@ RSpec.describe Projects::CreateService, '#execute' do
expect(imported_project.import_data.data).to eq(import_data[:data])
expect(imported_project.import_url).to eq('http://import-url')
end
+
+ it 'tracks for the combined_registration experiment', :experiment do
+ expect(experiment(:combined_registration)).to track(:import_project).on_next_instance
+
+ imported_project
+ end
end
context 'builds_enabled global setting' do
@@ -601,6 +607,18 @@ RSpec.describe Projects::CreateService, '#execute' do
MARKDOWN
end
end
+
+ context 'and readme_template is specified' do
+ before do
+ opts[:readme_template] = "# GitLab\nThis is customized template."
+ end
+
+ it_behaves_like 'creates README.md'
+
+ it 'creates README.md with specified template' do
+ expect(project.repository.readme.data).to include('This is customized template.')
+ end
+ end
end
end
diff --git a/spec/services/projects/fork_service_spec.rb b/spec/services/projects/fork_service_spec.rb
index d710e4a777f..3f58fa46806 100644
--- a/spec/services/projects/fork_service_spec.rb
+++ b/spec/services/projects/fork_service_spec.rb
@@ -28,7 +28,8 @@ RSpec.describe Projects::ForkService do
namespace: @from_namespace,
star_count: 107,
avatar: avatar,
- description: 'wow such project')
+ description: 'wow such project',
+ external_authorization_classification_label: 'classification-label')
@to_user = create(:user)
@to_namespace = @to_user.namespace
@from_project.add_user(@to_user, :developer)
@@ -66,6 +67,7 @@ RSpec.describe Projects::ForkService do
it { expect(to_project.description).to eq(@from_project.description) }
it { expect(to_project.avatar.file).to be_exists }
it { expect(to_project.ci_config_path).to eq(@from_project.ci_config_path) }
+ it { expect(to_project.external_authorization_classification_label).to eq(@from_project.external_authorization_classification_label) }
# This test is here because we had a bug where the from-project lost its
# avatar after being forked.
diff --git a/spec/services/projects/group_links/destroy_service_spec.rb b/spec/services/projects/group_links/destroy_service_spec.rb
index d65afb68bfe..5d07fd52230 100644
--- a/spec/services/projects/group_links/destroy_service_spec.rb
+++ b/spec/services/projects/group_links/destroy_service_spec.rb
@@ -20,54 +20,28 @@ RSpec.describe Projects::GroupLinks::DestroyService, '#execute' do
group.add_maintainer(user)
end
- context 'when the feature flag `use_specialized_worker_for_project_auth_recalculation` is enabled' do
- before do
- stub_feature_flags(use_specialized_worker_for_project_auth_recalculation: true)
- end
-
- it 'calls AuthorizedProjectUpdate::ProjectRecalculateWorker to update project authorizations' do
- expect(AuthorizedProjectUpdate::ProjectRecalculateWorker)
- .to receive(:perform_async).with(group_link.project.id)
-
- subject.execute(group_link)
- end
-
- it 'calls AuthorizedProjectUpdate::UserRefreshFromReplicaWorker with a delay to update project authorizations' do
- expect(AuthorizedProjectUpdate::UserRefreshFromReplicaWorker).to(
- receive(:bulk_perform_in)
- .with(1.hour,
- [[user.id]],
- batch_delay: 30.seconds, batch_size: 100)
- )
-
- subject.execute(group_link)
- end
+ it 'calls AuthorizedProjectUpdate::ProjectRecalculateWorker to update project authorizations' do
+ expect(AuthorizedProjectUpdate::ProjectRecalculateWorker)
+ .to receive(:perform_async).with(group_link.project.id)
- it 'updates project authorizations of users who had access to the project via the group share', :sidekiq_inline do
- expect { subject.execute(group_link) }.to(
- change { Ability.allowed?(user, :read_project, project) }
- .from(true).to(false))
- end
+ subject.execute(group_link)
end
- context 'when the feature flag `use_specialized_worker_for_project_auth_recalculation` is disabled' do
- before do
- stub_feature_flags(use_specialized_worker_for_project_auth_recalculation: false)
- end
-
- it 'calls UserProjectAccessChangedService to update project authorizations' do
- expect_next_instance_of(UserProjectAccessChangedService, [user.id]) do |service|
- expect(service).to receive(:execute)
- end
+ it 'calls AuthorizedProjectUpdate::UserRefreshFromReplicaWorker with a delay to update project authorizations' do
+ expect(AuthorizedProjectUpdate::UserRefreshFromReplicaWorker).to(
+ receive(:bulk_perform_in)
+ .with(1.hour,
+ [[user.id]],
+ batch_delay: 30.seconds, batch_size: 100)
+ )
- subject.execute(group_link)
- end
+ subject.execute(group_link)
+ end
- it 'updates project authorizations of users who had access to the project via the group share' do
- expect { subject.execute(group_link) }.to(
- change { Ability.allowed?(user, :read_project, project) }
- .from(true).to(false))
- end
+ it 'updates project authorizations of users who had access to the project via the group share', :sidekiq_inline do
+ expect { subject.execute(group_link) }.to(
+ change { Ability.allowed?(user, :read_project, project) }
+ .from(true).to(false))
end
end
diff --git a/spec/services/projects/open_issues_count_service_spec.rb b/spec/services/projects/open_issues_count_service_spec.rb
index c739fea5ecf..8710d0c0267 100644
--- a/spec/services/projects/open_issues_count_service_spec.rb
+++ b/spec/services/projects/open_issues_count_service_spec.rb
@@ -4,89 +4,102 @@ require 'spec_helper'
RSpec.describe Projects::OpenIssuesCountService, :use_clean_rails_memory_store_caching do
let(:project) { create(:project) }
+ let(:user) { create(:user) }
+ let(:banned_user) { create(:user, :banned) }
- subject { described_class.new(project) }
+ subject { described_class.new(project, user) }
it_behaves_like 'a counter caching service'
+ before do
+ create(:issue, :opened, project: project)
+ create(:issue, :opened, confidential: true, project: project)
+ create(:issue, :opened, author: banned_user, project: project)
+ create(:issue, :closed, project: project)
+
+ described_class.new(project).refresh_cache
+ end
+
describe '#count' do
- context 'when user is nil' do
- it 'does not include confidential issues in the issue count' do
- create(:issue, :opened, project: project)
- create(:issue, :opened, confidential: true, project: project)
+ shared_examples 'counts public issues, does not count hidden or confidential' do
+ it 'counts only public issues' do
+ expect(subject.count).to eq(1)
+ end
- expect(described_class.new(project).count).to eq(1)
+ it 'uses PUBLIC_COUNT_WITHOUT_HIDDEN_KEY cache key' do
+ expect(subject.cache_key).to include('project_open_public_issues_without_hidden_count')
end
end
- context 'when user is provided' do
- let(:user) { create(:user) }
+ context 'when user is nil' do
+ let(:user) { nil }
+
+ it_behaves_like 'counts public issues, does not count hidden or confidential'
+ end
+ context 'when user is provided' do
context 'when user can read confidential issues' do
before do
project.add_reporter(user)
end
- it 'returns the right count with confidential issues' do
- create(:issue, :opened, project: project)
- create(:issue, :opened, confidential: true, project: project)
-
- expect(described_class.new(project, user).count).to eq(2)
+ it 'includes confidential issues and does not include hidden issues in count' do
+ expect(subject.count).to eq(2)
end
- it 'uses total_open_issues_count cache key' do
- expect(described_class.new(project, user).cache_key_name).to eq('total_open_issues_count')
+ it 'uses TOTAL_COUNT_WITHOUT_HIDDEN_KEY cache key' do
+ expect(subject.cache_key).to include('project_open_issues_without_hidden_count')
end
end
- context 'when user cannot read confidential issues' do
+ context 'when user cannot read confidential or hidden issues' do
before do
project.add_guest(user)
end
- it 'does not include confidential issues' do
- create(:issue, :opened, project: project)
- create(:issue, :opened, confidential: true, project: project)
+ it_behaves_like 'counts public issues, does not count hidden or confidential'
+ end
+
+ context 'when user is an admin' do
+ let_it_be(:user) { create(:user, :admin) }
+
+ context 'when admin mode is enabled', :enable_admin_mode do
+ it 'includes confidential and hidden issues in count' do
+ expect(subject.count).to eq(3)
+ end
- expect(described_class.new(project, user).count).to eq(1)
+ it 'uses TOTAL_COUNT_KEY cache key' do
+ expect(subject.cache_key).to include('project_open_issues_including_hidden_count')
+ end
end
- it 'uses public_open_issues_count cache key' do
- expect(described_class.new(project, user).cache_key_name).to eq('public_open_issues_count')
+ context 'when admin mode is disabled' do
+ it_behaves_like 'counts public issues, does not count hidden or confidential'
end
end
end
+ end
- describe '#refresh_cache' do
- before do
- create(:issue, :opened, project: project)
- create(:issue, :opened, project: project)
- create(:issue, :opened, confidential: true, project: project)
- end
-
- context 'when cache is empty' do
- it 'refreshes cache keys correctly' do
- subject.refresh_cache
-
- expect(Rails.cache.read(subject.cache_key(described_class::PUBLIC_COUNT_KEY))).to eq(2)
- expect(Rails.cache.read(subject.cache_key(described_class::TOTAL_COUNT_KEY))).to eq(3)
- end
+ describe '#refresh_cache', :aggregate_failures do
+ context 'when cache is empty' do
+ it 'refreshes cache keys correctly' do
+ expect(Rails.cache.read(described_class.new(project).cache_key(described_class::PUBLIC_COUNT_WITHOUT_HIDDEN_KEY))).to eq(1)
+ expect(Rails.cache.read(described_class.new(project).cache_key(described_class::TOTAL_COUNT_WITHOUT_HIDDEN_KEY))).to eq(2)
+ expect(Rails.cache.read(described_class.new(project).cache_key(described_class::TOTAL_COUNT_KEY))).to eq(3)
end
+ end
- context 'when cache is outdated' do
- before do
- subject.refresh_cache
- end
-
- it 'refreshes cache keys correctly' do
- create(:issue, :opened, project: project)
- create(:issue, :opened, confidential: true, project: project)
+ context 'when cache is outdated' do
+ it 'refreshes cache keys correctly' do
+ create(:issue, :opened, project: project)
+ create(:issue, :opened, confidential: true, project: project)
+ create(:issue, :opened, author: banned_user, project: project)
- subject.refresh_cache
+ described_class.new(project).refresh_cache
- expect(Rails.cache.read(subject.cache_key(described_class::PUBLIC_COUNT_KEY))).to eq(3)
- expect(Rails.cache.read(subject.cache_key(described_class::TOTAL_COUNT_KEY))).to eq(5)
- end
+ expect(Rails.cache.read(described_class.new(project).cache_key(described_class::PUBLIC_COUNT_WITHOUT_HIDDEN_KEY))).to eq(2)
+ expect(Rails.cache.read(described_class.new(project).cache_key(described_class::TOTAL_COUNT_WITHOUT_HIDDEN_KEY))).to eq(4)
+ expect(Rails.cache.read(described_class.new(project).cache_key(described_class::TOTAL_COUNT_KEY))).to eq(6)
end
end
end
diff --git a/spec/services/projects/operations/update_service_spec.rb b/spec/services/projects/operations/update_service_spec.rb
index 1d9d5f6e938..a71fafb2121 100644
--- a/spec/services/projects/operations/update_service_spec.rb
+++ b/spec/services/projects/operations/update_service_spec.rb
@@ -153,6 +153,7 @@ RSpec.describe Projects::Operations::UpdateService do
{
error_tracking_setting_attributes: {
enabled: false,
+ integrated: true,
api_host: 'http://gitlab.com/',
token: 'token',
project: {
@@ -174,6 +175,7 @@ RSpec.describe Projects::Operations::UpdateService do
project.reload
expect(project.error_tracking_setting).not_to be_enabled
+ expect(project.error_tracking_setting.integrated).to be_truthy
expect(project.error_tracking_setting.api_url).to eq(
'http://gitlab.com/api/0/projects/org/project/'
)
@@ -206,6 +208,7 @@ RSpec.describe Projects::Operations::UpdateService do
{
error_tracking_setting_attributes: {
enabled: true,
+ integrated: true,
api_host: 'http://gitlab.com/',
token: 'token',
project: {
@@ -222,6 +225,7 @@ RSpec.describe Projects::Operations::UpdateService do
expect(result[:status]).to eq(:success)
expect(project.error_tracking_setting).to be_enabled
+ expect(project.error_tracking_setting.integrated).to be_truthy
expect(project.error_tracking_setting.api_url).to eq(
'http://gitlab.com/api/0/projects/org/project/'
)
diff --git a/spec/services/projects/transfer_service_spec.rb b/spec/services/projects/transfer_service_spec.rb
index b71677a5e8f..d96573e26af 100644
--- a/spec/services/projects/transfer_service_spec.rb
+++ b/spec/services/projects/transfer_service_spec.rb
@@ -292,10 +292,37 @@ RSpec.describe Projects::TransferService do
end
end
- context 'target namespace allows developers to create projects' do
+ context 'target namespace matches current namespace' do
+ let(:group) { user.namespace }
+
+ it 'does not allow project transfer' do
+ transfer_result = execute_transfer
+
+ expect(transfer_result).to eq false
+ expect(project.namespace).to eq(user.namespace)
+ expect(project.errors[:new_namespace]).to include('Project is already in this namespace.')
+ end
+ end
+
+ context 'when user does not own the project' do
+ let(:project) { create(:project, :repository, :legacy_storage) }
+
+ before do
+ project.add_developer(user)
+ end
+
+ it 'does not allow project transfer to the target namespace' do
+ transfer_result = execute_transfer
+
+ expect(transfer_result).to eq false
+ expect(project.errors[:new_namespace]).to include("You don't have permission to transfer this project.")
+ end
+ end
+
+ context 'when user can create projects in the target namespace' do
let(:group) { create(:group, project_creation_level: ::Gitlab::Access::DEVELOPER_MAINTAINER_PROJECT_ACCESS) }
- context 'the user is a member of the target namespace with developer permissions' do
+ context 'but has only developer permissions in the target namespace' do
before do
group.add_developer(user)
end
@@ -305,7 +332,7 @@ RSpec.describe Projects::TransferService do
expect(transfer_result).to eq false
expect(project.namespace).to eq(user.namespace)
- expect(project.errors[:new_namespace]).to include('Transfer failed, please contact an admin.')
+ expect(project.errors[:new_namespace]).to include("You don't have permission to transfer projects into that namespace.")
end
end
end
diff --git a/spec/services/projects/update_pages_service_spec.rb b/spec/services/projects/update_pages_service_spec.rb
index 0f21736eda0..6d0b75e0c95 100644
--- a/spec/services/projects/update_pages_service_spec.rb
+++ b/spec/services/projects/update_pages_service_spec.rb
@@ -18,17 +18,6 @@ RSpec.describe Projects::UpdatePagesService do
subject { described_class.new(project, build) }
- before do
- stub_feature_flags(skip_pages_deploy_to_legacy_storage: false)
- project.legacy_remove_pages
- end
-
- context '::TMP_EXTRACT_PATH' do
- subject { described_class::TMP_EXTRACT_PATH }
-
- it { is_expected.not_to match(Gitlab::PathRegex.namespace_format_regex) }
- end
-
context 'for new artifacts' do
context "for a valid job" do
let!(:artifacts_archive) { create(:ci_job_artifact, :correct_checksum, file: file, job: build) }
@@ -52,36 +41,6 @@ RSpec.describe Projects::UpdatePagesService do
expect(project.pages_metadatum).to be_deployed
expect(project.pages_metadatum.artifacts_archive).to eq(artifacts_archive)
expect(project.pages_deployed?).to be_truthy
-
- # Check that all expected files are extracted
- %w[index.html zero .hidden/file].each do |filename|
- expect(File.exist?(File.join(project.pages_path, 'public', filename))).to be_truthy
- end
- end
-
- it 'creates a temporary directory with the project and build ID' do
- expect(Dir).to receive(:mktmpdir).with("project-#{project.id}-build-#{build.id}-", anything).and_call_original
-
- subject.execute
- end
-
- it "doesn't deploy to legacy storage if it's disabled" do
- allow(Settings.pages.local_store).to receive(:enabled).and_return(false)
-
- expect(execute).to eq(:success)
- expect(project.pages_deployed?).to be_truthy
-
- expect(File.exist?(File.join(project.pages_path, 'public', 'index.html'))).to eq(false)
- end
-
- it "doesn't deploy to legacy storage if skip_pages_deploy_to_legacy_storage is enabled" do
- allow(Settings.pages.local_store).to receive(:enabled).and_return(true)
- stub_feature_flags(skip_pages_deploy_to_legacy_storage: true)
-
- expect(execute).to eq(:success)
- expect(project.pages_deployed?).to be_truthy
-
- expect(File.exist?(File.join(project.pages_path, 'public', 'index.html'))).to eq(false)
end
it 'creates pages_deployment and saves it in the metadata' do
@@ -99,16 +58,6 @@ RSpec.describe Projects::UpdatePagesService do
expect(deployment.ci_build_id).to eq(build.id)
end
- it 'fails if another deployment is in progress' do
- subject.try_obtain_lease do
- expect do
- execute
- end.to raise_error("Failed to deploy pages - other deployment is in progress")
-
- expect(GenericCommitStatus.last.description).to eq("Failed to deploy pages - other deployment is in progress")
- end
- end
-
it 'does not fail if pages_metadata is absent' do
project.pages_metadatum.destroy!
project.reload
@@ -156,47 +105,10 @@ RSpec.describe Projects::UpdatePagesService do
expect(GenericCommitStatus.last.description).to eq("pages site contains 3 file entries, while limit is set to 2")
end
- it 'removes pages after destroy' do
- expect(PagesWorker).to receive(:perform_in)
- expect(project.pages_deployed?).to be_falsey
- expect(Dir.exist?(File.join(project.pages_path))).to be_falsey
-
- expect(execute).to eq(:success)
-
- expect(project.pages_metadatum).to be_deployed
- expect(project.pages_deployed?).to be_truthy
- expect(Dir.exist?(File.join(project.pages_path))).to be_truthy
-
- project.destroy!
-
- expect(Dir.exist?(File.join(project.pages_path))).to be_falsey
- expect(ProjectPagesMetadatum.find_by_project_id(project)).to be_nil
- end
-
- context 'when using empty file' do
- let(:file) { empty_file }
-
- it 'fails to extract' do
- expect { execute }
- .to raise_error(Projects::UpdatePagesService::FailedToExtractError)
- end
- end
-
- context 'when using pages with non-writeable public' do
- let(:file) { fixture_file_upload("spec/fixtures/pages_non_writeable.zip") }
-
- context 'when using RubyZip' do
- it 'succeeds to extract' do
- expect(execute).to eq(:success)
- expect(project.pages_metadatum).to be_deployed
- end
- end
- end
-
context 'when timeout happens by DNS error' do
before do
allow_next_instance_of(described_class) do |instance|
- allow(instance).to receive(:extract_zip_archive!).and_raise(SocketError)
+ allow(instance).to receive(:create_pages_deployment).and_raise(SocketError)
end
end
@@ -209,24 +121,6 @@ RSpec.describe Projects::UpdatePagesService do
end
end
- context 'when failed to extract zip artifacts' do
- before do
- expect_next_instance_of(described_class) do |instance|
- expect(instance).to receive(:extract_zip_archive!)
- .and_raise(Projects::UpdatePagesService::FailedToExtractError)
- end
- end
-
- it 'raises an error' do
- expect { execute }
- .to raise_error(Projects::UpdatePagesService::FailedToExtractError)
-
- build.reload
- expect(deploy_status).to be_failed
- expect(project.pages_metadatum).not_to be_deployed
- end
- end
-
context 'when missing artifacts metadata' do
before do
expect(build).to receive(:artifacts_metadata?).and_return(false)
@@ -338,12 +232,6 @@ RSpec.describe Projects::UpdatePagesService do
end
end
- it 'fails to remove project pages when no pages is deployed' do
- expect(PagesWorker).not_to receive(:perform_in)
- expect(project.pages_deployed?).to be_falsey
- project.destroy!
- end
-
it 'fails if no artifacts' do
expect(execute).not_to eq(:success)
end
@@ -384,38 +272,6 @@ RSpec.describe Projects::UpdatePagesService do
end
end
- context 'when file size is spoofed' do
- let(:metadata) { spy('metadata') }
-
- include_context 'pages zip with spoofed size'
-
- before do
- file = fixture_file_upload(fake_zip_path, 'pages.zip')
- metafile = fixture_file_upload('spec/fixtures/pages.zip.meta')
-
- create(:ci_job_artifact, :archive, file: file, job: build)
- create(:ci_job_artifact, :metadata, file: metafile, job: build)
-
- allow(build).to receive(:artifacts_metadata_entry).with('public/', recursive: true)
- .and_return(metadata)
- allow(metadata).to receive(:total_size).and_return(100)
-
- # to pass entries count check
- root_metadata = double('root metadata')
- allow(build).to receive(:artifacts_metadata_entry).with('', recursive: true)
- .and_return(root_metadata)
- allow(root_metadata).to receive_message_chain(:entries, :count).and_return(10)
- end
-
- it 'raises an error' do
- expect do
- subject.execute
- end.to raise_error(Projects::UpdatePagesService::FailedToExtractError,
- 'Entry public/index.html should be 1B but is larger when inflated')
- expect(deploy_status).to be_script_failure
- end
- end
-
context 'when retrying the job' do
let!(:older_deploy_job) do
create(:generic_commit_status, :failed, pipeline: pipeline,
@@ -435,18 +291,6 @@ RSpec.describe Projects::UpdatePagesService do
expect(older_deploy_job.reload).to be_retried
end
-
- context 'when FF ci_fix_commit_status_retried is disabled' do
- before do
- stub_feature_flags(ci_fix_commit_status_retried: false)
- end
-
- it 'does not mark older pages:deploy jobs retried' do
- expect(execute).to eq(:success)
-
- expect(older_deploy_job.reload).not_to be_retried
- end
- end
end
private
diff --git a/spec/services/projects/update_service_spec.rb b/spec/services/projects/update_service_spec.rb
index c74a8295d0a..115f3098185 100644
--- a/spec/services/projects/update_service_spec.rb
+++ b/spec/services/projects/update_service_spec.rb
@@ -441,6 +441,30 @@ RSpec.describe Projects::UpdateService do
end
end
+ context 'when updating #shared_runners', :https_pages_enabled do
+ let!(:pending_build) { create(:ci_pending_build, project: project, instance_runners_enabled: true) }
+
+ subject(:call_service) do
+ update_project(project, admin, shared_runners_enabled: shared_runners_enabled)
+ end
+
+ context 'when shared runners is toggled' do
+ let(:shared_runners_enabled) { false }
+
+ it 'updates ci pending builds' do
+ expect { call_service }.to change { pending_build.reload.instance_runners_enabled }.to(false)
+ end
+ end
+
+ context 'when shared runners is not toggled' do
+ let(:shared_runners_enabled) { true }
+
+ it 'updates ci pending builds' do
+ expect { call_service }.to not_change { pending_build.reload.instance_runners_enabled }
+ end
+ end
+ end
+
context 'with external authorization enabled' do
before do
enable_external_authorization_service_check