Instruction:
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_params
      add_pages_unique_domain

      validate!

      ensure_wiki_exists if enabling_wiki?

      if changing_repository_storage?
        storage_move = project.repository_storage_moves.build(
          source_storage_name: project.repository_storage,
          destination_storage_name: params.delete(:repository_storage)
        )
        storage_move.schedule
      end

      yield if block_given?

      validate_classification_label(project, :external_authorization_classification_label)

      # If the block added errors, don't try to save the project
      return update_failed! if project.errors.any?

      if project.update(params.except(:default_branch))
        after_update

        success
      else
        update_failed!
      end
    rescue ValidationError => e
      error(e.message)
    end

    def run_auto_devops_pipeline?
      return false if project.repository.gitlab_ci_yml || !project.auto_devops&.previous_changes&.include?('enabled')

      project.auto_devops_enabled?
    end

    private

    def add_pages_unique_domain
      return unless params.dig(:project_setting_attributes, :pages_unique_domain_enabled)

      Gitlab::Pages.add_unique_domain_to(project)
    end

    def validate!
      unless valid_visibility_level_change?(project, project.visibility_attribute_value(params))
        raise_validation_error(s_('UpdateProject|New visibility level not allowed!'))
      end

      validate_default_branch_change
      validate_renaming_project_with_tags
    end

    def validate_default_branch_change
      return unless changing_default_branch?

      previous_default_branch = project.default_branch
      new_default_branch = params[:default_branch]

      if project.change_head(new_default_branch)
        params[:previous_default_branch] = previous_default_branch

        if !project.root_ref?(new_default_branch) && has_custom_head_branch?
          raise_validation_error(
            format(
              s_("UpdateProject|Could not set the default branch. Do you have a branch named 'HEAD' in your repository? (%{linkStart}How do I fix this?%{linkEnd})"),
              linkStart: ambiguous_head_documentation_link, linkEnd: '</a>'
            ).html_safe
          )
        end

        after_default_branch_change(previous_default_branch)
      else
        raise_validation_error(s_("UpdateProject|Could not set the default branch"))
      end
    end

    def validate_renaming_project_with_tags
      return unless renaming_project_with_container_registry_tags?

      unless Feature.enabled?(:renaming_project_with_tags, project) &&
          ContainerRegistry::GitlabApiClient.supports_gitlab_api?
        raise ValidationError, s_('UpdateProject|Cannot rename project because it contains container registry tags!')
      end

      dry_run = ContainerRegistry::GitlabApiClient.rename_base_repository_path(
        project.full_path, name: params[:path], dry_run: true)

      return if dry_run == :accepted

      log_error("Dry run failed for renaming project with tags: #{project.full_path}, error: #{dry_run}")
      raise_validation_error(
        format(
          s_("UpdateProject|Cannot rename project, the container registry path rename validation failed: %{error}"),
          error: dry_run.to_s.titleize
        )
      )
    end

    def ambiguous_head_documentation_link
      url = Rails.application.routes.url_helpers.help_page_path('user/project/repository/branches/index', anchor: 'error-ambiguous-head-branch-exists')

      format('<a href="%{url}" target="_blank" rel="noopener noreferrer">', url: url)
    end

    # See issue: https://gitlab.com/gitlab-org/gitlab/-/issues/381731
    def has_custom_head_branch?
      project.repository.branch_names.any? { |name| name.casecmp('head') == 0 }
    end

    def after_default_branch_change(previous_default_branch)
      # overridden by EE module
    end

    # overridden by EE module
    def remove_unallowed_params
      params.delete(:emails_enabled) unless can?(current_user, :set_emails_disabled, project)

      params.delete(:runner_registration_enabled) if Gitlab::CurrentSettings.valid_runner_registrars.exclude?('project')
    end

    def after_update
      todos_features_changes = %w[
        issues_access_level
        merge_requests_access_level
        repository_access_level
      ]
      project_changed_feature_keys = project.project_feature.previous_changes.keys

      if project.visibility_level_previous_changes && project.private?
        # don't enqueue immediately to prevent todos removal in case of a mistake
        TodosDestroyer::ConfidentialIssueWorker.perform_in(Todo::WAIT_FOR_DELETE, nil, project.id)
        TodosDestroyer::ProjectPrivateWorker.perform_in(Todo::WAIT_FOR_DELETE, project.id)
      elsif (project_changed_feature_keys & todos_features_changes).present?
        TodosDestroyer::PrivateFeaturesWorker.perform_in(Todo::WAIT_FOR_DELETE, project.id)
      end

      if project.previous_changes.include?('path')
        after_rename_service(project).execute
      else
        system_hook_service.execute_hooks_for(project, :update)
      end

      update_pending_builds if runners_settings_toggled?

      publish_events
    end

    def after_rename_service(project)
      AfterRenameService.new(project, path_before: project.path_before_last_save, full_path_before: project.full_path_before_last_save)
    end

    def raise_validation_error(message)
      raise ValidationError, message
    end

    def update_failed!
      model_errors = project.errors.full_messages.to_sentence
      error_message = model_errors.presence || s_('UpdateProject|Project could not be updated!')

      error(error_message)
    end

    def renaming_project_with_container_registry_tags?
      new_path = params[:path]

      new_path && new_path != project.path &&
        project.has_container_registry_tags?
    end

    def changing_default_branch?
      new_branch = params[:default_branch]

      new_branch && project.repository.exists? &&
        new_branch != project.default_branch
    end

    def enabling_wiki?
      return false if project.wiki_enabled?

      params.dig(:project_feature_attributes, :wiki_access_level).to_i > ProjectFeature::DISABLED
    end

    def ensure_wiki_exists
      return if project.create_wiki

      log_error("Could not create wiki for #{project.full_name}")
      Gitlab::Metrics.counter(:wiki_can_not_be_created_total, 'Counts the times we failed to create a wiki').increment
    end

    def changing_repository_storage?
      new_repository_storage = params[:repository_storage]

      new_repository_storage && project.repository.exists? &&
        project.repository_storage != new_repository_storage &&
        can?(current_user, :change_repository_storage, project)
    end

    def build_topics
      topics = params.delete(:topics)
      tag_list = params.delete(:tag_list)
      topic_list = topics || tag_list

      params[:topic_list] ||= topic_list if topic_list
    end

    def update_pending_builds
      update_params = {
        instance_runners_enabled: project.shared_runners_enabled?,
        namespace_traversal_ids: group_runner_traversal_ids
      }

      ::Ci::UpdatePendingBuildService
        .new(project, update_params)
        .execute
    end

    def shared_runners_settings_toggled?
      project.previous_changes.include?(:shared_runners_enabled)
    end

    def group_runners_settings_toggled?
      return false unless project.ci_cd_settings.present?

      project.ci_cd_settings.previous_changes.include?(:group_runners_enabled)
    end

    def runners_settings_toggled?
      shared_runners_settings_toggled? || group_runners_settings_toggled?
    end

    def group_runner_traversal_ids
      if project.group_runners_enabled?
        project.namespace.traversal_ids
      else
        []
      end
    end

    def publish_events
      publish_project_archived_event
      publish_project_attributed_changed_event
      publish_project_features_changed_event
    end

    def publish_project_archived_event
      return unless project.archived_previously_changed?

      event = Projects::ProjectArchivedEvent.new(data: {
        project_id: @project.id,
        namespace_id: @project.namespace_id,
        root_namespace_id: @project.root_namespace.id
      })

      Gitlab::EventStore.publish(event)
    end

    def publish_project_attributed_changed_event
      changes = @project.previous_changes

      return if changes.blank?

      event = Projects::ProjectAttributesChangedEvent.new(data: {
        project_id: @project.id,
        namespace_id: @project.namespace_id,
        root_namespace_id: @project.root_namespace.id,
        attributes: changes.keys
      })

      Gitlab::EventStore.publish(event)
    end

    def publish_project_features_changed_event
      changes = @project.project_feature.previous_changes

      return if changes.blank?

      event = Projects::ProjectFeaturesChangedEvent.new(data: {
        project_id: @project.id,
        namespace_id: @project.namespace_id,
        root_namespace_id: @project.root_namespace.id,
        features: changes.keys
      })

      Gitlab::EventStore.publish(event)
    end
  end
end

Projects::UpdateService.prepend_mod_with('Projects::UpdateService')

