INSTRUCTION
stringlengths
202
35.5k
RESPONSE
stringlengths
75
161k
Write RSpec test file for following ruby class ```ruby # frozen_string_literal: true module Ci module Components class FetchService include Gitlab::Utils::StrongMemoize COMPONENT_PATHS = [ ::Gitlab::Ci::Components::InstancePath ].freeze def initialize(address:, current_user:) ...
# frozen_string_literal: true require 'spec_helper' RSpec.describe Ci::Components::FetchService, feature_category: :pipeline_composition do let_it_be(:user) { create(:user) } let_it_be(:current_user) { user } let_it_be(:current_host) { Gitlab.config.gitlab.host } let_it_be(:content) do <<~COMPONENT jo...
Write RSpec test file for following ruby class ```ruby # frozen_string_literal: true module Ci module PrometheusMetrics class ObserveHistogramsService class << self def available_histograms @available_histograms ||= [ histogram(:pipeline_graph_link_calculation_duration_seconds...
# frozen_string_literal: true require 'spec_helper' RSpec.describe Ci::PrometheusMetrics::ObserveHistogramsService, feature_category: :continuous_integration do let_it_be(:project) { create(:project) } let(:params) { {} } subject(:execute) { described_class.new(project, params).execute } before do Gitl...
Write RSpec test file for following ruby class ```ruby # frozen_string_literal: true module Ci module Refs class EnqueuePipelinesToUnlockService include BaseServiceUtility BATCH_SIZE = 50 ENQUEUE_INTERVAL_SECONDS = 0.1 EXCLUDED_IDS_LIMIT = 1000 def execute(ci_ref, before_pipeline:...
# frozen_string_literal: true require 'spec_helper' RSpec.describe Ci::Refs::EnqueuePipelinesToUnlockService, :unlock_pipelines, :clean_gitlab_redis_shared_state, feature_category: :build_artifacts do describe '#execute' do let_it_be(:ref) { 'master' } let_it_be(:project) { create(:project) } let_it_be(...
Write RSpec test file for following ruby class ```ruby # frozen_string_literal: true module Ci module Queue class PendingBuildsStrategy attr_reader :runner def initialize(runner) @runner = runner end # rubocop:disable CodeReuse/ActiveRecord def builds_for_shared_runner ...
# frozen_string_literal: true require 'spec_helper' RSpec.describe Ci::Queue::PendingBuildsStrategy, feature_category: :continuous_integration do let_it_be(:group) { create(:group) } let_it_be(:group_runner) { create(:ci_runner, :group, groups: [group]) } let_it_be(:project) { create(:project, group: group) } ...
Write RSpec test file for following ruby class ```ruby # frozen_string_literal: true module Ci module Runners class UpdateRunnerService attr_reader :runner def initialize(runner) @runner = runner end def execute(params) params[:active] = !params.delete(:paused) if params...
# frozen_string_literal: true require 'spec_helper' RSpec.describe Ci::Runners::UpdateRunnerService, '#execute', feature_category: :runner_fleet do subject(:execute) { described_class.new(runner).execute(params) } let(:runner) { create(:ci_runner) } before do allow(runner).to receive(:tick_runner_queue) ...
Write RSpec test file for following ruby class ```ruby # frozen_string_literal: true module Ci module Runners class SetRunnerAssociatedProjectsService # @param [Ci::Runner] runner: the project runner to assign/unassign projects from # @param [User] current_user: the user performing the operation ...
# frozen_string_literal: true require 'spec_helper' RSpec.describe ::Ci::Runners::SetRunnerAssociatedProjectsService, '#execute', feature_category: :runner_fleet do subject(:execute) do described_class.new(runner: runner, current_user: user, project_ids: new_projects.map(&:id)).execute end let_it_be(:owner...
Write RSpec test file for following ruby class ```ruby # frozen_string_literal: true module Ci module Runners class BulkDeleteRunnersService attr_reader :runners RUNNER_LIMIT = 50 # @param runners [Array<Ci::Runner>] the runners to unregister/destroy # @param current_user [User] the use...
# frozen_string_literal: true require 'spec_helper' RSpec.describe ::Ci::Runners::BulkDeleteRunnersService, '#execute', feature_category: :runner_fleet do subject(:execute) { described_class.new(**service_args).execute } let_it_be(:admin_user) { create(:user, :admin) } let_it_be_with_refind(:owner_user) { crea...
Write RSpec test file for following ruby class ```ruby # frozen_string_literal: true module Ci module Runners class UnregisterRunnerManagerService attr_reader :runner, :author, :system_id # @param [Ci::Runner] runner the runner to unregister/destroy # @param [User, authentication token String]...
# frozen_string_literal: true require 'spec_helper' RSpec.describe ::Ci::Runners::UnregisterRunnerManagerService, '#execute', feature_category: :runner_fleet do subject(:execute) { described_class.new(runner, 'some_token', system_id: system_id).execute } context 'with runner registered with registration token' d...
Write RSpec test file for following ruby class ```ruby # frozen_string_literal: true module Ci module Runners class UnassignRunnerService # @param [Ci::RunnerProject] runner_project the runner/project association to destroy # @param [User] user the user performing the operation def initialize(r...
# frozen_string_literal: true require 'spec_helper' RSpec.describe ::Ci::Runners::UnassignRunnerService, '#execute', feature_category: :runner_fleet do let_it_be(:project) { create(:project) } let_it_be(:runner) { create(:ci_runner, :project, projects: [project]) } let(:runner_project) { runner.runner_projects...
Write RSpec test file for following ruby class ```ruby # frozen_string_literal: true module Ci module Runners class CreateRunnerService RUNNER_CLASS_MAPPING = { 'instance_type' => Ci::Runners::RunnerCreationStrategies::InstanceRunnerStrategy, 'group_type' => Ci::Runners::RunnerCreationStrat...
# frozen_string_literal: true require 'spec_helper' RSpec.describe ::Ci::Runners::CreateRunnerService, "#execute", feature_category: :runner_fleet do subject(:execute) { described_class.new(user: current_user, params: params).execute } let(:runner) { execute.payload[:runner] } let_it_be(:admin) { create(:admi...
Write RSpec test file for following ruby class ```ruby # frozen_string_literal: true module Ci module Runners class AssignRunnerService # @param [Ci::Runner] runner: the runner to assign to a project # @param [Project] project: the new project to assign the runner to # @param [User] user: the u...
# frozen_string_literal: true require 'spec_helper' RSpec.describe ::Ci::Runners::AssignRunnerService, '#execute', feature_category: :runner_fleet do subject(:execute) { described_class.new(runner, new_project, user).execute } let_it_be(:owner_group) { create(:group) } let_it_be(:owner_project) { create(:proje...
Write RSpec test file for following ruby class ```ruby # frozen_string_literal: true module Ci module Runners class ReconcileExistingRunnerVersionsService VERSION_BATCH_SIZE = 100 def execute insert_result = insert_runner_versions total_deleted = cleanup_runner_versions(insert_result...
# frozen_string_literal: true require 'spec_helper' RSpec.describe ::Ci::Runners::ReconcileExistingRunnerVersionsService, '#execute', feature_category: :runner_fleet do include RunnerReleasesHelper subject(:execute) { described_class.new.execute } let_it_be(:runner_14_0_1) { create(:ci_runner, version: '14.0....
Write RSpec test file for following ruby class ```ruby # frozen_string_literal: true module Ci module Runners class ResetRegistrationTokenService # @param [ApplicationSetting, Project, Group] scope: the scope of the reset operation # @param [User] user: the user performing the operation def ini...
# frozen_string_literal: true require 'spec_helper' RSpec.describe ::Ci::Runners::ResetRegistrationTokenService, '#execute', feature_category: :runner_fleet do subject(:execute) { described_class.new(scope, current_user).execute } let_it_be(:user) { build(:user) } let_it_be(:admin_user) { create(:user, :admin)...
Write RSpec test file for following ruby class ```ruby # frozen_string_literal: true module Ci module Runners class UnregisterRunnerService attr_reader :runner, :author # @param [Ci::Runner] runner the runner to unregister/destroy # @param [User, authentication token String] author the user or...
# frozen_string_literal: true require 'spec_helper' RSpec.describe ::Ci::Runners::UnregisterRunnerService, '#execute', feature_category: :runner_fleet do subject(:execute) { described_class.new(runner, 'some_token').execute } let(:runner) { create(:ci_runner) } it 'destroys runner' do expect(runner).to re...
Write RSpec test file for following ruby class ```ruby # frozen_string_literal: true module Ci module Runners class StaleManagersCleanupService MAX_DELETIONS = 1000 SUB_BATCH_LIMIT = 100 def execute ServiceResponse.success(payload: delete_stale_runner_managers) end private...
# frozen_string_literal: true require 'spec_helper' RSpec.describe Ci::Runners::StaleManagersCleanupService, feature_category: :runner_fleet do let(:service) { described_class.new } let!(:runner_manager3) { create(:ci_runner_machine, created_at: 6.months.ago, contacted_at: Time.current) } subject(:response) { ...
Write RSpec test file for following ruby class ```ruby # frozen_string_literal: true module Ci module Runners class RegisterRunnerService include Gitlab::Utils::StrongMemoize def initialize(registration_token, attributes) @registration_token = registration_token @attributes = attribu...
# frozen_string_literal: true require 'spec_helper' RSpec.describe ::Ci::Runners::RegisterRunnerService, '#execute', feature_category: :runner_fleet do let(:registration_token) { 'abcdefg123456' } let(:token) {} let(:args) { {} } let(:runner) { execute.payload[:runner] } let(:allow_runner_registration_token...
Write RSpec test file for following ruby class ```ruby # frozen_string_literal: true module Ci module Runners class ProcessRunnerVersionUpdateService def initialize(version) @version = version end def execute return ServiceResponse.error(message: 'version update disabled') unle...
# frozen_string_literal: true require 'spec_helper' RSpec.describe Ci::Runners::ProcessRunnerVersionUpdateService, feature_category: :runner_fleet do subject(:service) { described_class.new(version) } let(:version) { '1.0.0' } let(:available_runner_releases) { %w[1.0.0 1.0.1] } describe '#execute' do su...
Write RSpec test file for following ruby class ```ruby # frozen_string_literal: true module Ci module JobArtifacts class DeleteProjectArtifactsService < BaseProjectService def execute ExpireProjectBuildArtifactsWorker.perform_async(project.id) end end end end ```
# frozen_string_literal: true require 'spec_helper' RSpec.describe Ci::JobArtifacts::DeleteProjectArtifactsService, feature_category: :build_artifacts do let_it_be(:project) { create(:project) } subject { described_class.new(project: project) } describe '#execute' do it 'enqueues a Ci::ExpireProjectBuildA...
Write RSpec test file for following ruby class ```ruby # frozen_string_literal: true module Ci module JobArtifacts class TrackArtifactReportService include Gitlab::Utils::UsageData REPORT_TRACKED = %i[test coverage].freeze def execute(pipeline) REPORT_TRACKED.each do |report| ...
# frozen_string_literal: true require 'spec_helper' RSpec.describe Ci::JobArtifacts::TrackArtifactReportService, feature_category: :build_artifacts do describe '#execute', :clean_gitlab_redis_shared_state do let_it_be(:group) { create(:group, :private) } let_it_be(:project) { create(:project, group: group) ...
Write RSpec test file for following ruby class ```ruby # frozen_string_literal: true module Ci module JobArtifacts class DestroyBatchService include BaseServiceUtility include ::Gitlab::Utils::StrongMemoize # Danger: Private - Should only be called in Ci Services that pass a batch of job artif...
# frozen_string_literal: true require 'spec_helper' RSpec.describe Ci::JobArtifacts::DestroyBatchService, feature_category: :build_artifacts do let(:artifacts) { Ci::JobArtifact.where(id: [artifact_with_file.id, artifact_without_file.id]) } let(:skip_projects_on_refresh) { false } let(:service) do described...
Write RSpec test file for following ruby class ```ruby # frozen_string_literal: true module Ci module JobArtifacts # This class is used by Ci::JobArtifact's FastDestroyAll implementation. # Ci::JobArtifact.begin_fast_destroy instantiates this service and calls #destroy_records. # This will set @statistic...
# frozen_string_literal: true require 'spec_helper' RSpec.describe Ci::JobArtifacts::DestroyAssociationsService, feature_category: :build_artifacts do let_it_be(:project_1) { create(:project) } let_it_be(:project_2) { create(:project) } let_it_be(:artifact_1, refind: true) { create(:ci_job_artifact, :zip, proj...
Write RSpec test file for following ruby class ```ruby # frozen_string_literal: true module Ci module JobArtifacts class DestroyAllExpiredService include ::Gitlab::ExclusiveLeaseHelpers include ::Gitlab::LoopHelpers BATCH_SIZE = 100 LOOP_LIMIT = 500 LOOP_TIMEOUT = 5.minutes L...
# frozen_string_literal: true require 'spec_helper' RSpec.describe Ci::JobArtifacts::DestroyAllExpiredService, :clean_gitlab_redis_shared_state, feature_category: :build_artifacts do include ExclusiveLeaseHelpers let(:service) { described_class.new } describe '.execute' do subject { service.execute } ...
Write RSpec test file for following ruby class ```ruby # frozen_string_literal: true module Ci module JobArtifacts class UpdateUnknownLockedStatusService include ::Gitlab::ExclusiveLeaseHelpers include ::Gitlab::LoopHelpers BATCH_SIZE = 100 LOOP_TIMEOUT = 5.minutes LOOP_LIMIT = 100...
# frozen_string_literal: true require 'spec_helper' RSpec.describe Ci::JobArtifacts::UpdateUnknownLockedStatusService, :clean_gitlab_redis_shared_state, feature_category: :build_artifacts do include ExclusiveLeaseHelpers let(:service) { described_class.new } describe '.execute' do subject { service.exec...
Write RSpec test file for following ruby class ```ruby # frozen_string_literal: true module Ci module JobArtifacts class BulkDeleteByProjectService include BaseServiceUtility JOB_ARTIFACTS_COUNT_LIMIT = 50 def initialize(job_artifact_ids:, project:, current_user:) @job_artifact_ids = ...
# frozen_string_literal: true require 'spec_helper' RSpec.describe ::Ci::JobArtifacts::BulkDeleteByProjectService, "#execute", feature_category: :build_artifacts do subject(:execute) do described_class.new( job_artifact_ids: job_artifact_ids, current_user: current_user, project: project).execu...
Write RSpec test file for following ruby class ```ruby # frozen_string_literal: true module Ci module JobArtifacts class CreateService < ::BaseService include Gitlab::Utils::UsageData LSIF_ARTIFACT_TYPE = 'lsif' OBJECT_STORAGE_ERRORS = [ Errno::EIO, Google::Apis::ServerError, ...
# frozen_string_literal: true require 'spec_helper' RSpec.describe Ci::JobArtifacts::CreateService, :clean_gitlab_redis_shared_state, feature_category: :build_artifacts do include WorkhorseHelpers include Gitlab::Utils::Gzip let_it_be(:project) { create(:project) } let(:service) { described_class.new(job) }...
Write RSpec test file for following ruby class ```ruby # frozen_string_literal: true module Ci module JobArtifacts class DeleteService include BaseServiceUtility def initialize(build) @build = build end def execute if build.project.refreshing_build_artifacts_size? ...
# frozen_string_literal: true require 'spec_helper' RSpec.describe Ci::JobArtifacts::DeleteService, feature_category: :build_artifacts do let_it_be(:build, reload: true) do create(:ci_build, :artifacts, :trace_artifact, artifacts_expire_at: 100.days.from_now) end subject(:service) { described_class.new(bui...
Write RSpec test file for following ruby class ```ruby # frozen_string_literal: true module Ci module JobArtifacts class ExpireProjectBuildArtifactsService BATCH_SIZE = 1000 def initialize(project_id, expiry_time) @project_id = project_id @expiry_time = expiry_time end #...
# frozen_string_literal: true require 'spec_helper' RSpec.describe Ci::JobArtifacts::ExpireProjectBuildArtifactsService, feature_category: :build_artifacts do let_it_be(:project) { create(:project) } let_it_be(:pipeline, reload: true) { create(:ci_pipeline, :unlocked, project: project) } let(:expiry_time) { Ti...
Write RSpec test file for following ruby class ```ruby # frozen_string_literal: true module Ci module PipelineSchedules class CalculateNextRunService < BaseService include Gitlab::Utils::StrongMemoize def execute(schedule, fallback_method:) @schedule = schedule return fallback_metho...
# frozen_string_literal: true # rubocop:disable Layout/LineLength require 'spec_helper' RSpec.describe Ci::PipelineSchedules::CalculateNextRunService, feature_category: :continuous_integration do let_it_be(:project) { create(:project, :public, :repository) } describe '#execute' do using RSpec::Parameterized::...
Write RSpec test file for following ruby class ```ruby # frozen_string_literal: true module Ci module PipelineSchedules class TakeOwnershipService def initialize(schedule, user) @schedule = schedule @user = user end def execute return forbidden unless allowed? ...
# frozen_string_literal: true require 'spec_helper' RSpec.describe Ci::PipelineSchedules::TakeOwnershipService, feature_category: :continuous_integration do let_it_be(:user) { create(:user) } let_it_be(:owner) { create(:user) } let_it_be(:reporter) { create(:user) } let_it_be(:project) { create(:project, :pub...
Write RSpec test file for following ruby class ```ruby # frozen_string_literal: true module Ci module PipelineSchedules class UpdateService < BaseSaveService AUTHORIZE = :update_pipeline_schedule def initialize(schedule, user, params) @schedule = schedule @user = user @projec...
# frozen_string_literal: true require 'spec_helper' RSpec.describe Ci::PipelineSchedules::UpdateService, feature_category: :continuous_integration do let_it_be_with_reload(:user) { create(:user) } let_it_be_with_reload(:project) { create(:project, :public, :repository) } let_it_be_with_reload(:pipeline_schedule...
Write RSpec test file for following ruby class ```ruby # frozen_string_literal: true module Ci module PipelineSchedules class CreateService < BaseSaveService AUTHORIZE = :create_pipeline_schedule def initialize(project, user, params) @schedule = project.pipeline_schedules.new @user =...
# frozen_string_literal: true require 'spec_helper' RSpec.describe Ci::PipelineSchedules::CreateService, feature_category: :continuous_integration do let_it_be(:reporter) { create(:user) } let_it_be_with_reload(:user) { create(:user) } let_it_be_with_reload(:project) { create(:project, :public, :repository) } ...
Write RSpec test file for following ruby class ```ruby # frozen_string_literal: true module Ci module PipelineCreation class CancelRedundantPipelinesService include Gitlab::Utils::StrongMemoize BATCH_SIZE = 25 PAGE_SIZE = 500 def initialize(pipeline) @pipeline = pipeline ...
# frozen_string_literal: true require 'spec_helper' RSpec.describe Ci::PipelineCreation::CancelRedundantPipelinesService, feature_category: :continuous_integration do let_it_be(:project) { create(:project) } let_it_be(:user) { create(:user) } let(:prev_pipeline) { create(:ci_pipeline, project: project) } let...
Write RSpec test file for following ruby class ```ruby # frozen_string_literal: true module Ci module PipelineCreation class StartPipelineService attr_reader :pipeline def initialize(pipeline) @pipeline = pipeline end def execute ## # Create a persistent ref for ...
# frozen_string_literal: true require 'spec_helper' RSpec.describe Ci::PipelineCreation::StartPipelineService, feature_category: :continuous_integration do let(:pipeline) { build(:ci_pipeline) } subject(:service) { described_class.new(pipeline) } describe '#execute' do it 'calls the pipeline process servi...
Write RSpec test file for following ruby class ```ruby # frozen_string_literal: true module Ci module Deployments class DestroyService < BaseService def execute(deployment) raise Gitlab::Access::AccessDeniedError unless can?(current_user, :destroy_deployment, deployment) return ServiceResp...
# frozen_string_literal: true require 'spec_helper' RSpec.describe ::Ci::Deployments::DestroyService, feature_category: :continuous_integration do let_it_be(:project) { create(:project, :repository) } let(:environment) { create(:environment, project: project) } let(:commits) { project.repository.commits(nil, {...
Write RSpec test file for following ruby class ```ruby # frozen_string_literal: true module Environments class ResetAutoStopService < ::BaseService def execute(environment) return error(_('Failed to cancel auto stop because you do not have permission to update the environment.')) unless can_update_environm...
# frozen_string_literal: true require 'spec_helper' RSpec.describe Environments::ResetAutoStopService, feature_category: :continuous_delivery do let_it_be(:project) { create(:project) } let_it_be(:developer) { create(:user).tap { |user| project.add_developer(user) } } let_it_be(:reporter) { create(:user).tap { ...
Write RSpec test file for following ruby class ```ruby # frozen_string_literal: true module Environments class ScheduleToDeleteReviewAppsService < ::BaseService include ::Gitlab::ExclusiveLeaseHelpers EXCLUSIVE_LOCK_KEY_BASE = 'environments:delete_review_apps:lock' LOCK_TIMEOUT = 2.minutes def exec...
# frozen_string_literal: true require "spec_helper" RSpec.describe Environments::ScheduleToDeleteReviewAppsService, feature_category: :continuous_delivery do include ExclusiveLeaseHelpers let_it_be(:maintainer) { create(:user) } let_it_be(:developer) { create(:user) } let_it_be(:reporter) { create(:user) ...
Write RSpec test file for following ruby class ```ruby # frozen_string_literal: true module Environments # This class creates an environment record for a pipeline job. class CreateForJobService def execute(job) return unless job.is_a?(::Ci::Processable) && job.has_environment_keyword? environment ...
# frozen_string_literal: true require 'spec_helper' RSpec.describe Environments::CreateForJobService, feature_category: :continuous_delivery do let_it_be(:project) { create(:project, :repository) } let_it_be(:user) { create(:user) } let_it_be(:pipeline) { create(:ci_pipeline, project: project) } let(:service...
Write RSpec test file for following ruby class ```ruby # frozen_string_literal: true module Environments class AutoStopService include ::Gitlab::ExclusiveLeaseHelpers include ::Gitlab::LoopHelpers BATCH_SIZE = 100 LOOP_TIMEOUT = 45.minutes LOOP_LIMIT = 1000 EXCLUSIVE_LOCK_KEY = 'environments...
# frozen_string_literal: true require 'spec_helper' RSpec.describe Environments::AutoStopService, :clean_gitlab_redis_shared_state, :sidekiq_inline, feature_category: :continuous_delivery do include CreateEnvironmentsHelpers include ExclusiveLeaseHelpers let_it_be(:project) { create(:project, :repository) } ...
Write RSpec test file for following ruby class ```ruby # frozen_string_literal: true module Environments class StopService < BaseService attr_reader :ref def execute(environment) unless can?(current_user, :stop_environment, environment) return ServiceResponse.error( message: 'Unautho...
# frozen_string_literal: true require 'spec_helper' RSpec.describe Environments::StopService, feature_category: :continuous_delivery do include CreateEnvironmentsHelpers let(:project) { create(:project, :private, :repository) } let(:user) { create(:user) } let(:service) { described_class.new(project, user) ...
Write RSpec test file for following ruby class ```ruby # frozen_string_literal: true module Environments class AutoRecoverService include ::Gitlab::ExclusiveLeaseHelpers include ::Gitlab::LoopHelpers BATCH_SIZE = 100 LOOP_TIMEOUT = 45.minutes LOOP_LIMIT = 1000 EXCLUSIVE_LOCK_KEY = 'environme...
# frozen_string_literal: true require 'spec_helper' RSpec.describe Environments::AutoRecoverService, :clean_gitlab_redis_shared_state, :sidekiq_inline, feature_category: :continuous_delivery do include CreateEnvironmentsHelpers include ExclusiveLeaseHelpers let_it_be(:project) { create(:project, :repository)...
Write RSpec test file for following ruby class ```ruby # frozen_string_literal: true module Environments class DestroyService < BaseService def execute(environment) unless can?(current_user, :destroy_environment, environment) return ServiceResponse.error( message: 'Unauthorized to delete ...
# frozen_string_literal: true require 'spec_helper' RSpec.describe Environments::DestroyService, feature_category: :continuous_delivery do include CreateEnvironmentsHelpers let_it_be(:project) { create(:project, :private, :repository) } let_it_be(:user) { create(:user) } let(:service) { described_class.new(...
Write RSpec test file for following ruby class ```ruby # frozen_string_literal: true module Environments class UpdateService < BaseService ALLOWED_ATTRIBUTES = %i[external_url tier cluster_agent kubernetes_namespace flux_resource_path].freeze def execute(environment) unless can?(current_user, :update_...
# frozen_string_literal: true require 'spec_helper' RSpec.describe Environments::UpdateService, feature_category: :environment_management do let_it_be(:project) { create(:project, :repository) } let_it_be(:developer) { create(:user).tap { |u| project.add_developer(u) } } let_it_be(:reporter) { create(:user).tap...
Write RSpec test file for following ruby class ```ruby # frozen_string_literal: true module Environments class CreateService < BaseService ALLOWED_ATTRIBUTES = %i[name external_url tier cluster_agent kubernetes_namespace flux_resource_path].freeze def execute unless can?(current_user, :create_environm...
# frozen_string_literal: true require 'spec_helper' RSpec.describe Environments::CreateService, feature_category: :environment_management do let_it_be(:project) { create(:project, :repository) } let_it_be(:developer) { create(:user).tap { |u| project.add_developer(u) } } let_it_be(:reporter) { create(:user).tap...
Write RSpec test file for following ruby class ```ruby # frozen_string_literal: true module Environments class StopStaleService < BaseService def execute return ServiceResponse.error(message: 'Before date must be provided') unless params[:before].present? return ServiceResponse.error(message: 'Unaut...
# frozen_string_literal: true require 'spec_helper' RSpec.describe Environments::StopStaleService, :clean_gitlab_redis_shared_state, :sidekiq_inline, feature_category: :continuous_delivery do let_it_be(:project) { create(:project, :repository) } let_it_be(:user) { create(:user) } let(:params) { { after: ...
Write RSpec test file for following ruby class ```ruby # frozen_string_literal: true module Environments module CanaryIngress class UpdateService < ::BaseService def execute_async(environment) result = validate(environment) return result unless result[:status] == :success Environm...
# frozen_string_literal: true require 'spec_helper' RSpec.describe Environments::CanaryIngress::UpdateService, :clean_gitlab_redis_cache, feature_category: :continuous_delivery do include KubernetesHelpers let_it_be(:project, refind: true) { create(:project) } let_it_be(:maintainer) { create(:user) } let_i...
Write RSpec test file for following ruby class ```ruby # frozen_string_literal: true module Projects class ImportService < BaseService Error = Class.new(StandardError) PermissionError = Class.new(StandardError) # Returns true if this importer is supposed to perform its work in the # background. ...
# frozen_string_literal: true require 'spec_helper' RSpec.describe Projects::ImportService, feature_category: :importers do let!(:project) { create(:project) } let(:user) { project.creator } subject { described_class.new(project, user) } before do allow(project).to receive(:lfs_enabled?).and_return(true...
Write RSpec test file for following ruby class ```ruby # frozen_string_literal: true module Projects # Service class for counting and caching the number of open merge requests of # a project. class OpenMergeRequestsCountService < Projects::CountService def cache_key_name 'open_merge_requests_count' ...
# frozen_string_literal: true require 'spec_helper' RSpec.describe Projects::OpenMergeRequestsCountService, :use_clean_rails_memory_store_caching, feature_category: :code_review_workflow do let_it_be(:project) { create(:project) } subject { described_class.new(project) } it_behaves_like 'a counter caching ser...
Write RSpec test file for following ruby class ```ruby # frozen_string_literal: true module Projects # Service class that can be used to execute actions necessary after creating a # default branch. class ProtectDefaultBranchService attr_reader :project, :default_branch_protection # @param [Project] proj...
# frozen_string_literal: true require 'spec_helper' RSpec.describe Projects::ProtectDefaultBranchService, feature_category: :source_code_management do let(:service) { described_class.new(project) } let(:project) { create(:project) } describe '#execute' do before do allow(service) .to receive(...
Write RSpec test file for following ruby class ```ruby # frozen_string_literal: true module Projects class UpdateRepositoryStorageService include UpdateRepositoryStorageMethods delegate :project, to: :repository_storage_move private def track_repository(destination_storage_name) project.upda...
# frozen_string_literal: true require 'spec_helper' RSpec.describe Projects::UpdateRepositoryStorageService, feature_category: :source_code_management do include Gitlab::ShellAdapter subject { described_class.new(repository_storage_move) } describe "#execute" do let(:time) { Time.current } before do ...
Write RSpec test file for following ruby class ```ruby # frozen_string_literal: true module Projects class FetchStatisticsIncrementService attr_reader :project def initialize(project) @project = project end def execute increment_fetch_count_sql = <<~SQL INSERT INTO #{table_name}...
# frozen_string_literal: true require 'spec_helper' module Projects RSpec.describe FetchStatisticsIncrementService, feature_category: :groups_and_projects do let(:project) { create(:project) } describe '#execute' do subject { described_class.new(project).execute } it 'creates a new record for ...
Write RSpec test file for following ruby class ```ruby # frozen_string_literal: true module Projects class UpdatePagesService < BaseService include Gitlab::Utils::StrongMemoize # old deployment can be cached by pages daemon # so we need to give pages daemon some time update cache # 10 minutes is eno...
# frozen_string_literal: true require "spec_helper" RSpec.describe Projects::UpdatePagesService, feature_category: :pages do let_it_be(:project, refind: true) { create(:project, :repository) } let_it_be(:old_pipeline) { create(:ci_pipeline, project: project, sha: project.commit('HEAD').sha) } let_it_be(:pipeli...
Write RSpec test file for following ruby class ```ruby # frozen_string_literal: true # NOTE: This service cannot be used directly because it is part of a # a bigger process. Instead, use the service MoveAccessService which moves # project memberships, project group links, authorizations and refreshes # the authorizati...
# frozen_string_literal: true require 'spec_helper' RSpec.describe Projects::MoveProjectMembersService, feature_category: :groups_and_projects do let!(:user) { create(:user) } let(:project_with_users) { create(:project, namespace: user.namespace) } let(:target_project) { create(:project, namespace: user.namespa...
Write RSpec test file for following ruby class ```ruby # frozen_string_literal: true # Service class for getting and caching the number of merge requests of several projects # Warning: do not user this service with a really large set of projects # because the service use maps to retrieve the project ids module Project...
# frozen_string_literal: true require 'spec_helper' RSpec.describe Projects::BatchOpenMergeRequestsCountService, feature_category: :code_review_workflow do subject { described_class.new([project_1, project_2]) } let_it_be(:project_1) { create(:project) } let_it_be(:project_2) { create(:project) } describe '...
Write RSpec test file for following ruby class ```ruby # frozen_string_literal: true module Projects class SlackApplicationInstallService < BaseService include Gitlab::Routing # Endpoint to initiate the OAuth flow, redirects to Slack's authorization screen # https://api.slack.com/authentication/oauth-v2...
# frozen_string_literal: true require 'spec_helper' RSpec.describe Projects::SlackApplicationInstallService, feature_category: :integrations do let_it_be(:user) { create(:user) } let_it_be_with_refind(:project) { create(:project) } let(:integration) { project.gitlab_slack_application_integration } let(:insta...
Write RSpec test file for following ruby class ```ruby # frozen_string_literal: true module Projects # Service class for performing operations that should take place after a # project has been renamed. # # Example usage: # # project = Project.find(42) # # project.update(...) # # Project...
# frozen_string_literal: true require 'spec_helper' RSpec.describe Projects::AfterRenameService, feature_category: :groups_and_projects do let(:legacy_storage) { Storage::LegacyProject.new(project) } let(:hashed_storage) { Storage::Hashed.new(project) } let!(:path_before_rename) { project.path } let!(:full_pa...
Write RSpec test file for following ruby class ```ruby # frozen_string_literal: true module Projects class MoveForksService < BaseMoveRelationsService def execute(source_project, remove_remaining_elements: true) return unless super && source_project.fork_network Project.transaction do move_f...
# frozen_string_literal: true require 'spec_helper' RSpec.describe Projects::MoveForksService, feature_category: :source_code_management do include ProjectForksHelper let!(:user) { create(:user) } let!(:project_with_forks) { create(:project, namespace: user.namespace) } let!(:target_project) { create(:projec...
Write RSpec test file for following ruby class ```ruby # frozen_string_literal: true module Projects class MoveUsersStarProjectsService < BaseMoveRelationsService def execute(source_project, remove_remaining_elements: true) return unless super user_stars = source_project.users_star_projects r...
# frozen_string_literal: true require 'spec_helper' RSpec.describe Projects::MoveUsersStarProjectsService, feature_category: :groups_and_projects do let!(:user) { create(:user) } let!(:project_with_stars) { create(:project, namespace: user.namespace) } let!(:target_project) { create(:project, namespace: user.na...
Write RSpec test file for following ruby class ```ruby # frozen_string_literal: true module Projects class AutocompleteService < BaseService include LabelsAsHash def issues IssuesFinder.new(current_user, project_id: project.id, state: 'opened').execute.select([:iid, :title]) end def milestones...
# frozen_string_literal: true require 'spec_helper' RSpec.describe Projects::AutocompleteService, feature_category: :groups_and_projects do describe '#issues' do describe 'confidential issues' do let(:author) { create(:user) } let(:assignee) { create(:user) } let(:non_member) { create(:user) }...
Write RSpec test file for following ruby class ```ruby # frozen_string_literal: true # Projects::BranchesByModeService uses Gitaly page-token pagination # in order to optimally fetch branches. # The drawback of the page-token pagination is that it doesn't provide # an option of going to the previous page of the collec...
# frozen_string_literal: true require 'spec_helper' RSpec.describe Projects::BranchesByModeService, feature_category: :source_code_management do let_it_be(:user) { create(:user) } let_it_be(:project) { create(:project, :repository) } let(:finder) { described_class.new(project, params) } let(:params) { { mode...
Write RSpec test file for following ruby class ```ruby # frozen_string_literal: true # This service is an adapter used to for the GitLab Import feature, and # creating a project from a template. # The latter will under the hood just import an archive supplied by GitLab. module Projects class GitlabProjectsImportServ...
# frozen_string_literal: true require 'spec_helper' RSpec.describe Projects::GitlabProjectsImportService, feature_category: :importers do let_it_be(:namespace) { create(:namespace) } let(:path) { 'test-path' } let(:file) { fixture_file_upload('spec/fixtures/project_export.tar.gz') } let(:overwrite) { false }...
Write RSpec test file for following ruby class ```ruby # frozen_string_literal: true module Projects # Service class for counting and caching the number of all merge requests of # a project. class AllMergeRequestsCountService < Projects::CountService def relation_for_count @project.merge_requests e...
# frozen_string_literal: true require 'spec_helper' RSpec.describe Projects::AllMergeRequestsCountService, :use_clean_rails_memory_store_caching, feature_category: :groups_and_projects do let_it_be(:project) { create(:project) } subject { described_class.new(project) } it_behaves_like 'a counter caching servi...
Write RSpec test file for following ruby class ```ruby # frozen_string_literal: true module Projects # Service class for counting and caching the number of all issues of a # project. class AllIssuesCountService < Projects::CountService def relation_for_count @project.issues end def cache_key_n...
# frozen_string_literal: true require 'spec_helper' RSpec.describe Projects::AllIssuesCountService, :use_clean_rails_memory_store_caching, feature_category: :groups_and_projects do let_it_be(:group) { create(:group, :public) } let_it_be(:project) { create(:project, :public, namespace: group) } let_it_be(:banned...
Write RSpec test file for following ruby class ```ruby # frozen_string_literal: true module Projects class ParticipantsService < BaseService include Users::ParticipableService def execute(noteable) @noteable = noteable participants = noteable_owner + participants_in_noteable + ...
# frozen_string_literal: true require 'spec_helper' RSpec.describe Projects::ParticipantsService, feature_category: :groups_and_projects do describe '#execute' do let_it_be(:user) { create(:user) } let_it_be(:project) { create(:project, :public) } let_it_be(:noteable) { create(:issue, project: project) ...
Write RSpec test file for following ruby class ```ruby # frozen_string_literal: true module Projects class MoveNotificationSettingsService < BaseMoveRelationsService def execute(source_project, remove_remaining_elements: true) return unless super Project.transaction do move_notification_sett...
# frozen_string_literal: true require 'spec_helper' RSpec.describe Projects::MoveNotificationSettingsService, feature_category: :groups_and_projects do let(:user) { create(:user) } let(:project_with_notifications) { create(:project, namespace: user.namespace) } let(:target_project) { create(:project, namespace:...
Write RSpec test file for following ruby class ```ruby # frozen_string_literal: true module Projects class OverwriteProjectService < BaseService def execute(source_project) return unless source_project && source_project.namespace_id == @project.namespace_id start_time = ::Gitlab::Metrics::System.mon...
# frozen_string_literal: true require 'spec_helper' RSpec.describe Projects::OverwriteProjectService, feature_category: :groups_and_projects do include ProjectForksHelper let(:user) { create(:user) } let(:project_from) { create(:project, namespace: user.namespace) } let(:project_to) { create(:project, namesp...
Write RSpec test file for following ruby class ```ruby # frozen_string_literal: true module Projects class CreateFromTemplateService < BaseService include Gitlab::Utils::StrongMemoize attr_reader :template_name def initialize(user, params) @current_user = user @params = params.to_h.dup ...
# frozen_string_literal: true require 'spec_helper' RSpec.describe Projects::CreateFromTemplateService, feature_category: :groups_and_projects do let(:user) { create(:user) } let(:template_name) { 'rails' } let(:project_params) do { path: user.to_param, template_name: template_name, ...
Write RSpec test file for following ruby class ```ruby # frozen_string_literal: true module Projects class DownloadService < BaseService ALLOWLIST = [ /^[^.]+\.fogbugz.com$/ ].freeze def initialize(project, url) @project = project @url = url end def execute return unless...
# frozen_string_literal: true require 'spec_helper' RSpec.describe Projects::DownloadService, feature_category: :groups_and_projects do describe 'File service' do before do @user = create(:user) @project = create(:project, creator_id: @user.id, namespace: @user.namespace) end context 'for a...
Write RSpec test file for following ruby class ```ruby # frozen_string_literal: true module Projects class RepositoryLanguagesService < BaseService def execute perform_language_detection unless project.detected_repository_languages? persisted_repository_languages end private def perform...
# frozen_string_literal: true require 'spec_helper' RSpec.describe Projects::RepositoryLanguagesService, feature_category: :source_code_management do let(:service) { described_class.new(project, project.first_owner) } context 'when detected_repository_languages flag is set' do let(:project) { create(:project...
Write RSpec test file for following ruby class ```ruby # frozen_string_literal: true # Projects::TransferService class # # Used to transfer a project to another namespace # # Ex. # # Move project to namespace by user # Projects::TransferService.new(project, user).execute(namespace) # module Projects class Transf...
# frozen_string_literal: true require 'spec_helper' RSpec.describe Projects::TransferService, feature_category: :groups_and_projects do let_it_be(:group) { create(:group) } let_it_be(:user) { create(:user) } let_it_be(:group_integration) { create(:integrations_slack, :group, group: group, webhook: 'http://group...
Write RSpec test file for following ruby class ```ruby # frozen_string_literal: true module Projects class RefreshBuildArtifactsSizeStatisticsService BATCH_SIZE = 500 REFRESH_INTERVAL_SECONDS = 0.1 def execute refresh = Projects::BuildArtifactsSizeRefresh.process_next_refresh! return unless...
# frozen_string_literal: true require 'spec_helper' RSpec.describe Projects::RefreshBuildArtifactsSizeStatisticsService, :clean_gitlab_redis_shared_state, feature_category: :build_artifacts do let(:service) { described_class.new } describe '#execute' do let_it_be(:project, reload: true) { create(:project) } ...
Write RSpec test file for following ruby class ```ruby # frozen_string_literal: true module Projects class ForkService < BaseService def execute(fork_to_project = nil) forked_project = fork_to_project ? link_existing_project(fork_to_project) : fork_new_project if forked_project&.saved? refre...
# frozen_string_literal: true require 'spec_helper' RSpec.describe Projects::ForkService, feature_category: :source_code_management do include ProjectForksHelper shared_examples 'forks count cache refresh' do it 'flushes the forks count cache of the source project', :clean_gitlab_redis_cache do expect(...
Write RSpec test file for following ruby class ```ruby # frozen_string_literal: true module Projects class UnlinkForkService < BaseService # Close existing MRs coming from the project and remove it from the fork network def execute(refresh_statistics: true) fork_network = @project.fork_network fo...
# frozen_string_literal: true require 'spec_helper' RSpec.describe Projects::UnlinkForkService, :use_clean_rails_memory_store_caching, feature_category: :source_code_management do include ProjectForksHelper subject { described_class.new(forked_project, user) } let(:project) { create(:project, :public) } let...
Write RSpec test file for following ruby class ```ruby # frozen_string_literal: true module Projects # Service class for getting and caching the number of forks of a project. class ForksCountService < Projects::CountService def cache_key_name 'forks_count' end # rubocop: disable CodeReuse/Active...
# frozen_string_literal: true require 'spec_helper' RSpec.describe Projects::ForksCountService, :use_clean_rails_memory_store_caching, feature_category: :source_code_management do let(:project) { build(:project) } subject { described_class.new(project) } it_behaves_like 'a counter caching service' describe...
Write RSpec test file for following ruby class ```ruby # frozen_string_literal: true module Projects # The CleanupService removes data from the project repository following a # BFG rewrite: https://rtyley.github.io/bfg-repo-cleaner/ # # Before executing this service, all refs rewritten by BFG should have been ...
# frozen_string_literal: true require 'spec_helper' RSpec.describe Projects::CleanupService, feature_category: :source_code_management do subject(:service) { described_class.new(project) } describe '.enqueue' do let_it_be(:project) { create(:project, :repository) } let_it_be(:user) { create(:user) } ...
Write RSpec test file for following ruby class ```ruby # frozen_string_literal: true module Projects class UpdateRemoteMirrorService < BaseService include Gitlab::Utils::StrongMemoize MAX_TRIES = 3 def execute(remote_mirror, tries) return success unless remote_mirror.enabled? # Blocked URL...
# frozen_string_literal: true require 'spec_helper' RSpec.describe Projects::UpdateRemoteMirrorService, feature_category: :source_code_management do let_it_be(:project) { create(:project, :repository, lfs_enabled: true) } let_it_be(:remote_project) { create(:forked_project_with_submodules) } let_it_be(:remote_m...
Write RSpec test file for following ruby class ```ruby # frozen_string_literal: true module Projects class MoveAccessService < BaseMoveRelationsService def execute(source_project, remove_remaining_elements: true) return unless super @project.with_transaction_returning_status do if @project.n...
# frozen_string_literal: true require 'spec_helper' RSpec.describe Projects::MoveAccessService, feature_category: :groups_and_projects do let(:user) { create(:user) } let(:group) { create(:group) } let(:project_with_access) { create(:project, namespace: user.namespace) } let(:maintainer_user) { create(:user) ...
Write RSpec test file for following ruby class ```ruby # frozen_string_literal: true # NOTE: This service cannot be used directly because it is part of a # a bigger process. Instead, use the service MoveAccessService which moves # project memberships, project group links, authorizations and refreshes # the authorizati...
# frozen_string_literal: true require 'spec_helper' RSpec.describe Projects::MoveProjectAuthorizationsService, feature_category: :groups_and_projects do let!(:user) { create(:user) } let(:project_with_users) { create(:project, namespace: user.namespace) } let(:target_project) { create(:project, namespace: user....
Write RSpec test file for following ruby class ```ruby # frozen_string_literal: true module Projects # Tries to schedule a move for every project with repositories on the source shard class ScheduleBulkRepositoryShardMovesService include ScheduleBulkRepositoryShardMovesMethods extend ::Gitlab::Utils::Overr...
# frozen_string_literal: true require 'spec_helper' RSpec.describe Projects::ScheduleBulkRepositoryShardMovesService, feature_category: :source_code_management do it_behaves_like 'moves repository shard in bulk' do let_it_be_with_reload(:container) { create(:project, :repository) } let(:move_service_klass)...
Write RSpec test file for following ruby class ```ruby # frozen_string_literal: true module Projects class ReadmeRendererService < BaseService include Rails.application.routes.url_helpers TEMPLATE_PATH = Rails.root.join('app', 'views', 'projects', 'readme_templates') def execute render(params[:te...
# frozen_string_literal: true require 'spec_helper' RSpec.describe Projects::ReadmeRendererService, '#execute', feature_category: :groups_and_projects do using RSpec::Parameterized::TableSyntax subject(:service) { described_class.new(project, nil, opts) } let_it_be(:project) { create(:project, title: 'My Proj...
Write RSpec test file for following ruby class ```ruby # frozen_string_literal: true module Projects class DestroyService < BaseService include Gitlab::ShellAdapter DestroyError = Class.new(StandardError) BATCH_SIZE = 100 def async_execute project.update_attribute(:pending_delete, true) ...
# frozen_string_literal: true require 'spec_helper' RSpec.describe Projects::DestroyService, :aggregate_failures, :event_store_publisher, feature_category: :groups_and_projects do include ProjectForksHelper include BatchDestroyDependentAssociationsHelper let_it_be(:user) { create(:user) } let!(:project) { c...
Write RSpec test file for following ruby class ```ruby # frozen_string_literal: true # NOTE: This service cannot be used directly because it is part of a # a bigger process. Instead, use the service MoveAccessService which moves # project memberships, project group links, authorizations and refreshes # the authorizati...
# frozen_string_literal: true require 'spec_helper' RSpec.describe Projects::MoveProjectGroupLinksService, feature_category: :groups_and_projects do let!(:user) { create(:user) } let(:project_with_groups) { create(:project, namespace: user.namespace) } let(:target_project) { create(:project, namespace: user.nam...
Write RSpec test file for following ruby class ```ruby # frozen_string_literal: true module Projects class UpdateService < BaseService include UpdateVisibilityLevel include ValidatesClassificationLabel ValidationError = Class.new(StandardError) def execute build_topics remove_unallowed_...
# frozen_string_literal: true require 'spec_helper' RSpec.describe Projects::UpdateService, feature_category: :groups_and_projects do include ExternalAuthorizationServiceHelpers include ProjectForksHelper let(:user) { create(:user) } let(:project) do create(:project, creator: user, namespace: user.namespa...
Write RSpec test file for following ruby class ```ruby # frozen_string_literal: true module Projects class EnableDeployKeyService < BaseService def execute key_id = params[:key_id] || params[:id] key = find_accessible_key(key_id) return unless key unless project.deploy_keys.include?(key...
# frozen_string_literal: true require 'spec_helper' RSpec.describe Projects::EnableDeployKeyService, feature_category: :continuous_delivery do let(:deploy_key) { create(:deploy_key, public: true) } let(:project) { create(:project) } let(:user) { project.creator } let!(:params) { { key_id: depl...
Write RSpec test file for following ruby class ```ruby # frozen_string_literal: true module Projects class MoveLfsObjectsProjectsService < BaseMoveRelationsService def execute(source_project, remove_remaining_elements: true) return unless super Project.transaction do move_lfs_objects_project...
# frozen_string_literal: true require 'spec_helper' RSpec.describe Projects::MoveLfsObjectsProjectsService, feature_category: :source_code_management do let!(:user) { create(:user) } let!(:project_with_lfs_objects) { create(:project, namespace: user.namespace) } let!(:target_project) { create(:project, namespac...
Write RSpec test file for following ruby class ```ruby # frozen_string_literal: true module Projects # Service class to detect target platforms of a project made for the Apple # Ecosystem. # # This service searches project.pbxproj and *.xcconfig files (contains build # settings) for the string "SDKROOT = <SD...
# frozen_string_literal: true require 'spec_helper' RSpec.describe Projects::AppleTargetPlatformDetectorService, feature_category: :groups_and_projects do let_it_be(:project) { build(:project) } subject { described_class.new(project).execute } context 'when project is not an xcode project' do before do ...
Write RSpec test file for following ruby class ```ruby # frozen_string_literal: true module Projects class RecordTargetPlatformsService < BaseService include Gitlab::Utils::StrongMemoize def initialize(project, detector_service) @project = project @detector_service = detector_service end ...
# frozen_string_literal: true require 'spec_helper' RSpec.describe Projects::RecordTargetPlatformsService, '#execute', feature_category: :groups_and_projects do let_it_be(:project) { create(:project) } let(:detector_service) { Projects::AppleTargetPlatformDetectorService } subject(:execute) { described_class....
Write RSpec test file for following ruby class ```ruby # frozen_string_literal: true module Projects # Service class for counting and caching the number of open issues of a # project. class OpenIssuesCountService < Projects::CountService include Gitlab::Utils::StrongMemoize # Cache keys used to store is...
# frozen_string_literal: true require 'spec_helper' RSpec.describe Projects::OpenIssuesCountService, :use_clean_rails_memory_store_caching, feature_category: :team_planning do let(:project) { create(:project) } subject { described_class.new(project) } it_behaves_like 'a counter caching service' describe '#...
Write RSpec test file for following ruby class ```ruby # frozen_string_literal: true # Service class for getting and caching the number of issues of several projects # Warning: do not user this service with a really large set of projects # because the service use maps to retrieve the project ids module Projects clas...
# frozen_string_literal: true require 'spec_helper' RSpec.describe Projects::BatchOpenIssuesCountService, feature_category: :groups_and_projects do let!(:project_1) { create(:project) } let!(:project_2) { create(:project) } let(:subject) { described_class.new([project_1, project_2]) } describe '#refresh_cac...
Write RSpec test file for following ruby class ```ruby # frozen_string_literal: true module Projects class GitDeduplicationService < BaseService include ExclusiveLeaseGuard LEASE_TIMEOUT = 86400 delegate :pool_repository, to: :project attr_reader :project def initialize(project) @project...
# frozen_string_literal: true require 'spec_helper' RSpec.describe Projects::GitDeduplicationService, feature_category: :source_code_management do include ExclusiveLeaseHelpers let(:pool) { create(:pool_repository, :ready) } let(:project) { create(:project, :repository) } let(:lease_key) { "git_deduplication...
Write RSpec test file for following ruby class ```ruby # frozen_string_literal: true module Projects class UpdateStatisticsService < BaseService include ::Gitlab::Utils::StrongMemoize STAT_TO_CACHED_METHOD = { repository_size: [:size, :recent_objects_size], commit_count: :commit_count }.free...
# frozen_string_literal: true require 'spec_helper' RSpec.describe Projects::UpdateStatisticsService, feature_category: :groups_and_projects do using RSpec::Parameterized::TableSyntax let(:service) { described_class.new(project, nil, statistics: statistics) } let(:statistics) { %w[repository_size] } describ...
Write RSpec test file for following ruby class ```ruby # frozen_string_literal: true module Projects # Base class for the various service classes that count project data (e.g. # issues or forks). class CountService < BaseCountService # The version of the cache format. This should be bumped whenever the #...
# frozen_string_literal: true require 'spec_helper' RSpec.describe Projects::CountService, feature_category: :groups_and_projects do let(:project) { build(:project, id: 1) } let(:service) { described_class.new(project) } describe '.query' do it 'raises NotImplementedError' do expect { described_class...
Write RSpec test file for following ruby class ```ruby # frozen_string_literal: true module Projects class MoveDeployKeysProjectsService < BaseMoveRelationsService def execute(source_project, remove_remaining_elements: true) return unless super # The SHA256 fingerprint should be there, but just in c...
# frozen_string_literal: true require 'spec_helper' RSpec.describe Projects::MoveDeployKeysProjectsService, feature_category: :continuous_delivery do let!(:user) { create(:user) } let!(:project_with_deploy_keys) { create(:project, namespace: user.namespace) } let!(:target_project) { create(:project, namespace: ...
Write RSpec test file for following ruby class ```ruby # frozen_string_literal: true module Projects class DetectRepositoryLanguagesService < BaseService attr_reader :programming_languages # rubocop: disable CodeReuse/ActiveRecord def execute repository_languages = project.repository_languages ...
# frozen_string_literal: true require 'spec_helper' RSpec.describe Projects::DetectRepositoryLanguagesService, :clean_gitlab_redis_shared_state, feature_category: :groups_and_projects do let_it_be(:project, reload: true) { create(:project, :repository) } subject { described_class.new(project) } describe '#exe...
Write RSpec test file for following ruby class ```ruby # frozen_string_literal: true module Projects class CreateService < BaseService include ValidatesClassificationLabel ImportSourceDisabledError = Class.new(StandardError) INTERNAL_IMPORT_SOURCES = %w[gitlab_custom_project_template gitlab_project_migr...
# frozen_string_literal: true require 'spec_helper' RSpec.describe Projects::CreateService, '#execute', feature_category: :groups_and_projects do include ExternalAuthorizationServiceHelpers let(:user) { create :user } let(:project_name) { 'GitLab' } let(:opts) do { name: project_name, namespa...
Write RSpec test file for following ruby class ```ruby # frozen_string_literal: true module Projects # Used by project imports, it removes any potential paths # included in an error message that could be stored in the DB class ImportErrorFilter ERROR_MESSAGE_FILTER = /[^\s]*#{File::SEPARATOR}[^\s]*(?=(\s|\z)...
# frozen_string_literal: true require 'spec_helper' RSpec.describe Projects::ImportErrorFilter, feature_category: :importers do it 'filters any full paths' do message = 'Error importing into /my/folder Permission denied @ unlink_internal - /var/opt/gitlab/gitlab-rails/shared/a/b/c/uploads/file' expect(desc...
Write RSpec test file for following ruby class ```ruby # frozen_string_literal: true module Projects module Alerting class NotifyService < ::BaseProjectService extend ::Gitlab::Utils::Override include ::AlertManagement::AlertProcessing include ::AlertManagement::Responses def initialize(...
# frozen_string_literal: true require 'spec_helper' RSpec.describe Projects::Alerting::NotifyService, feature_category: :groups_and_projects do let_it_be_with_reload(:project) { create(:project) } let(:payload) { ActionController::Parameters.new(payload_raw).permit! } let(:payload_raw) { {} } let(:service) ...
Write RSpec test file for following ruby class ```ruby # frozen_string_literal: true module Projects module ContainerRepository class DeleteTagsService < BaseService LOG_DATA_BASE = { service_class: self.to_s }.freeze def execute(container_repository) @container_repository = container_reposi...
# frozen_string_literal: true require 'spec_helper' RSpec.describe Projects::ContainerRepository::DeleteTagsService, feature_category: :container_registry do using RSpec::Parameterized::TableSyntax include_context 'container repository delete tags service shared context' let(:service) { described_class.new(pro...
Write RSpec test file for following ruby class ```ruby # frozen_string_literal: true module Projects module ContainerRepository class CleanupTagsService < BaseContainerRepositoryService def execute return error('access denied') unless can_destroy? return error('invalid regex') unless valid_...
# frozen_string_literal: true require 'spec_helper' RSpec.describe Projects::ContainerRepository::CleanupTagsService, feature_category: :container_registry do let_it_be_with_reload(:container_repository) { create(:container_repository) } let_it_be(:user) { container_repository.project.owner } let(:params) { {}...
Write RSpec test file for following ruby class ```ruby # frozen_string_literal: true module Projects module ContainerRepository class DestroyService < BaseService CLEANUP_TAGS_SERVICE_PARAMS = { 'name_regex_delete' => '.*', 'container_expiration_policy' => true, # to avoid permissions check...
# frozen_string_literal: true require 'spec_helper' RSpec.describe Projects::ContainerRepository::DestroyService, feature_category: :container_registry do let_it_be(:user) { create(:user) } let_it_be(:project) { create(:project, :private) } let_it_be(:params) { {} } subject { described_class.new(project, use...
Write RSpec test file for following ruby class ```ruby # frozen_string_literal: true module Projects module ContainerRepository module Gitlab class DeleteTagsService include BaseServiceUtility include ::Gitlab::Utils::StrongMemoize include ::Projects::ContainerRepository::Gitlab::Ti...
# frozen_string_literal: true require 'spec_helper' RSpec.describe Projects::ContainerRepository::Gitlab::DeleteTagsService, feature_category: :container_registry do include_context 'container repository delete tags service shared context' let(:service) { described_class.new(repository, tags) } describe '#exe...