```

Response:
# 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.namespace)
  end

  shared_examples 'publishing Projects::ProjectAttributesChangedEvent' do |params:, attributes:|
    it "publishes Projects::ProjectAttributesChangedEvent" do
      expect { update_project(project, user, params) }
        .to publish_event(Projects::ProjectAttributesChangedEvent)
        .with(
          project_id: project.id,
          namespace_id: project.namespace_id,
          root_namespace_id: project.root_namespace.id,
          attributes: attributes
        )
    end
  end

  describe '#execute' do
    let(:admin) { create(:admin) }

    context 'when changing visibility level' do
      it_behaves_like 'publishing Projects::ProjectAttributesChangedEvent',
        params: { visibility_level: Gitlab::VisibilityLevel::INTERNAL },
        attributes: %w[updated_at visibility_level]

      context 'when visibility_level changes to INTERNAL' do
        it 'updates the project to internal' do
          expect(TodosDestroyer::ProjectPrivateWorker).not_to receive(:perform_in)

          result = update_project(project, user, visibility_level: Gitlab::VisibilityLevel::INTERNAL)

          expect(result).to eq({ status: :success })
          expect(project).to be_internal
        end
      end

      context 'when visibility_level changes to PUBLIC' do
        it 'updates the project to public' do
          expect(TodosDestroyer::ProjectPrivateWorker).not_to receive(:perform_in)

          result = update_project(project, user, visibility_level: Gitlab::VisibilityLevel::PUBLIC)

          expect(result).to eq({ status: :success })
          expect(project).to be_public
        end

        context 'and project is PRIVATE' do
          it 'does not unlink project from fork network' do
            expect(Projects::UnlinkForkService).not_to receive(:new)

            update_project(project, user, visibility_level: Gitlab::VisibilityLevel::PUBLIC)
          end
        end
      end

      context 'when visibility_level changes to PRIVATE' do
        before do
          project.update!(visibility_level: Gitlab::VisibilityLevel::PUBLIC)
        end

        it 'updates the project to private' do
          expect(TodosDestroyer::ProjectPrivateWorker).to receive(:perform_in).with(Todo::WAIT_FOR_DELETE, project.id)
          expect(TodosDestroyer::ConfidentialIssueWorker).to receive(:perform_in).with(Todo::WAIT_FOR_DELETE, nil, project.id)

          result = update_project(project, user, visibility_level: Gitlab::VisibilityLevel::PRIVATE)

          expect(result).to eq({ status: :success })
          expect(project).to be_private
        end
      end

      context 'when visibility levels are restricted to PUBLIC only' do
        before do
          stub_application_setting(restricted_visibility_levels: [Gitlab::VisibilityLevel::PUBLIC])
        end

        context 'when visibility_level is INTERNAL' do
          it 'updates the project to internal' do
            result = update_project(project, user, visibility_level: Gitlab::VisibilityLevel::INTERNAL)

            expect(result).to eq({ status: :success })
            expect(project).to be_internal
          end
        end

        context 'when visibility_level is PUBLIC' do
          it 'does not update the project to public' do
            result = update_project(project, user, visibility_level: Gitlab::VisibilityLevel::PUBLIC)

            expect(result).to eq({ status: :error, message: 'New visibility level not allowed!' })
            expect(project).to be_private
          end

          context 'when updated by an admin' do
            context 'when admin mode is enabled', :enable_admin_mode do
              it 'updates the project to public' do
                result = update_project(project, admin, visibility_level: Gitlab::VisibilityLevel::PUBLIC)

                expect(result).to eq({ status: :success })
                expect(project).to be_public
              end
            end

            context 'when admin mode is disabled' do
              it 'does not update the project to public' do
                result = update_project(project, admin, visibility_level: Gitlab::VisibilityLevel::PUBLIC)

                expect(result).to eq({ status: :error, message: 'New visibility level not allowed!' })
                expect(project).to be_private
              end
            end
          end
        end
      end

      context 'when project visibility is higher than parent group' do
        let(:group) { create(:group, visibility_level: Gitlab::VisibilityLevel::INTERNAL) }

        before do
          project.update!(namespace: group, visibility_level: group.visibility_level)
        end

        it 'does not update project visibility level even if admin', :enable_admin_mode do
          result = update_project(project, admin, visibility_level: Gitlab::VisibilityLevel::PUBLIC)

          expect(result).to eq({ status: :error, message: 'Visibility level public is not allowed in a internal group.' })
          expect(project.reload).to be_internal
        end
      end

      context 'when user is not project owner' do
        let_it_be(:maintainer) { create(:user) }

        before do
          project.add_maintainer(maintainer)
        end

        context 'when project is private' do
          it 'does not update the project to public' do
            result = update_project(project, maintainer, visibility_level: Gitlab::VisibilityLevel::PUBLIC)

            expect(result).to eq({ status: :error, message: 'New visibility level not allowed!' })
            expect(project).to be_private
          end

          it 'does not update the project to public with tricky value' do
            result = update_project(project, maintainer, visibility_level: Gitlab::VisibilityLevel::PUBLIC.to_s + 'r')

            expect(result).to eq({ status: :error, message: 'New visibility level not allowed!' })
            expect(project).to be_private
          end
        end

        context 'when project is public' do
          before do
            project.update!(visibility_level: Gitlab::VisibilityLevel::PUBLIC)
          end

          it 'does not update the project to private' do
            result = update_project(project, maintainer, visibility_level: Gitlab::VisibilityLevel::PRIVATE)

            expect(result).to eq({ status: :error, message: 'New visibility level not allowed!' })
            expect(project).to be_public
          end

          it 'does not update the project to private with invalid string value' do
            result = update_project(project, maintainer, visibility_level: 'invalid')

            expect(result).to eq({ status: :error, message: 'New visibility level not allowed!' })
            expect(project).to be_public
          end

          it 'does not update the project to private with valid string value' do
            result = update_project(project, maintainer, visibility_level: 'private')

            expect(result).to eq({ status: :error, message: 'New visibility level not allowed!' })
            expect(project).to be_public
          end

          # See https://gitlab.com/gitlab-org/gitlab/-/issues/359910
          it 'does not update the project to private because of Active Record typecasting' do
            result = update_project(project, maintainer, visibility_level: 'public')

            expect(result).to eq({ status: :success })
            expect(project).to be_public
          end
        end
      end

      context 'when updating shared runners' do
        context 'can enable shared runners' do
          let(:group) { create(:group, shared_runners_enabled: true) }
          let(:project) { create(:project, namespace: group, shared_runners_enabled: false) }

          it 'enables shared runners' do
            result = update_project(project, user, shared_runners_enabled: true)

            expect(result).to eq({ status: :success })
            expect(project.reload.shared_runners_enabled).to be_truthy
          end
        end

        context 'cannot enable shared runners' do
          let(:group) { create(:group, :shared_runners_disabled) }
          let(:project) { create(:project, namespace: group, shared_runners_enabled: false) }

          it 'does not enable shared runners' do
            result = update_project(project, user, shared_runners_enabled: true)

            expect(result).to eq({ status: :error, message: 'Shared runners enabled cannot be enabled because parent group does not allow it' })
            expect(project.reload.shared_runners_enabled).to be_falsey
          end
        end
      end
    end

    describe 'when updating project that has forks' do
      let(:project) { create(:project, :internal) }
      let(:user) { project.first_owner }
      let(:forked_project) { fork_project(project) }

      it 'does not change visibility of forks' do
        opts = { visibility_level: Gitlab::VisibilityLevel::PRIVATE }

        expect(project).to be_internal
        expect(forked_project).to be_internal

        expect(update_project(project, user, opts)).to eq({ status: :success })

        expect(project).to be_private
        expect(forked_project.reload).to be_internal
      end
    end

    context 'when updating a default branch' do
      let(:project) { create(:project, :repository) }

      it 'changes default branch, tracking the previous branch' do
        previous_default_branch = project.default_branch

        update_project(project, admin, default_branch: 'feature')

        project.reload

        expect(project.default_branch).to eq('feature')
        expect(project.previous_default_branch).to eq(previous_default_branch)

        update_project(project, admin, default_branch: previous_default_branch)

        project.reload

        expect(project.default_branch).to eq(previous_default_branch)
        expect(project.previous_default_branch).to eq('feature')
      end

      it 'does not change a default branch' do
        # The branch 'unexisted-branch' does not exist.
        update_project(project, admin, default_branch: 'unexisted-branch')

        project.reload

        expect(project.default_branch).to eq 'master'
        expect(project.previous_default_branch).to be_nil
      end

      context 'when repository has an ambiguous branch named "HEAD"' do
        before do
          allow(project.repository.raw).to receive(:write_ref).and_return(false)
          allow(project.repository).to receive(:branch_names) { %w[fix master main HEAD] }
        end

        it 'returns an error to the user' do
          result = update_project(project, admin, default_branch: 'fix')

          expect(result).to include(status: :error)
          expect(result[:message]).to include("Could not set the default branch. Do you have a branch named 'HEAD' in your repository?")

          project.reload

          expect(project.default_branch).to eq 'master'
          expect(project.previous_default_branch).to be_nil
        end
      end
    end

    context 'when we update project but not enabling a wiki' do
      it 'does not try to create an empty wiki' do
        project.wiki.repository.raw.remove

        result = update_project(project, user, { name: 'test1' })

        expect(result).to eq({ status: :success })
        expect(project.wiki_repository_exists?).to be false
      end

      it 'handles empty project feature attributes' do
        project.project_feature.update!(wiki_access_level: ProjectFeature::DISABLED)

        result = update_project(project, user, { name: 'test1' })

        expect(result).to eq({ status: :success })
        expect(project.wiki_repository_exists?).to be false
      end
    end

    context 'when enabling a wiki' do
      it 'creates a wiki' do
        project.project_feature.update!(wiki_access_level: ProjectFeature::DISABLED)
        project.wiki.repository.raw.remove

        result = update_project(project, user, project_feature_attributes: { wiki_access_level: ProjectFeature::ENABLED })

        expect(result).to eq({ status: :success })
        expect(project.wiki_repository_exists?).to be true
        expect(project.wiki_enabled?).to be true
      end

      it 'logs an error and creates a metric when wiki can not be created' do
        project.project_feature.update!(wiki_access_level: ProjectFeature::DISABLED)

        expect_next_instance_of(ProjectWiki) do |project_wiki|
          expect(project_wiki).to receive(:create_wiki_repository).and_raise(Wiki::CouldNotCreateWikiError)
        end
        expect_any_instance_of(described_class).to receive(:log_error).with("Could not create wiki for #{project.full_name}")

        counter = double(:counter)
        expect(Gitlab::Metrics).to receive(:counter).with(:wiki_can_not_be_created_total, 'Counts the times we failed to create a wiki').and_return(counter)
        expect(counter).to receive(:increment)

        update_project(project, user, project_feature_attributes: { wiki_access_level: ProjectFeature::ENABLED })
      end
    end

    context 'when changing feature visibility to private' do
      it 'updates the visibility correctly' do
        expect(TodosDestroyer::PrivateFeaturesWorker)
          .to receive(:perform_in).with(Todo::WAIT_FOR_DELETE, project.id)

        result = update_project(project, user, project_feature_attributes:
                                 { issues_access_level: ProjectFeature::PRIVATE }
        )

        expect(result).to eq({ status: :success })
        expect(project.project_feature.issues_access_level).to be(ProjectFeature::PRIVATE)
      end
    end

    context 'when changes project features' do
      # Using some sample features for testing.
      # Not using all the features because some of them must be enabled/disabled together
      %w[issues wiki forking model_experiments].each do |feature_name|
        context "with feature_name:#{feature_name}" do
          let(:feature) { "#{feature_name}_access_level" }
          let(:params) do
            { project_feature_attributes: { feature => ProjectFeature::ENABLED } }
          end

          before do
            project.project_feature.update!(feature => ProjectFeature::DISABLED)
          end

          it 'publishes Projects::ProjectFeaturesChangedEvent' do
            expect { update_project(project, user, params) }
              .to publish_event(Projects::ProjectFeaturesChangedEvent)
              .with(
                project_id: project.id,
                namespace_id: project.namespace_id,
                root_namespace_id: project.root_namespace.id,
                features: array_including(feature, "updated_at")
              )
          end
        end
      end
    end

    context 'when archiving a project' do
      it_behaves_like 'publishing Projects::ProjectAttributesChangedEvent',
        params: { archived: true },
        attributes: %w[updated_at archived]

      it 'publishes a ProjectTransferedEvent' do
        expect { update_project(project, user, archived: true) }
          .to publish_event(Projects::ProjectArchivedEvent)
          .with(
            project_id: project.id,
            namespace_id: project.namespace_id,
            root_namespace_id: project.root_namespace.id
          )
      end
    end

    context 'when changing operations feature visibility' do
      let(:feature_params) { { operations_access_level: ProjectFeature::DISABLED } }

      it 'does not sync the changes to the related fields' do
        result = update_project(project, user, project_feature_attributes: feature_params)

        expect(result).to eq({ status: :success })
        feature = project.project_feature

        expect(feature.operations_access_level).to eq(ProjectFeature::DISABLED)
        expect(feature.monitor_access_level).not_to eq(ProjectFeature::DISABLED)
        expect(feature.infrastructure_access_level).not_to eq(ProjectFeature::DISABLED)
        expect(feature.feature_flags_access_level).not_to eq(ProjectFeature::DISABLED)
        expect(feature.environments_access_level).not_to eq(ProjectFeature::DISABLED)
      end
    end

    context 'when updating a project that contains container images' do
      let(:new_name) { 'renamed' }

      before do
        stub_container_registry_config(enabled: true)
        stub_container_registry_tags(repository: /image/, tags: %w[rc1])
        create(:container_repository, project: project, name: :image)
      end

      shared_examples 'renaming the project fails with message' do |error_message|
        it 'does not allow to rename the project' do
          result = update_project(project, admin, path: new_name)

          expect(result).to include(status: :error)
          expect(result[:message]).to match(error_message)
        end
      end

      context 'when feature renaming_project_with_tags is disabled' do
        before do
          stub_feature_flags(renaming_project_with_tags: false)
        end

        it_behaves_like 'renaming the project fails with message', /contains container registry tags/
      end

      context "when the GitlabAPI is not supported" do
        before do
          allow(ContainerRegistry::GitlabApiClient).to receive(:supports_gitlab_api?).and_return(false)
        end

        it_behaves_like 'renaming the project fails with message', /contains container registry tags/
      end

      context 'when Gitlab API is supported' do
        before do
          allow(ContainerRegistry::GitlabApiClient).to receive(:supports_gitlab_api?).and_return(true)
        end

        it 'executes a dry run of the project rename' do
          stub_rename_base_repository_in_registry(dry_run: true)

          update_project(project, admin, path: new_name)

          expect_rename_of_base_repository_in_registry(dry_run: true)
        end

        context 'when the dry run fails' do
          before do
            stub_rename_base_repository_in_registry(dry_run: true, result: :bad_request)
          end

          it_behaves_like 'renaming the project fails with message', /container registry path rename validation failed/

          it 'logs the error' do
            expect_any_instance_of(described_class).to receive(:log_error).with("Dry run failed for renaming project with tags: #{project.full_path}, error: bad_request")

            update_project(project, admin, path: new_name)
          end
        end

        context 'when the dry run succeeds' do
          before do
            stub_rename_base_repository_in_registry(dry_run: true, result: :accepted)
          end

          it 'continues with the project rename' do
            stub_rename_base_repository_in_registry(dry_run: false, result: :ok)
            old_project_full_path = project.full_path

            update_project(project, admin, path: new_name)

            expect_rename_of_base_repository_in_registry(dry_run: true, path: old_project_full_path)
            expect_rename_of_base_repository_in_registry(dry_run: false, path: old_project_full_path)
          end
        end

        def stub_rename_base_repository_in_registry(dry_run:, result: nil)
          options = { name: new_name }
          options[:dry_run] = true if dry_run

          allow(ContainerRegistry::GitlabApiClient)
            .to receive(:rename_base_repository_path)
            .with(project.full_path, options)
            .and_return(result)
        end

        def expect_rename_of_base_repository_in_registry(dry_run:, path: nil)
          options = { name: new_name }
          options[:dry_run] = true if dry_run

          expect(ContainerRegistry::GitlabApiClient)
            .to have_received(:rename_base_repository_path)
            .with(path || project.full_path, options)
        end
      end

      it 'allows to update other settings' do
        result = update_project(project, admin, public_builds: true)

        expect(result[:status]).to eq :success
        expect(project.reload.public_builds).to be true
      end
    end

    context 'when renaming a project' do
      let(:raw_fake_repo) { Gitlab::Git::Repository.new('default', File.join(user.namespace.full_path, 'existing.git'), nil, nil) }

      context 'with legacy storage' do
        let(:project) { create(:project, :legacy_storage, :repository, creator: user, namespace: user.namespace) }

        before do
          raw_fake_repo.create_repository
        end

        after do
          raw_fake_repo.remove
        end

        it 'does not allow renaming when new path matches existing repository on disk' do
          result = update_project(project, admin, path: 'existing')

          expect(result).to include(status: :error)
          expect(result[:message]).to match('There is already a repository with that name on disk')
          expect(project).not_to be_valid
          expect(project.errors.messages).to have_key(:base)
          expect(project.errors.messages[:base]).to include('There is already a repository with that name on disk')
        end

        context 'when hashed storage is enabled' do
          before do
            stub_application_setting(hashed_storage_enabled: true)
          end

          it 'migrates project to a hashed storage instead of renaming the repo to another legacy name' do
            result = update_project(project, admin, path: 'new-path')

            expect(result).not_to include(status: :error)
            expect(project).to be_valid
            expect(project.errors).to be_empty
            expect(project.reload.hashed_storage?(:repository)).to be_truthy
          end
        end
      end

      context 'with hashed storage' do
        let(:project) { create(:project, :repository, creator: user, namespace: user.namespace) }

        before do
          stub_application_setting(hashed_storage_enabled: true)
        end

        it 'does not check if new path matches existing repository on disk' do
          expect(project).not_to receive(:repository_with_same_path_already_exists?)

          result = update_project(project, admin, path: 'existing')

          expect(result).to include(status: :success)
        end
      end
    end

    context 'when passing invalid parameters' do
      it 'returns an error result when record cannot be updated' do
        result = update_project(project, admin, { name: 'foo&bar' })

        expect(result).to eq({
          status: :error,
          message: "Name can contain only letters, digits, emoji, '_', '.', '+', dashes, or spaces. It must start with a letter, digit, emoji, or '_'."
        })
      end
    end

    context 'when updating #emails_enabled' do
      it 'updates the attribute for the project owner' do
        expect { update_project(project, user, emails_enabled: false) }
          .to change { project.emails_enabled }
          .to(false)
      end

      it 'does not update when not project owner' do
        maintainer = create(:user)
        project.add_member(maintainer, :maintainer)

        expect { update_project(project, maintainer, emails_enabled: false) }
          .not_to change { project.emails_enabled }
      end
    end

    context 'when updating #runner_registration_enabled' do
      it 'updates the attribute' do
        expect { update_project(project, user, runner_registration_enabled: false) }
          .to change { project.runner_registration_enabled }
          .to(false)
      end

      context 'when runner registration is disabled for all projects' do
        before do
          stub_application_setting(valid_runner_registrars: [])
        end

        it 'restricts updating the attribute' do
          expect { update_project(project, user, runner_registration_enabled: false) }
            .not_to change { project.runner_registration_enabled }
        end
      end
    end

    context 'when updating runners settings' do
      let(:settings) do
        { instance_runners_enabled: true, namespace_traversal_ids: [123] }
      end

      let!(:pending_build) do
        create(:ci_pending_build, project: project, **settings)
      end

      context 'when project has shared runners enabled' do
        let(:project) { create(:project, shared_runners_enabled: true) }

        it 'updates builds queue when shared runners get disabled' do
          expect { update_project(project, admin, shared_runners_enabled: false) }
            .to change { pending_build.reload.instance_runners_enabled }.to(false)

          expect(pending_build.reload.instance_runners_enabled).to be false
        end
      end

      context 'when project has shared runners disabled' do
        let(:project) { create(:project, shared_runners_enabled: false) }

        it 'updates builds queue when shared runners get enabled' do
          expect { update_project(project, admin, shared_runners_enabled: true) }
            .to not_change { pending_build.reload.instance_runners_enabled }

          expect(pending_build.reload.instance_runners_enabled).to be true
        end
      end

      context 'when project has group runners enabled' do
        let(:project) { create(:project, group_runners_enabled: true) }

        before do
          project.ci_cd_settings.update!(group_runners_enabled: true)
        end

        it 'updates builds queue when group runners get disabled' do
          update_project(project, admin, group_runners_enabled: false)

          expect(pending_build.reload.namespace_traversal_ids).to be_empty
        end
      end

      context 'when project has group runners disabled' do
        let(:project) { create(:project, :in_subgroup, group_runners_enabled: false) }

        before do
          project.reload.ci_cd_settings.update!(group_runners_enabled: false)
        end

        it 'updates builds queue when group runners get enabled' do
          update_project(project, admin, group_runners_enabled: true)

          expect(pending_build.reload.namespace_traversal_ids).to include(project.namespace.id)
        end
      end
    end

    context 'with external authorization enabled' do
      before do
        enable_external_authorization_service_check

        allow(::Gitlab::ExternalAuthorization)
          .to receive(:access_allowed?).with(user, 'default_label', project.full_path).and_call_original
      end

      it 'does not save the project with an error if the service denies access' do
        expect(::Gitlab::ExternalAuthorization)
          .to receive(:access_allowed?).with(user, 'new-label') { false }

        result = update_project(project, user, { external_authorization_classification_label: 'new-label' })

        expect(result[:message]).to be_present
        expect(result[:status]).to eq(:error)
      end

      it 'saves the new label if the service allows access' do
        expect(::Gitlab::ExternalAuthorization)
          .to receive(:access_allowed?).with(user, 'new-label') { true }

        result = update_project(project, user, { external_authorization_classification_label: 'new-label' })

        expect(result[:status]).to eq(:success)
        expect(project.reload.external_authorization_classification_label).to eq('new-label')
      end

      it 'checks the default label when the classification label was cleared' do
        expect(::Gitlab::ExternalAuthorization)
          .to receive(:access_allowed?).with(user, 'default_label') { true }

        update_project(project, user, { external_authorization_classification_label: '' })
      end

      it 'does not check the label when it does not change' do
        expect(::Gitlab::ExternalAuthorization).to receive(:access_allowed?).once

        update_project(project, user, { name: 'New name' })
      end
    end

    context 'when updating nested attributes for prometheus integration' do
      context 'prometheus integration exists' do
        let(:prometheus_integration_attributes) do
          attributes_for(
            :prometheus_integration,
            project: project,
            properties: { api_url: "http://new.prometheus.com", manual_configuration: "0" }
          )
        end

        let!(:prometheus_integration) do
          create(
            :prometheus_integration,
            project: project,
            properties: { api_url: "http://old.prometheus.com", manual_configuration: "0" }
          )
        end

        it 'updates existing record' do
          expect { update_project(project, user, prometheus_integration_attributes: prometheus_integration_attributes) }
            .to change { prometheus_integration.reload.api_url }
            .from("http://old.prometheus.com")
            .to("http://new.prometheus.com")
        end
      end

      context 'prometheus integration does not exist' do
        context 'valid parameters' do
          let(:prometheus_integration_attributes) do
            attributes_for(
              :prometheus_integration,
              project: project,
              properties: { api_url: "http://example.prometheus.com", manual_configuration: "0" }
            )
          end

          it 'creates new record' do
            expect { update_project(project, user, prometheus_integration_attributes: prometheus_integration_attributes) }
              .to change { ::Integrations::Prometheus.where(project: project).count }
              .from(0)
              .to(1)
          end
        end

        context 'invalid parameters' do
          let(:prometheus_integration_attributes) do
            attributes_for(
              :prometheus_integration,
              project: project,
              properties: { api_url: 'invalid-url', manual_configuration: "1" }
            )
          end

          it 'does not create new record' do
            expect { update_project(project, user, prometheus_integration_attributes: prometheus_integration_attributes) }
              .not_to change { ::Integrations::Prometheus.where(project: project).count }
          end
        end
      end
    end

    describe 'when changing repository_storage' do
      let(:repository_read_only) { false }
      let(:project) { create(:project, :repository, repository_read_only: repository_read_only) }
      let(:opts) { { repository_storage: 'test_second_storage' } }

      before do
        stub_storage_settings('test_second_storage' => {})
      end

      shared_examples 'the transfer was not scheduled' do
        it 'does not schedule the transfer' do
          expect do
            update_project(project, user, opts)
          end.not_to change(project.repository_storage_moves, :count)
        end
      end

      context 'authenticated as admin' do
        let(:user) { create(:admin) }

        context 'when admin mode is enabled', :enable_admin_mode do
          it 'schedules the transfer of the repository to the new storage and locks the project' do
            update_project(project, admin, opts)

            expect(project).to be_repository_read_only
            expect(project.repository_storage_moves.last).to have_attributes(
              state: ::Projects::RepositoryStorageMove.state_machines[:state].states[:scheduled].value,
              source_storage_name: 'default',
              destination_storage_name: 'test_second_storage'
            )
          end
        end

        context 'when admin mode is disabled' do
          it_behaves_like 'the transfer was not scheduled'
        end

        context 'the repository is read-only' do
          let(:repository_read_only) { true }

          it_behaves_like 'the transfer was not scheduled'
        end

        context 'the storage has not changed' do
          let(:opts) { { repository_storage: 'default' } }

          it_behaves_like 'the transfer was not scheduled'
        end

        context 'the storage does not exist' do
          let(:opts) { { repository_storage: 'nonexistent' } }

          it_behaves_like 'the transfer was not scheduled'
        end
      end

      context 'authenticated as user' do
        let(:user) { create(:user) }

        it_behaves_like 'the transfer was not scheduled'
      end
    end

    describe 'when updating topics' do
      let(:project) { create(:project, topic_list: 'topic1, topic2') }

      it 'update using topics' do
        result = update_project(project, user, { topics: 'topics' })

        expect(result[:status]).to eq(:success)
        expect(project.topic_list).to eq(%w[topics])
      end

      it 'update using topic_list' do
        result = update_project(project, user, { topic_list: 'topic_list' })

        expect(result[:status]).to eq(:success)
        expect(project.topic_list).to eq(%w[topic_list])
      end

      it 'update using tag_list (deprecated)' do
        result = update_project(project, user, { tag_list: 'tag_list' })

        expect(result[:status]).to eq(:success)
        expect(project.topic_list).to eq(%w[tag_list])
      end
    end

    describe 'when updating pages unique domain', feature_category: :pages do
      before do
        stub_pages_setting(enabled: true)
      end

      context 'when turning it on' do
        it 'adds pages unique domain' do
          expect(Gitlab::Pages).to receive(:add_unique_domain_to)

          expect { update_project(project, user, project_setting_attributes: { pages_unique_domain_enabled: true }) }
            .to change { project.project_setting.pages_unique_domain_enabled }
            .from(false).to(true)
        end
      end

      context 'when turning it off' do
        it 'adds pages unique domain' do
          expect(Gitlab::Pages).not_to receive(:add_unique_domain_to)

          expect { update_project(project, user, project_setting_attributes: { pages_unique_domain_enabled: false }) }
            .not_to change { project.project_setting.pages_unique_domain_enabled }
        end
      end
    end
  end

  describe '#run_auto_devops_pipeline?' do
    subject { described_class.new(project, user).run_auto_devops_pipeline? }

    context 'when master contains a .gitlab-ci.yml file' do
      before do
        allow(project.repository).to receive(:gitlab_ci_yml).and_return("script: ['test']")
      end

      it { is_expected.to eq(false) }
    end

    context 'when auto devops is nil' do
      it { is_expected.to eq(false) }
    end

    context 'when auto devops is explicitly enabled' do
      before do
        project.create_auto_devops!(enabled: true)
      end

      it { is_expected.to eq(true) }
    end

    context 'when auto devops is explicitly disabled' do
      before do
        project.create_auto_devops!(enabled: false)
      end

      it { is_expected.to eq(false) }
    end

    context 'when auto devops is set to instance setting' do
      before do
        project.create_auto_devops!(enabled: nil)
        project.reload

        allow(project.auto_devops).to receive(:previous_changes).and_return('enabled' => true)
      end

      context 'when auto devops is enabled system-wide' do
        before do
          stub_application_setting(auto_devops_enabled: true)
        end

        it { is_expected.to eq(true) }
      end

      context 'when auto devops is disabled system-wide' do
        before do
          stub_application_setting(auto_devops_enabled: false)
        end

        it { is_expected.to eq(false) }
      end
    end
  end

  def update_project(project, user, opts)
    described_class.new(project, user, opts).execute
  end
end


Instruction:
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)
        project.deploy_keys << key
      end

      key
    end

    private

    def find_accessible_key(key_id)
      if current_user.admin?
        DeployKey.find_by_id(key_id)
      else
        current_user.accessible_deploy_keys.find_by_id(key_id)
      end
    end
  end
end

Projects::EnableDeployKeyService.prepend_mod_with('Projects::EnableDeployKeyService')

```

Response:
# 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: deploy_key.id } }

  it 'enables the key' do
    expect do
      service.execute
    end.to change { project.deploy_keys.count }.from(0).to(1)
  end

  context 'trying to add an unaccessable key' do
    let(:another_key) { create(:another_key) }
    let!(:params)     { { key_id: another_key.id } }

    it 'returns nil if the key cannot be added' do
      expect(service.execute).to be nil
    end
  end

  context 'add the same key twice' do
    before do
      project.deploy_keys << deploy_key
    end

    it 'returns existing key' do
      expect(service.execute).to eq(deploy_key)
    end
  end

  def service
    Projects::EnableDeployKeyService.new(project, user, params)
  end
end


Instruction:
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_projects
        remove_remaining_lfs_objects_project if remove_remaining_elements

        success
      end
    end

    private

    def move_lfs_objects_projects
      non_existent_lfs_objects_projects.update_all(project_id: @project.id)
    end

    def remove_remaining_lfs_objects_project
      source_project.lfs_objects_projects.destroy_all # rubocop: disable Cop/DestroyAll
    end

    # rubocop: disable CodeReuse/ActiveRecord
    def non_existent_lfs_objects_projects
      source_project.lfs_objects_projects.where.not(lfs_object: @project.lfs_objects)
    end
    # rubocop: enable CodeReuse/ActiveRecord
  end
end

```

Response:
# 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, namespace: user.namespace) }

  subject { described_class.new(target_project, user) }

  before do
    create_list(:lfs_objects_project, 3, project: project_with_lfs_objects)
  end

  describe '#execute' do
    it 'links the lfs objects from existent in source project' do
      expect(target_project.lfs_objects.count).to eq 0

      subject.execute(project_with_lfs_objects)

      expect(project_with_lfs_objects.reload.lfs_objects.count).to eq 0
      expect(target_project.reload.lfs_objects.count).to eq 3
    end

    it 'does not link existent lfs_object in the current project' do
      target_project.lfs_objects << project_with_lfs_objects.lfs_objects.first(2)

      expect(target_project.lfs_objects.count).to eq 2

      subject.execute(project_with_lfs_objects)

      expect(target_project.lfs_objects.count).to eq 3
    end

    it 'rollbacks changes if transaction fails' do
      allow(subject).to receive(:success).and_raise(StandardError)

      expect { subject.execute(project_with_lfs_objects) }.to raise_error(StandardError)

      expect(project_with_lfs_objects.lfs_objects.count).to eq 3
      expect(target_project.lfs_objects.count).to eq 0
    end

    context 'when remove_remaining_elements is false' do
      let(:options) { { remove_remaining_elements: false } }

      it 'does not remove remaining lfs objects' do
        target_project.lfs_objects << project_with_lfs_objects.lfs_objects.first(2)

        subject.execute(project_with_lfs_objects, **options)

        expect(project_with_lfs_objects.lfs_objects.count).not_to eq 0
      end
    end
  end
end


Instruction:
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 = <SDK_name>" where SDK_name can be
  # 'iphoneos', 'macosx', 'appletvos' or 'watchos'. Currently, the service is
  # intentionally limited (for performance reasons) to detect if a project
  # targets iOS.
  #
  # Ref: https://developer.apple.com/documentation/xcode/build-settings-reference/
  #
  # Example usage:
  # > AppleTargetPlatformDetectorService.new(a_project).execute
  # => []
  # > AppleTargetPlatformDetectorService.new(an_ios_project).execute
  # => [:ios]
  # > AppleTargetPlatformDetectorService.new(multiplatform_project).execute
  # => [:ios, :osx, :tvos, :watchos]
  class AppleTargetPlatformDetectorService < BaseService
    BUILD_CONFIG_FILENAMES = %w[project.pbxproj *.xcconfig].freeze

    # For the current iteration, we only want to detect when the project targets
    # iOS. In the future, we can use the same logic to detect projects that
    # target OSX, TvOS, and WatchOS platforms with SDK names 'macosx', 'appletvos',
    # and 'watchos', respectively.
    PLATFORM_SDK_NAMES = { ios: 'iphoneos' }.freeze

    def execute
      detect_platforms
    end

    private

    def file_finder
      @file_finder ||= ::Gitlab::FileFinder.new(project, project.default_branch)
    end

    def detect_platforms
      # Return array of SDK names for which "SDKROOT = <sdk_name>" setting
      # definition can be found in either project.pbxproj or *.xcconfig files.
      PLATFORM_SDK_NAMES.select do |_, sdk|
        config_files_containing_sdk_setting(sdk).present?
      end.keys
    end

    # Return array of project.pbxproj and/or *.xcconfig files
    # (Gitlab::Search::FoundBlob) that contain the setting definition string
    # "SDKROOT = <sdk_name>"
    def config_files_containing_sdk_setting(sdk)
      BUILD_CONFIG_FILENAMES.map do |filename|
        file_finder.find("SDKROOT = #{sdk} filename:#{filename}")
      end.flatten
    end
  end
end

```

Response:
# 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
      allow(Gitlab::FileFinder).to receive(:new) { instance_double(Gitlab::FileFinder, find: []) }
    end

    it 'returns an empty array' do
      is_expected.to match_array []
    end
  end

  context 'when project is an xcode project' do
    using RSpec::Parameterized::TableSyntax

    let(:finder) { instance_double(Gitlab::FileFinder) }

    before do
      allow(Gitlab::FileFinder).to receive(:new) { finder }
    end

    def search_query(sdk, filename)
      "SDKROOT = #{sdk} filename:#{filename}"
    end

    context 'when setting string is found' do
      where(:sdk, :filename, :result) do
        'iphoneos'  | 'project.pbxproj' | [:ios]
        'iphoneos'  | '*.xcconfig'      | [:ios]
      end

      with_them do
        before do
          allow(finder).to receive(:find).with(anything) { [] }
          allow(finder).to receive(:find).with(search_query(sdk, filename)) { [instance_double(Gitlab::Search::FoundBlob)] }
        end

        it 'returns an array of unique detected targets' do
          is_expected.to match_array result
        end
      end
    end

    context 'when setting string is not found' do
      before do
        allow(finder).to receive(:find).with(anything) { [] }
      end

      it 'returns an empty array' do
        is_expected.to match_array []
      end
    end
  end
end


Instruction:
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

    def execute
      record_target_platforms
    end

    private

    attr_reader :project, :detector_service

    def target_platforms
      strong_memoize(:target_platforms) do
        Array(detector_service.new(project).execute)
      end
    end

    def record_target_platforms
      return unless target_platforms.present?

      project_setting.target_platforms = target_platforms
      project_setting.save
      project_setting.target_platforms
    end

    def project_setting
      @project_setting ||= ::ProjectSetting.find_or_initialize_by(project: project) # rubocop:disable CodeReuse/ActiveRecord
    end
  end
end

```

Response:
# 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.new(project, detector_service).execute }

  context 'when project is an XCode project' do
    def project_setting
      ProjectSetting.find_by_project_id(project.id)
    end

    before do
      double = instance_double(detector_service, execute: [:ios, :osx])
      allow(Projects::AppleTargetPlatformDetectorService).to receive(:new) { double }
    end

    it 'creates a new setting record for the project', :aggregate_failures do
      expect { execute }.to change { ProjectSetting.count }.from(0).to(1)
      expect(ProjectSetting.last.target_platforms).to match_array(%w[ios osx])
    end

    it 'returns array of detected target platforms' do
      expect(execute).to match_array %w[ios osx]
    end

    context 'when a project has an existing setting record' do
      before do
        create(:project_setting, project: project, target_platforms: saved_target_platforms)
      end

      context 'when target platforms changed' do
        let(:saved_target_platforms) { %w[tvos] }

        it 'updates' do
          expect { execute }.to change { project_setting.target_platforms }.from(%w[tvos]).to(%w[ios osx])
        end

        it { is_expected.to match_array %w[ios osx] }
      end

      context 'when target platforms are the same' do
        let(:saved_target_platforms) { %w[osx ios] }

        it 'does not update' do
          expect { execute }.not_to change { project_setting.updated_at }
        end
      end
    end
  end

  context 'when project is not an XCode project' do
    before do
      double = instance_double(Projects::AppleTargetPlatformDetectorService, execute: [])
      allow(Projects::AppleTargetPlatformDetectorService).to receive(:new).with(project) { double }
    end

    it 'does nothing' do
      expect { execute }.not_to change { ProjectSetting.count }
    end

    it { is_expected.to be_nil }
  end
end


Instruction:
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 issues count
    PUBLIC_COUNT_KEY = 'public_open_issues_count'
    TOTAL_COUNT_KEY = 'total_open_issues_count'

    def initialize(project, user = nil)
      @user = user

      super(project)
    end

    def cache_key_name
      public_only? ? PUBLIC_COUNT_KEY : TOTAL_COUNT_KEY
    end

    def public_only?
      !user_is_at_least_reporter?
    end

    def user_is_at_least_reporter?
      strong_memoize(:user_is_at_least_reporter) do
        @project.member?(@user, Gitlab::Access::REPORTER)
      end
    end

    def relation_for_count
      self.class.query(@project, public_only: public_only?)
    end

    def public_count_cache_key
      cache_key(PUBLIC_COUNT_KEY)
    end

    def total_count_cache_key
      cache_key(TOTAL_COUNT_KEY)
    end

    # rubocop: disable CodeReuse/ActiveRecord
    def refresh_cache(&block)
      count_grouped_by_confidential = self.class.query(@project, public_only: false).group(:confidential).count
      public_count = count_grouped_by_confidential[false] || 0
      total_count = public_count + (count_grouped_by_confidential[true] || 0)

      update_cache_for_key(public_count_cache_key) do
        public_count
      end

      update_cache_for_key(total_count_cache_key) do
        total_count
      end
    end

    # We only show issues count including confidential for reporters, who are allowed to view confidential issues.
    # This will still show a discrepancy on issues number but should be less than before.
    # Check https://gitlab.com/gitlab-org/gitlab-foss/issues/38418 description.

    # rubocop: disable CodeReuse/ActiveRecord
    def self.query(projects, public_only: true)
      open_issues = Issue.opened

      if public_only
        open_issues.public_only.where(project: projects)
      else
        open_issues.where(project: projects)
      end
    end
    # rubocop: enable CodeReuse/ActiveRecord
  end
end

```

Response:
# 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 '#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)

        expect(described_class.new(project).count).to eq(1)
      end
    end

    context 'when user is provided' do
      let(:user) { create(:user) }

      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)
        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')
        end
      end

      context 'when user cannot read confidential 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)

          expect(described_class.new(project, user).count).to eq(1)
        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')
        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
      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)

          subject.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
      end
    end
  end
end


Instruction:
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
  class BatchOpenIssuesCountService < Projects::BatchCountService
    # rubocop: disable CodeReuse/ActiveRecord
    def global_count
      @global_count ||= count_service.query(project_ids).group(:project_id).count
    end
    # rubocop: enable CodeReuse/ActiveRecord

    def count_service
      ::Projects::OpenIssuesCountService
    end
  end
end

```

Response:
# 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_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_2)
      create(:issue, project: project_2, confidential: true)
    end

    context 'when cache is clean' do
      it 'refreshes cache keys correctly' do
        subject.refresh_cache_and_retrieve_data

        # 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)

        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
  end

  def get_cache_key(subject, project, public_key = false)
    service = subject.count_service.new(project)

    if public_key
      service.cache_key(service.class::PUBLIC_COUNT_KEY)
    else
      service.cache_key(service.class::TOTAL_COUNT_KEY)
    end
  end
end


Instruction:
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 = project
    end

    def execute
      try_obtain_lease do
        unless project.has_pool_repository?
          disconnect_git_alternates
          break
        end

        if source_project? && pool_can_fetch_from_source?
          fetch_from_source
        end

        project.link_pool_repository if same_storage_as_pool?(project.repository)
      end
    end

    private

    def disconnect_git_alternates
      project.repository.disconnect_alternates
    end

    def pool_can_fetch_from_source?
      project.git_objects_poolable? &&
        same_storage_as_pool?(pool_repository.source_project.repository)
    end

    def same_storage_as_pool?(repository)
      pool_repository.object_pool.repository.storage == repository.storage
    end

    def fetch_from_source
      project.pool_repository.object_pool.fetch
    end

    def source_project?
      return unless project.has_pool_repository?

      project.pool_repository.source_project == project
    end

    def lease_timeout
      LEASE_TIMEOUT
    end

    def lease_key
      "git_deduplication:#{project.id}"
    end
  end
end

```

Response:
# 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:#{project.id}" }
  let(:lease_timeout) { Projects::GitDeduplicationService::LEASE_TIMEOUT }

  subject(:service) { described_class.new(project) }

  describe '#execute' do
    context 'when there is not already a lease' do
      context 'when the project does not have a pool repository' do
        it 'calls disconnect_git_alternates' do
          stub_exclusive_lease(lease_key, timeout: lease_timeout)

          expect(project.repository).to receive(:disconnect_alternates)

          service.execute
        end
      end

      context 'when the project has a pool repository' do
        let(:project) { create(:project, :repository, pool_repository: pool) }

        context 'when the project is a source project' do
          let(:lease_key) { "git_deduplication:#{pool.source_project.id}" }

          subject(:service) { described_class.new(pool.source_project) }

          it 'calls fetch' do
            stub_exclusive_lease(lease_key, timeout: lease_timeout)
            allow(pool.source_project).to receive(:git_objects_poolable?).and_return(true)

            expect(pool.object_pool).to receive(:fetch)

            service.execute
          end

          it 'does not call fetch if git objects are not poolable' do
            stub_exclusive_lease(lease_key, timeout: lease_timeout)
            allow(pool.source_project).to receive(:git_objects_poolable?).and_return(false)

            expect(pool.object_pool).not_to receive(:fetch)

            service.execute
          end

          it 'does not call fetch if pool and project are not on the same storage' do
            stub_exclusive_lease(lease_key, timeout: lease_timeout)
            allow(pool.source_project.repository).to receive(:storage).and_return('special_storage_001')

            expect(pool.object_pool).not_to receive(:fetch)

            service.execute
          end

          context 'when visibility level of the project' do
            before do
              allow(pool.source_project).to receive(:repository_access_level).and_return(ProjectFeature::ENABLED)
            end

            context 'is private' do
              it 'does not call fetch' do
                allow(pool.source_project).to receive(:visibility_level).and_return(Gitlab::VisibilityLevel::PRIVATE)
                expect(pool.object_pool).not_to receive(:fetch)

                service.execute
              end
            end

            context 'is public' do
              it 'calls fetch' do
                allow(pool.source_project).to receive(:visibility_level).and_return(Gitlab::VisibilityLevel::PUBLIC)
                expect(pool.object_pool).to receive(:fetch)

                service.execute
              end
            end

            context 'is internal' do
              it 'calls fetch' do
                allow(pool.source_project).to receive(:visibility_level).and_return(Gitlab::VisibilityLevel::INTERNAL)
                expect(pool.object_pool).to receive(:fetch)

                service.execute
              end
            end
          end

          context 'when the repository access level' do
            before do
              allow(pool.source_project).to receive(:visibility_level).and_return(Gitlab::VisibilityLevel::PUBLIC)
            end

            context 'is private' do
              it 'does not call fetch' do
                allow(pool.source_project).to receive(:repository_access_level).and_return(ProjectFeature::PRIVATE)

                expect(pool.object_pool).not_to receive(:fetch)

                service.execute
              end
            end

            context 'is greater than private' do
              it 'calls fetch' do
                allow(pool.source_project).to receive(:repository_access_level).and_return(ProjectFeature::PUBLIC)

                expect(pool.object_pool).to receive(:fetch)

                service.execute
              end
            end
          end
        end

        it 'links the repository to the object pool' do
          expect(project).to receive(:link_pool_repository)

          service.execute
        end

        it 'does not link the repository to the object pool if they are not on the same storage' do
          allow(project.repository).to receive(:storage).and_return('special_storage_001')
          expect(project).not_to receive(:link_pool_repository)

          service.execute
        end
      end

      context 'when a lease is already out' do
        before do
          stub_exclusive_lease_taken(lease_key, timeout: lease_timeout)
        end

        it 'fails when a lease is already out' do
          expect(Gitlab::AppJsonLogger).to receive(:error).with({ message: "Cannot obtain an exclusive lease. There must be another instance already in execution.", lease_key: lease_key, class_name: described_class.name, lease_timeout: lease_timeout })

          service.execute
        end
      end
    end
  end
end


Instruction:
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
    }.freeze

    def execute
      return unless project

      Gitlab::AppLogger.info("Updating statistics for project #{project.id}")

      expire_repository_caches
      expire_wiki_caches
      project.statistics.refresh!(only: statistics)
    end

    private

    def expire_repository_caches
      if statistics.empty?
        project.repository.expire_statistics_caches
      elsif method_caches_to_expire.present?
        project.repository.expire_method_caches(method_caches_to_expire)
      end
    end

    def expire_wiki_caches
      return unless project.wiki_enabled? && statistics.include?(:wiki_size)

      project.wiki.repository.expire_method_caches([:size])
    end

    def method_caches_to_expire
      strong_memoize(:method_caches_to_expire) do
        statistics.flat_map { |stat| STAT_TO_CACHED_METHOD[stat] }.compact
      end
    end

    def statistics
      strong_memoize(:statistics) do
        params[:statistics]&.map(&:to_sym)
      end
    end
  end
end

```

Response:
# 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] }

  describe '#execute' do
    context 'with a non-existing project' do
      let(:project) { nil }

      it 'does nothing' do
        expect_any_instance_of(ProjectStatistics).not_to receive(:refresh!)

        service.execute
      end
    end

    context 'with an existing project' do
      let_it_be(:project) { create(:project) }

      where(:statistics, :method_caches) do
        []                                                   | %i[size recent_objects_size commit_count]
        ['repository_size']                                  | %i[size recent_objects_size]
        [:repository_size]                                   | %i[size recent_objects_size]
        [:lfs_objects_size]                                  | nil
        [:commit_count]                                      | [:commit_count]
        [:repository_size, :commit_count]                    | %i[size recent_objects_size commit_count]
        [:repository_size, :commit_count, :lfs_objects_size] | %i[size recent_objects_size commit_count]
      end

      with_them do
        it 'refreshes the project statistics' do
          expect(project.statistics).to receive(:refresh!).with(only: statistics.map(&:to_sym)).and_call_original

          service.execute
        end

        it 'invalidates the method caches after a refresh' do
          expect(project.wiki.repository).not_to receive(:expire_method_caches)

          if method_caches.present?
            expect(project.repository).to receive(:expire_method_caches).with(method_caches).and_call_original
          else
            expect(project.repository).not_to receive(:expire_method_caches)
          end

          service.execute
        end
      end
    end

    context 'with an existing project with a Wiki' do
      let(:project) { create(:project, :repository, :wiki_enabled) }
      let(:statistics) { [:wiki_size] }

      it 'invalidates and refreshes Wiki size' do
        expect(project.statistics).to receive(:refresh!).with(only: statistics).and_call_original
        expect(project.wiki.repository).to receive(:expire_method_caches).with(%i[size]).and_call_original

        service.execute
      end
    end
  end
end


Instruction:
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
    # underlying logic changes. This removes the need for explicitly flushing
    # all caches.
    VERSION = 1

    attr_reader :project

    def initialize(project)
      @project = project
    end

    def relation_for_count
      self.class.query(@project.id)
    end

    def cache_key_name
      raise(
        NotImplementedError,
        '"cache_key_name" must be implemented and return a String'
      )
    end

    def cache_key(key = nil)
      cache_key = key || cache_key_name

      ['projects', 'count_service', VERSION, @project.id, cache_key]
    end

    def self.query(project_ids)
      raise(
        NotImplementedError,
        '"query" must be implemented and return an ActiveRecord::Relation'
      )
    end
  end
end

```

Response:
# 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.query(project.id) }.to raise_error(NotImplementedError)
    end
  end

  describe '#relation_for_count' do
    it 'calls the class method query with the project id' do
      expect(described_class).to receive(:query).with(project.id)

      service.relation_for_count
    end
  end

  describe '#count' do
    before do
      allow(service).to receive(:cache_key_name).and_return('count_service')
    end

    it 'returns the number of rows' do
      allow(service).to receive(:uncached_count).and_return(1)

      expect(service.count).to eq(1)
    end

    it 'caches the number of rows', :use_clean_rails_memory_store_caching do
      expect(service).to receive(:uncached_count).once.and_return(1)

      2.times do
        expect(service.count).to eq(1)
      end
    end
  end

  describe '#refresh_cache', :use_clean_rails_memory_store_caching do
    before do
      allow(service).to receive(:cache_key_name).and_return('count_service')
    end

    it 'refreshes the cache' do
      expect(service).to receive(:uncached_count).once.and_return(1)

      service.refresh_cache

      expect(service.count).to eq(1)
    end
  end

  describe '#delete_cache', :use_clean_rails_memory_store_caching do
    before do
      allow(service).to receive(:cache_key_name).and_return('count_service')
    end

    it 'removes the cache' do
      expect(service).to receive(:uncached_count).twice.and_return(1)

      service.count
      service.delete_cache
      service.count
    end
  end

  describe '#cache_key_name' do
    it 'raises NotImplementedError' do
      expect { service.cache_key_name }.to raise_error(NotImplementedError)
    end
  end

  describe '#cache_key' do
    it 'returns the cache key as an Array' do
      allow(service).to receive(:cache_key_name).and_return('foo')
      expect(service.cache_key).to eq(['projects', 'count_service', described_class::VERSION, 1, 'foo'])
    end
  end
end


Instruction:
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 case it isn't
      # we want to make sure it's generated. Otherwise we might delete keys.
      ensure_sha256_fingerprints

      Project.transaction do
        move_deploy_keys_projects
        remove_remaining_deploy_keys_projects if remove_remaining_elements

        success
      end
    end

    private

    def ensure_sha256_fingerprints
      @project.deploy_keys.each(&:ensure_sha256_fingerprint!)
      source_project.deploy_keys.each(&:ensure_sha256_fingerprint!)
    end

    def move_deploy_keys_projects
      non_existent_deploy_keys_projects.update_all(project_id: @project.id)
    end

    # rubocop: disable CodeReuse/ActiveRecord
    def non_existent_deploy_keys_projects
      source_project.deploy_keys_projects
                    .joins(:deploy_key)
                    .where.not(keys: { fingerprint_sha256: @project.deploy_keys.select(:fingerprint_sha256) })
    end
    # rubocop: enable CodeReuse/ActiveRecord

    def remove_remaining_deploy_keys_projects
      source_project.deploy_keys_projects.destroy_all # rubocop: disable Cop/DestroyAll
    end
  end
end

```

Response:
# 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: user.namespace) }

  subject { described_class.new(target_project, user) }

  describe '#execute' do
    before do
      create_list(:deploy_keys_project, 2, project: project_with_deploy_keys)
    end

    it 'moves the user\'s deploy keys from one project to another' do
      expect(project_with_deploy_keys.deploy_keys_projects.count).to eq 2
      expect(target_project.deploy_keys_projects.count).to eq 0

      subject.execute(project_with_deploy_keys)

      expect(project_with_deploy_keys.deploy_keys_projects.count).to eq 0
      expect(target_project.deploy_keys_projects.count).to eq 2
    end

    it 'does not link existent deploy_keys in the current project' do
      target_project.deploy_keys << project_with_deploy_keys.deploy_keys.first

      expect(project_with_deploy_keys.deploy_keys_projects.count).to eq 2
      expect(target_project.deploy_keys_projects.count).to eq 1

      subject.execute(project_with_deploy_keys)

      expect(project_with_deploy_keys.deploy_keys_projects.count).to eq 0
      expect(target_project.deploy_keys_projects.count).to eq 2
    end

    it 'rollbacks changes if transaction fails' do
      allow(subject).to receive(:success).and_raise(StandardError)

      expect { subject.execute(project_with_deploy_keys) }.to raise_error(StandardError)

      expect(project_with_deploy_keys.deploy_keys_projects.count).to eq 2
      expect(target_project.deploy_keys_projects.count).to eq 0
    end

    context 'when remove_remaining_elements is false' do
      let(:options) { { remove_remaining_elements: false } }

      it 'does not remove remaining deploy keys projects' do
        target_project.deploy_keys << project_with_deploy_keys.deploy_keys.first

        subject.execute(project_with_deploy_keys, **options)

        expect(project_with_deploy_keys.deploy_keys_projects.count).not_to eq 0
      end
    end

    context 'when SHA256 fingerprint is missing' do
      before do
        create(:deploy_keys_project, project: target_project)
        DeployKey.all.update_all(fingerprint_sha256: nil)
      end

      it 'moves the user\'s deploy keys from one project to another' do
        combined_keys = project_with_deploy_keys.deploy_keys + target_project.deploy_keys

        subject.execute(project_with_deploy_keys)

        expect(project_with_deploy_keys.deploy_keys.reload).to be_empty
        expect(target_project.deploy_keys.reload).to match_array(combined_keys)
        expect(DeployKey.all.select(:fingerprint_sha256)).to all(be_present)
      end
    end
  end
end


Instruction:
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
      detection = Gitlab::LanguageDetection.new(repository, repository_languages)

      matching_programming_languages = ensure_programming_languages(detection)

      RepositoryLanguage.transaction do
        RepositoryLanguage.where(project_id: project.id, programming_language_id: detection.deletions).delete_all

        detection.updates.each do |update|
          RepositoryLanguage
            .where(project_id: project.id)
            .where(programming_language_id: update[:programming_language_id])
            .update_all(share: update[:share])
        end

        ApplicationRecord.legacy_bulk_insert( # rubocop:disable Gitlab/BulkInsert
          RepositoryLanguage.table_name,
          detection.insertions(matching_programming_languages)
        )

        set_detected_repository_languages
      end

      project.repository_languages.reset
    end
    # rubocop: enable CodeReuse/ActiveRecord

    private

    # rubocop: disable CodeReuse/ActiveRecord
    def ensure_programming_languages(detection)
      existing_languages = ProgrammingLanguage.where(name: detection.languages)
      return existing_languages if detection.languages.size == existing_languages.size

      missing_languages = detection.languages - existing_languages.map(&:name)
      created_languages = missing_languages.map do |name|
        create_language(name, detection.language_color(name))
      end

      existing_languages + created_languages
    end
    # rubocop: enable CodeReuse/ActiveRecord

    # rubocop: disable CodeReuse/ActiveRecord
    def create_language(name, color)
      ProgrammingLanguage.transaction do
        ProgrammingLanguage.where(name: name).first_or_create(color: color)
      end
    rescue ActiveRecord::RecordNotUnique
      retry
    end
    # rubocop: enable CodeReuse/ActiveRecord

    def set_detected_repository_languages
      return if project.detected_repository_languages?

      project.update_column(:detected_repository_languages, true)
    end
  end
end

```

Response:
# 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 '#execute' do
    context 'without previous detection' do
      it 'inserts new programming languages in the database' do
        subject.execute

        expect(ProgrammingLanguage.exists?(name: 'Ruby')).to be(true)
        expect(ProgrammingLanguage.count).to be(4)
      end

      it 'inserts the repository langauges' do
        names = subject.execute.map(&:name)

        expect(names).to eq(%w[Ruby JavaScript HTML CoffeeScript])
      end

      it 'updates detected_repository_languages flag' do
        expect { subject.execute }.to change(project, :detected_repository_languages).to(true)
      end
    end

    context 'with a previous detection' do
      before do
        subject.execute

        allow(project.repository).to receive(:languages).and_return(
          [{ value: 99.63, label: "Ruby", color: "#701516", highlight: "#701516" },
           { value: 0.3, label: "D", color: "#701516", highlight: "#701516" }]
        )
      end

      it 'updates the repository languages' do
        repository_languages = subject.execute.map(&:name)

        expect(repository_languages).to eq(%w[Ruby D])
      end

      it "doesn't touch detected_repository_languages flag" do
        expect(project).not_to receive(:update_column).with(:detected_repository_languages, true)

        subject.execute
      end
    end

    context 'when no repository exists' do
      let_it_be(:project) { create(:project) }

      it 'has no languages' do
        expect(subject.execute).to be_empty
        expect(project.repository_languages).to be_empty
      end
    end
  end
end