INSTRUCTION stringlengths 202 35.5k | RESPONSE stringlengths 75 161k |
|---|---|
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module Projects
module ContainerRepository
module Gitlab
class CleanupTagsService < CleanupTagsBaseService
include ::Projects::ContainerRepository::Gitlab::Timeoutable
TAGS_PAGE_SIZE = 1000
def in... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe Projects::ContainerRepository::Gitlab::CleanupTagsService, feature_category: :container_registry do
using RSpec::Parameterized::TableSyntax
include_context 'for a cleanup tags service'
let_it_be(:user) { create(:user) }
let_it_be(:user) { cr... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module Projects
module ContainerRepository
module ThirdParty
class DeleteTagsService
include BaseServiceUtility
def initialize(container_repository, tag_names)
@container_repository = container_r... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe Projects::ContainerRepository::ThirdParty::DeleteTagsService, feature_category: :container_registry do
include_context 'container repository delete tags service shared context'
let(:service) { described_class.new(repository, tags) }
describe '... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module Projects
module ContainerRepository
module ThirdParty
class CleanupTagsService < CleanupTagsBaseService
def initialize(container_repository:, current_user: nil, params: {})
super
@params... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe Projects::ContainerRepository::ThirdParty::CleanupTagsService, :clean_gitlab_redis_cache, feature_category: :container_registry do
using RSpec::Parameterized::TableSyntax
include_context 'for a cleanup tags service'
let_it_be(:user) { create(:... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module Projects
module GroupLinks
class DestroyService < BaseService
def execute(group_link, skip_authorization: false)
unless valid_to_destroy?(group_link, skip_authorization)
return ServiceResponse.erro... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe Projects::GroupLinks::DestroyService, '#execute', feature_category: :groups_and_projects do
let_it_be(:user) { create :user }
let_it_be(:project) { create(:project, :private) }
let_it_be(:group) { create(:group) }
let_it_be(:group_user) { crea... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module Projects
module GroupLinks
class UpdateService < BaseService
def initialize(group_link, user = nil)
super(group_link.project, user)
@group_link = group_link
end
def execute(group_link_p... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe Projects::GroupLinks::UpdateService, '#execute', feature_category: :groups_and_projects do
let_it_be(:user) { create :user }
let_it_be(:group) { create :group }
let_it_be(:project) { create :project }
let_it_be(:group_user) { create(:user).tap... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module Projects
module GroupLinks
class CreateService < BaseService
include GroupLinkable
def initialize(project, shared_with_group, user, params)
@shared_with_group = shared_with_group
super(projec... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe Projects::GroupLinks::CreateService, '#execute', feature_category: :groups_and_projects do
let_it_be(:user) { create :user }
let_it_be(:group) { create :group }
let_it_be(:project) { create(:project, namespace: create(:namespace, :with_namespace... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module Projects
module ImportExport
class ExportService < BaseService
def initialize(*args)
super
@shared = project.import_export_shared
@logger = Gitlab::Export::Logger.build
end
def ... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe Projects::ImportExport::ExportService, feature_category: :importers do
describe '#execute' do
let_it_be(:user) { create(:user) }
let_it_be(:group) { create(:group) }
let_it_be_with_reload(:project) { create(:project, group: group) }
... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module Projects
module ImportExport
class ParallelExportService
def initialize(export_job, current_user, after_export_strategy)
@export_job = export_job
@current_user = current_user
@after_export_st... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe Projects::ImportExport::ParallelExportService, feature_category: :importers do
let_it_be(:user) { create(:user) }
let(:export_job) { create(:project_export_job) }
let(:after_export_strategy) { Gitlab::ImportExport::AfterExportStrategies::Downlo... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module Projects
module ImportExport
class RelationExportService
include Gitlab::ImportExport::CommandLineUtil
def initialize(relation_export, jid)
@relation_export = relation_export
@jid = jid
... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe Projects::ImportExport::RelationExportService, feature_category: :importers do
using RSpec::Parameterized::TableSyntax
subject(:service) { described_class.new(relation_export, 'jid') }
let_it_be(:project_export_job) { create(:project_export_jo... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module Projects
module HashedStorage
class MigrateAttachmentsService < BaseAttachmentService
extend ::Gitlab::Utils::Override
# List of paths that can be excluded while evaluation if a target can be discarded
... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe Projects::HashedStorage::MigrateAttachmentsService, feature_category: :groups_and_projects do
subject(:service) { described_class.new(project: project, old_disk_path: project.full_path, logger: nil) }
let(:project) { create(:project, :repository,... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module Projects
module HashedStorage
AttachmentMigrationError = Class.new(StandardError)
AttachmentCannotMoveError = Class.new(StandardError)
class BaseAttachmentService < BaseService
# Returns the disk_path valu... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe Projects::HashedStorage::BaseAttachmentService, feature_category: :groups_and_projects do
let(:project) { create(:project, :repository, storage_version: 0, skip_disk_validation: true) }
subject(:service) { described_class.new(project: project, ol... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module Projects
module HashedStorage
class MigrationService < BaseService
attr_reader :logger, :old_disk_path
def initialize(project, old_disk_path, logger: nil)
@project = project
@old_disk_path = o... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe Projects::HashedStorage::MigrationService, feature_category: :groups_and_projects do
let(:project) { create(:project, :empty_repo, :wiki_repo, :legacy_storage) }
let(:logger) { double }
let!(:project_attachment) { build(:file_uploader, project: ... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module Projects
module Operations
class UpdateService < BaseService
def execute
Projects::UpdateService
.new(project, current_user, project_update_params)
.execute
end
private
... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe Projects::Operations::UpdateService, feature_category: :groups_and_projects do
let_it_be_with_refind(:project) { create(:project) }
let_it_be(:user) { create(:user) }
let(:result) { subject.execute }
subject { described_class.new(project, us... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module Projects
module AutoDevops
class DisableService < BaseService
def execute
return false unless implicitly_enabled_and_first_pipeline_failure?
disable_auto_devops
end
private
def i... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe Projects::AutoDevops::DisableService, '#execute', feature_category: :auto_devops do
let(:project) { create(:project, :repository, :auto_devops) }
let(:auto_devops) { project.auto_devops }
subject { described_class.new(project).execute }
conte... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module Projects
module DeployTokens
class DestroyService < BaseService
include DeployTokenMethods
def execute
destroy_deploy_token(@project, params)
end
end
end
end
Projects::DeployTokens::Destr... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe Projects::DeployTokens::DestroyService, feature_category: :continuous_delivery do
it_behaves_like 'a deploy token deletion service' do
let_it_be(:entity) { create(:project) }
let_it_be(:deploy_token_class) { ProjectDeployToken }
let_it_b... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module Projects
module DeployTokens
class CreateService < BaseService
include DeployTokenMethods
def execute
deploy_token = create_deploy_token_for(@project, current_user, params)
create_deploy_toke... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe Projects::DeployTokens::CreateService, feature_category: :continuous_delivery do
it_behaves_like 'a deploy token creation service' do
let(:entity) { create(:project) }
let(:deploy_token_class) { ProjectDeployToken }
end
end
|
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module Projects
module Forks
# A service for fetching upstream default branch and merging it to the fork's specified branch.
class SyncService < BaseService
ONGOING_MERGE_ERROR = 'The synchronization did not happen due... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe Projects::Forks::SyncService, feature_category: :source_code_management do
include ProjectForksHelper
include RepoHelpers
let_it_be(:user) { create(:user) }
let_it_be(:source_project) { create(:project, :repository, :public) }
let_it_be(:pr... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module Projects
module Prometheus
module Metrics
class DestroyService < Metrics::BaseService
def execute
metric.destroy
end
end
end
end
end
``` | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe Projects::Prometheus::Metrics::DestroyService, feature_category: :metrics do
let(:metric) { create(:prometheus_metric) }
subject { described_class.new(metric) }
it 'destroys metric' do
subject.execute
expect(PrometheusMetric.find_by(i... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module Projects
module Prometheus
module Alerts
class NotifyService < ::BaseProjectService
include Gitlab::Utils::StrongMemoize
include ::AlertManagement::Responses
# This set of keys identifies a ... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe Projects::Prometheus::Alerts::NotifyService, feature_category: :incident_management do
include PrometheusHelpers
using RSpec::Parameterized::TableSyntax
let_it_be_with_reload(:project) { create(:project) }
let_it_be_with_refind(:setting) do
... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
# This service yields operation on each download link from a remote source based on the
# oids provided
module Projects
module LfsPointers
class LfsDownloadLinkListService < BaseService
DOWNLOAD_ACTION = 'download'
... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe Projects::LfsPointers::LfsDownloadLinkListService, feature_category: :source_code_management do
let(:import_url) { 'http://www.gitlab.com/demo/repo.git' }
let(:lfs_endpoint) { "#{import_url}/info/lfs/objects/batch" }
let!(:project) { create(:proj... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
# This service is responsible of managing the retrieval of the lfs objects,
# and call the service LfsDownloadService, which performs the download
# for each of the retrieved lfs objects
module Projects
module LfsPointers
class ... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe Projects::LfsPointers::LfsImportService, feature_category: :source_code_management do
let(:project) { create(:project) }
let(:user) { project.creator }
let(:import_url) { 'http://www.gitlab.com/demo/repo.git' }
let(:oid_download_links) do
[... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
# Given a list of oids, this services links the existent Lfs Objects to the project
module Projects
module LfsPointers
class LfsLinkService < BaseService
TooManyOidsError = Class.new(StandardError)
MAX_OIDS = ENV.fe... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe Projects::LfsPointers::LfsLinkService, feature_category: :source_code_management do
let_it_be(:project) { create(:project, lfs_enabled: true) }
let_it_be(:lfs_objects_project) { create_list(:lfs_objects_project, 2, project: project) }
let(:new_o... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
# This service downloads and links lfs objects from a remote URL
module Projects
module LfsPointers
class LfsDownloadService < BaseService
SizeError = Class.new(StandardError)
OidError = Class.new(StandardError)
... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe Projects::LfsPointers::LfsDownloadService, feature_category: :source_code_management do
include StubRequests
let_it_be(:project) { create(:project) }
let(:lfs_content) { SecureRandom.random_bytes(10) }
let(:oid) { Digest::SHA256.hexdigest(lfs... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
# This service discovers the Lfs files that are linked in repository,
# but not downloaded yet and yields the operation
# on each Lfs file link (url) to remote repository.
module Projects
module LfsPointers
class LfsObjectDownlo... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe Projects::LfsPointers::LfsObjectDownloadListService, feature_category: :source_code_management do
let(:import_url) { 'http://www.gitlab.com/demo/repo.git' }
let(:default_endpoint) { "#{import_url}/info/lfs/objects/batch" }
let(:group) { create(:g... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module Emails
class ConfirmService < ::Emails::BaseService
def execute(email)
email.resend_confirmation_instructions
end
end
end
Emails::ConfirmService.prepend_mod
``` | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe Emails::ConfirmService, feature_category: :user_management do
let_it_be(:user) { create(:user) }
subject(:service) { described_class.new(user) }
describe '#execute' do
it 'enqueues a background job to send confirmation email again' do
... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module Emails
class DestroyService < ::Emails::BaseService
def execute(email)
raise StandardError, 'Cannot delete primary email' if email.user_primary_email?
email.destroy && update_secondary_emails!(email.email)
... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe Emails::DestroyService, feature_category: :user_management do
let!(:user) { create(:user) }
let!(:email) { create(:email, user: user) }
subject(:service) { described_class.new(user, user: user) }
describe '#execute' do
it 'removes an ema... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module Emails
class CreateService < ::Emails::BaseService
def execute(extra_params = {})
skip_confirmation = params.delete(:skip_confirmation)
user.emails.create(params.merge(extra_params)).tap do |email|
em... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe Emails::CreateService, feature_category: :user_management do
let_it_be(:user) { create(:user) }
let(:opts) { { email: 'new@email.com', user: user } }
subject(:service) { described_class.new(user, opts) }
describe '#execute' do
it 'creat... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module TwoFactor
class DestroyService < ::TwoFactor::BaseService
def execute
return error(_('You are not authorized to perform this action')) unless authorized?
return error(_('Two-factor authentication is not enable... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe TwoFactor::DestroyService, feature_category: :system_access do
let_it_be(:current_user) { create(:user) }
subject { described_class.new(current_user, user: user).execute }
context 'disabling two-factor authentication' do
shared_examples_fo... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module Wikis
class CreateAttachmentService < Files::CreateService
ATTACHMENT_PATH = 'uploads'
MAX_FILENAME_LENGTH = 255
attr_reader :container
delegate :wiki, to: :container
delegate :repository, to: :wiki
... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe Wikis::CreateAttachmentService, feature_category: :wiki do
let(:container) { create(:project, :wiki_repo) }
let(:user) { create(:user) }
let(:file_name) { 'filename.txt' }
let(:file_path_regex) { %r{#{described_class::ATTACHMENT_PATH}/\h{32}/#{... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module Clusters
module Kubernetes
GITLAB_SERVICE_ACCOUNT_NAME = 'gitlab'
GITLAB_SERVICE_ACCOUNT_NAMESPACE = 'default'
GITLAB_ADMIN_TOKEN_NAME = 'gitlab-token'
GITLAB_CLUSTER_ROLE_BINDING_NAME = 'gitlab-admin'
GIT... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe Clusters::Kubernetes, feature_category: :deployment_management do
it { is_expected.to be_const_defined(:GITLAB_SERVICE_ACCOUNT_NAME) }
it { is_expected.to be_const_defined(:GITLAB_SERVICE_ACCOUNT_NAMESPACE) }
it { is_expected.to be_const_defined... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module Clusters
class BuildService
def initialize(subject)
@subject = subject
end
def execute
::Clusters::Cluster.new.tap do |cluster|
case @subject
when ::Project
cluster.cluster_ty... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe Clusters::BuildService, feature_category: :deployment_management do
describe '#execute' do
subject { described_class.new(cluster_subject).execute }
describe 'when cluster subject is a project' do
let(:cluster_subject) { build(:project... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module Clusters
class BuildKubernetesNamespaceService
attr_reader :cluster, :environment
def initialize(cluster, environment:)
@cluster = cluster
@environment = environment
end
def execute
cluster... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe Clusters::BuildKubernetesNamespaceService, feature_category: :deployment_management do
let(:cluster) { create(:cluster, :project, :provided_by_gcp) }
let(:environment) { create(:environment) }
let(:project) { environment.project }
let(:namesp... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module Clusters
class DestroyService
attr_reader :current_user, :params
def initialize(user = nil, params = {})
@current_user = user
@params = params.dup
@response = {}
end
def execute(cluster)
... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe Clusters::DestroyService, feature_category: :deployment_management do
describe '#execute' do
subject { described_class.new(cluster.user, params).execute(cluster) }
let!(:cluster) { create(:cluster, :project, :provided_by_user) }
contex... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module Clusters
class UpdateService
attr_reader :current_user, :params
def initialize(user = nil, params = {})
@current_user = user
@params = params.dup
end
def execute(cluster)
if validate_params... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe Clusters::UpdateService, feature_category: :deployment_management do
include KubernetesHelpers
describe '#execute' do
subject { described_class.new(cluster.user, params).execute(cluster) }
let(:cluster) { create(:cluster, :project, :prov... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module Clusters
class CreateService
attr_reader :current_user, :params
def initialize(user = nil, params = {})
@current_user = user
@params = params.dup
end
def execute(access_token: nil)
raise Ar... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe Clusters::CreateService, feature_category: :deployment_management do
let(:access_token) { 'xxx' }
let(:project) { create(:project) }
let(:user) { create(:user) }
subject { described_class.new(user, params).execute(access_token: access_token) ... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module Clusters
module Management
class ValidateManagementProjectPermissionsService
attr_reader :current_user
def initialize(user = nil)
@current_user = user
end
def execute(cluster, management_... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe Clusters::Management::ValidateManagementProjectPermissionsService, feature_category: :deployment_management do
describe '#execute' do
subject { described_class.new(user).execute(cluster, management_project_id) }
let(:cluster) { build(:clust... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module Clusters
module Agents
class CreateActivityEventService
def initialize(agent, **params)
@agent = agent
@params = params
end
def execute
agent.activity_events.create!(params)
... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe Clusters::Agents::CreateActivityEventService, feature_category: :deployment_management do
let_it_be(:agent) { create(:cluster_agent) }
let_it_be(:token) { create(:cluster_agent_token, agent: agent) }
let_it_be(:user) { create(:user) }
describ... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module Clusters
module Agents
class AuthorizeProxyUserService < ::BaseService
include ::Gitlab::Utils::StrongMemoize
def initialize(current_user, agent)
@current_user = current_user
@agent = agent
... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe Clusters::Agents::AuthorizeProxyUserService, feature_category: :deployment_management do
subject(:service_response) { service.execute }
let(:service) { described_class.new(user, agent) }
let(:user) { create(:user) }
let_it_be(:organization) ... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module Clusters
module Agents
class DeleteExpiredEventsService
def initialize(agent)
@agent = agent
end
def execute
agent.activity_events
.recorded_before(remove_events_before)
... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe Clusters::Agents::DeleteExpiredEventsService, feature_category: :deployment_management do
let_it_be(:agent) { create(:cluster_agent) }
describe '#execute' do
let_it_be(:event1) { create(:agent_activity_event, agent: agent, recorded_at: 1.hour... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module Clusters
module Agents
class CreateService < BaseService
def execute(name:)
return error_no_permissions unless cluster_agent_permissions?
agent = ::Clusters::Agent.new(name: name, project: project, ... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe Clusters::Agents::CreateService, feature_category: :deployment_management do
subject(:service) { described_class.new(project, user) }
let(:project) { create(:project, :public, :repository) }
let(:user) { create(:user) }
describe '#execute' d... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module Clusters
module Agents
class DeleteService < ::BaseContainerService
def execute(cluster_agent)
return error_no_permissions unless current_user.can?(:admin_cluster, cluster_agent)
if cluster_agent.de... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe Clusters::Agents::DeleteService, feature_category: :deployment_management do
subject(:service) { described_class.new(container: project, current_user: user) }
let(:cluster_agent) { create(:cluster_agent) }
let(:project) { cluster_agent.project ... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module Clusters
module Agents
module Authorizations
module UserAccess
class RefreshService
include Gitlab::Utils::StrongMemoize
AUTHORIZED_ENTITY_LIMIT = 100
delegate :project, to: :... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe Clusters::Agents::Authorizations::UserAccess::RefreshService, feature_category: :deployment_management do
describe '#execute' do
let_it_be(:root_ancestor) { create(:group) }
let_it_be(:agent_management_project) { create(:project, namespace: ... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module Clusters
module Agents
module Authorizations
module CiAccess
class FilterService
def initialize(authorizations, filter_params)
@authorizations = authorizations
@filter_param... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe Clusters::Agents::Authorizations::CiAccess::FilterService, feature_category: :continuous_integration do
describe '#execute' do
let_it_be(:group) { create(:group) }
let_it_be(:project) { create(:project, group: group) }
let(:agent_author... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module Clusters
module Agents
module Authorizations
module CiAccess
class RefreshService
include Gitlab::Utils::StrongMemoize
AUTHORIZED_ENTITY_LIMIT = 100
delegate :project, to: :ag... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe Clusters::Agents::Authorizations::CiAccess::RefreshService, feature_category: :deployment_management do
describe '#execute' do
let_it_be(:root_ancestor) { create(:group) }
let_it_be(:removed_group) { create(:group, parent: root_ancestor) }
... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module Clusters
module Integrations
class CreateService < BaseContainerService
attr_accessor :cluster
def initialize(container:, cluster:, current_user: nil, params: {})
@cluster = cluster
super(con... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe Clusters::Integrations::CreateService, '#execute', feature_category: :deployment_management do
let_it_be(:project) { create(:project) }
let_it_be_with_reload(:cluster) { create(:cluster, :provided_by_gcp, projects: [project]) }
let(:service) do... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module Clusters
module Cleanup
class ProjectNamespaceService < ::Clusters::Cleanup::BaseService
KUBERNETES_NAMESPACE_BATCH_SIZE = 100
def execute
delete_project_namespaces_in_batches
# Keep calling ... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe Clusters::Cleanup::ProjectNamespaceService, feature_category: :deployment_management do
describe '#execute' do
subject { service.execute }
let!(:service) { described_class.new(cluster) }
let!(:cluster) { create(:cluster, :with_environme... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module Clusters
module Cleanup
class ServiceAccountService < ::Clusters::Cleanup::BaseService
def execute
delete_gitlab_service_account
log_event(:destroying_cluster)
cluster.destroy!
end
... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe Clusters::Cleanup::ServiceAccountService, feature_category: :deployment_management do
describe '#execute' do
subject { service.execute }
let!(:service) { described_class.new(cluster) }
let!(:cluster) { create(:cluster, :cleanup_removing... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module Clusters
module AgentTokens
class TrackUsageService
# The `UPDATE_USED_COLUMN_EVERY` defines how often the token DB entry can be updated
UPDATE_USED_COLUMN_EVERY = (40.minutes..55.minutes)
delegate :age... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe Clusters::AgentTokens::TrackUsageService, feature_category: :deployment_management do
let_it_be(:agent) { create(:cluster_agent) }
describe '#execute', :clean_gitlab_redis_cache do
let(:agent_token) { create(:cluster_agent_token, agent: agent... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module Clusters
module AgentTokens
class RevokeService
attr_reader :current_project, :current_user, :token
def initialize(token:, current_user:)
@token = token
@current_user = current_user
end
... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe Clusters::AgentTokens::RevokeService, feature_category: :deployment_management do
describe '#execute' do
subject { described_class.new(token: agent_token, current_user: user).execute }
let(:agent) { create(:cluster_agent) }
let(:agent_t... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module Clusters
module AgentTokens
class CreateService
ALLOWED_PARAMS = %i[agent_id description name].freeze
ACTIVE_TOKENS_LIMIT = 2
attr_reader :agent, :current_user, :params
def initialize(agent:, cur... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe Clusters::AgentTokens::CreateService, feature_category: :deployment_management do
subject(:service) { described_class.new(agent: cluster_agent, current_user: user, params: params) }
let_it_be(:user) { create(:user) }
let(:cluster_agent) { crea... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module Clusters
module Kubernetes
class FetchKubernetesTokenService
DEFAULT_TOKEN_RETRY_DELAY = 5.seconds
TOKEN_RETRY_LIMIT = 5
attr_reader :kubeclient, :service_account_token_name, :namespace
def initi... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe Clusters::Kubernetes::FetchKubernetesTokenService, feature_category: :deployment_management do
include KubernetesHelpers
describe '#execute' do
let(:api_url) { 'http://111.111.111.111' }
let(:namespace) { 'my-namespace' }
let(:service... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module Clusters
module Kubernetes
class CreateOrUpdateServiceAccountService
def initialize(kubeclient, service_account_name:, service_account_namespace:, token_name:, rbac:, service_account_namespace_labels: nil, namespace... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe Clusters::Kubernetes::CreateOrUpdateServiceAccountService, feature_category: :deployment_management do
include KubernetesHelpers
let(:api_url) { 'http://111.111.111.111' }
let(:platform_kubernetes) { cluster.platform_kubernetes }
let(:cluster_... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module Clusters
module Kubernetes
class CreateOrUpdateNamespaceService
def initialize(cluster:, kubernetes_namespace:)
@cluster = cluster
@kubernetes_namespace = kubernetes_namespace
@platform = clu... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe Clusters::Kubernetes::CreateOrUpdateNamespaceService, '#execute', feature_category: :deployment_management do
include KubernetesHelpers
let(:cluster) { create(:cluster, :project, :provided_by_gcp) }
let(:platform) { cluster.platform }
let(:ap... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module CustomerRelations
module Organizations
class UpdateService < BaseService
def execute(organization)
return error_no_permissions unless allowed?
handle_active_param
return error_updating(organ... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe CustomerRelations::Organizations::UpdateService, feature_category: :service_desk do
let_it_be(:user) { create(:user) }
let(:crm_organization) { create(:crm_organization, name: 'Test', group: group, state: 'active') }
subject(:update) { describ... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module CustomerRelations
module Organizations
class CreateService < BaseService
# returns the created organization
def execute
return error_no_permissions unless allowed?
organization = Organization.... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe CustomerRelations::Organizations::CreateService, feature_category: :service_desk do
describe '#execute' do
let_it_be(:user) { create(:user) }
let(:group) { create(:group, :crm_enabled) }
let(:params) { attributes_for(:crm_organization, ... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module CustomerRelations
module Contacts
class UpdateService < BaseService
def execute(contact)
return error_no_permissions unless allowed?
handle_active_param
return error_organization_invalid unl... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe CustomerRelations::Contacts::UpdateService, feature_category: :service_desk do
let_it_be(:user) { create(:user) }
let(:contact) { create(:contact, first_name: 'Mark', group: group, state: 'active') }
subject(:update) { described_class.new(grou... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module CustomerRelations
module Contacts
class CreateService < BaseService
def execute
return error_no_permissions unless allowed?
return error_organization_invalid unless organization_valid?
conta... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe CustomerRelations::Contacts::CreateService, feature_category: :service_desk do
describe '#execute' do
let_it_be(:user) { create(:user) }
let_it_be(:not_found_or_does_not_belong) { 'The specified organization was not found or does not belong ... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module Admin
class SetFeatureFlagService
UnknownOperationError = Class.new(StandardError)
def initialize(feature_flag_name:, params:)
@name = feature_flag_name
@target = Feature::Target.new(params)
@params... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe Admin::SetFeatureFlagService, feature_category: :feature_flags do
let_it_be(:user) { create(:user) }
let_it_be(:project) { create(:project) }
let_it_be(:group) { create(:group) }
let(:feature_name) { known_feature_flag.name }
let(:service) ... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module Admin
module AbuseReportLabels
class CreateService < Labels::BaseService
def initialize(params = {})
@params = params
end
def execute
params[:color] = convert_color_name_to_hex if params... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe Admin::AbuseReportLabels::CreateService, feature_category: :insider_threat do
describe '#execute' do
let(:color) { 'red' }
let(:color_in_hex) { ::Gitlab::Color.of(color) }
let(:params) { { title: 'FancyLabel', color: color } }
subje... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module Admin
module AbuseReports
class ModerateUserService < BaseService
attr_reader :abuse_report, :params, :current_user, :action
def initialize(abuse_report, current_user, params)
@abuse_report = abuse_re... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe Admin::AbuseReports::ModerateUserService, feature_category: :instance_resiliency do
let_it_be_with_reload(:abuse_report) { create(:abuse_report) }
let_it_be_with_reload(:similar_abuse_report) do
create(:abuse_report, user: abuse_report.user, c... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module Admin
module AbuseReports
class UpdateService < BaseService
attr_reader :abuse_report, :params, :current_user
def initialize(abuse_report, current_user, params)
@abuse_report = abuse_report
@c... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe Admin::AbuseReports::UpdateService, feature_category: :instance_resiliency do
let_it_be(:current_user) { create(:admin) }
let_it_be(:abuse_report) { create(:abuse_report) }
let_it_be(:label) { create(:abuse_report_label) }
let(:params) { {} }... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module Admin
module PlanLimits
class UpdateService < ::BaseService
def initialize(params = {}, current_user:, plan:)
@current_user = current_user
@params = params
@plan = plan
@plan_limits =... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe Admin::PlanLimits::UpdateService, feature_category: :shared do
let_it_be(:user) { create(:admin) }
let_it_be(:plan) { create(:plan, name: 'free') }
let_it_be(:limits) { plan.actual_limits }
let_it_be(:params) do
{
ci_pipeline_size: 1... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module IncidentManagement
module TimelineEventTags
class CreateService < TimelineEventTags::BaseService
attr_reader :project, :user, :params
def initialize(project, user, params)
@project = project
@... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe IncidentManagement::TimelineEventTags::CreateService, feature_category: :incident_management do
let_it_be(:user_with_permissions) { create(:user) }
let_it_be(:user_without_permissions) { create(:user) }
let_it_be_with_reload(:project) { create(:... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module IncidentManagement
module LinkAlerts
class DestroyService < BaseService
# @param incident [Issue] an incident to unlink alert from
# @param current_user [User]
# @param alert [AlertManagement::Alert] an ... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe IncidentManagement::LinkAlerts::DestroyService, feature_category: :incident_management do
let_it_be(:project) { create(:project) }
let_it_be(:another_project) { create(:project) }
let_it_be(:developer) { create(:user) }
let_it_be(:guest) { cre... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module IncidentManagement
module LinkAlerts
class CreateService < BaseService
# @param incident [Issue] an incident to link alerts
# @param current_user [User]
# @param alert_references [[String]] a list of ale... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe IncidentManagement::LinkAlerts::CreateService, feature_category: :incident_management do
let_it_be(:project) { create(:project) }
let_it_be(:another_project) { create(:project) }
let_it_be(:linked_alert) { create(:alert_management_alert, project... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module IncidentManagement
module TimelineEvents
class DestroyService < TimelineEvents::BaseService
# @param timeline_event [IncidentManagement::TimelineEvent]
# @param user [User]
def initialize(timeline_event,... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe IncidentManagement::TimelineEvents::DestroyService, feature_category: :incident_management do
let_it_be(:user_with_permissions) { create(:user) }
let_it_be(:user_without_permissions) { create(:user) }
let_it_be(:project) { create(:project) }
l... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module IncidentManagement
module TimelineEvents
# @param timeline_event [IncidentManagement::TimelineEvent]
# @param user [User]
# @param params [Hash]
# @option params [string] note
# @option params [datetime] o... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe IncidentManagement::TimelineEvents::UpdateService, feature_category: :incident_management do
let_it_be(:user) { create(:user) }
let_it_be(:project) { create(:project) }
let_it_be(:incident) { create(:incident, project: project) }
let_it_be(:ta... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module IncidentManagement
module TimelineEvents
DEFAULT_ACTION = 'comment'
DEFAULT_EDITABLE = false
DEFAULT_AUTO_CREATED = false
class CreateService < TimelineEvents::BaseService
def initialize(incident, user,... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe IncidentManagement::TimelineEvents::CreateService, feature_category: :incident_management do
let_it_be(:user_with_permissions) { create(:user) }
let_it_be(:user_without_permissions) { create(:user) }
let_it_be(:project) { create(:project) }
le... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module IncidentManagement
module IssuableEscalationStatuses
class AfterUpdateService < ::BaseProjectService
def initialize(issuable, current_user, **params)
@issuable = issuable
@escalation_status = issuabl... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe IncidentManagement::IssuableEscalationStatuses::AfterUpdateService,
feature_category: :incident_management do
let_it_be(:current_user) { create(:user) }
let_it_be(:escalation_status, reload: true) { create(:incident_management_issuable_escalatio... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module IncidentManagement
module IssuableEscalationStatuses
class BuildService < ::BaseProjectService
def initialize(issue)
@issue = issue
super(project: issue.project)
end
def execute
... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe IncidentManagement::IssuableEscalationStatuses::BuildService, feature_category: :incident_management do
let_it_be(:project) { create(:project) }
let_it_be(:incident, reload: true) { create(:incident, project: project) }
let(:service) { describe... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module IncidentManagement
module IssuableEscalationStatuses
class PrepareUpdateService < ::BaseProjectService
include Gitlab::Utils::StrongMemoize
SUPPORTED_PARAMS = %i[status].freeze
def initialize(issuable,... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe IncidentManagement::IssuableEscalationStatuses::PrepareUpdateService, factory_default: :keep,
feature_category: :incident_management do
let_it_be(:project) { create_default(:project) }
let_it_be(:escalation_status) { create(:incident_management_... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module IncidentManagement
module IssuableEscalationStatuses
class CreateService < ::BaseProjectService
def initialize(issue)
@issue = issue
super(project: issue.project)
end
def execute
... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe IncidentManagement::IssuableEscalationStatuses::CreateService, feature_category: :incident_management do
let_it_be(:project) { create(:project) }
let(:incident) { create(:incident, project: project) }
let(:service) { described_class.new(inciden... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module IncidentManagement
module PagerDuty
class ProcessWebhookService < ::BaseProjectService
include Gitlab::Utils::StrongMemoize
include IncidentManagement::Settings
# https://developer.pagerduty.com/docs/we... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe IncidentManagement::PagerDuty::ProcessWebhookService, feature_category: :incident_management do
let_it_be(:project, reload: true) { create(:project) }
describe '#execute' do
shared_examples 'does not process incidents' do
it 'does not p... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module IncidentManagement
module PagerDuty
class CreateIncidentIssueService < BaseService
include IncidentManagement::Settings
def initialize(project, incident_payload)
super(project, Users::Internal.alert_b... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe IncidentManagement::PagerDuty::CreateIncidentIssueService, feature_category: :incident_management do
let_it_be(:project, reload: true) { create(:project) }
let_it_be(:user) { Users::Internal.alert_bot }
let(:webhook_payload) { Gitlab::Json.pars... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module IncidentManagement
module Incidents
class CreateService < ::BaseProjectService
ISSUE_TYPE = 'incident'
def initialize(project, current_user, title:, description:, severity: IssuableSeverity::DEFAULT, alert: n... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe IncidentManagement::Incidents::CreateService, feature_category: :incident_management do
let_it_be(:project) { create(:project) }
let_it_be(:user) { Users::Internal.alert_bot }
let(:description) { 'Incident description' }
describe '#execute' ... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module Labels
class FindOrCreateService
def initialize(current_user, parent, params = {})
@current_user = current_user
@parent = parent
@available_labels = params.delete(:available_labels)
@existing_label... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe Labels::FindOrCreateService, feature_category: :team_planning do
describe '#execute' do
let(:group) { create(:group) }
let(:project) { create(:project, namespace: group) }
let(:params) do
{
title: 'Security',
des... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module Labels
class PromoteService < BaseService
BATCH_SIZE = 1000
# rubocop: disable CodeReuse/ActiveRecord
def execute(label)
return unless project.group &&
label.is_a?(ProjectLabel)
ProjectLabe... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe Labels::PromoteService, feature_category: :team_planning do
describe '#execute' do
let_it_be(:user) { create(:user) }
context 'without a group' do
let!(:project_1) { create(:project) }
let!(:project_label_1_1) { create(:label, ... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
# Labels::TransferService class
#
# User for recreate the missing group labels at project level
#
module Labels
class TransferService
def initialize(current_user, old_group, project)
@current_user = current_user
@old... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe Labels::TransferService, feature_category: :team_planning do
shared_examples 'transfer labels' do
describe '#execute' do
let_it_be(:user) { create(:user) }
let_it_be(:old_group_ancestor) { create(:group) }
let_it_be(:old_group... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module Labels
class AvailableLabelsService
attr_reader :current_user, :parent, :params
def initialize(current_user, parent, params)
@current_user = current_user
@parent = parent
@params = params
end
... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe Labels::AvailableLabelsService, feature_category: :team_planning do
let_it_be(:user) { create(:user) }
let(:project) { create(:project, :public, group: group) }
let(:group) { create(:group) }
let(:project_label) { create(:label, project: proje... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module Labels
class UpdateService < Labels::BaseService
def initialize(params = {})
@params = params.to_h.dup.with_indifferent_access
end
# returns the updated label
def execute(label)
params[:name] = pa... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe Labels::UpdateService, feature_category: :team_planning do
describe '#execute' do
let(:project) { create(:project) }
let(:hex_color) { '#FF0000' }
let(:named_color) { 'red' }
let(:upcase_color) { 'RED' }
let(:spaced_color) { ' r... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module Labels
class CreateService < Labels::BaseService
def initialize(params = {})
@params = params.to_h.dup.with_indifferent_access
end
# returns the created label
def execute(target_params)
params[:co... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe Labels::CreateService, feature_category: :team_planning do
describe '#execute' do
let(:project) { create(:project) }
let(:group) { create(:group) }
let(:hex_color) { '#FF0000' }
let(:named_color) { 'red' }
let(:upcase_color) {... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module IssueEmailParticipants
class CreateService < ::BaseProjectService
MAX_NUMBER_OF_EMAILS = 6
attr_reader :target, :emails
def initialize(target:, current_user:, emails:)
super(project: target.project, curren... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe IssueEmailParticipants::CreateService, feature_category: :service_desk do
shared_examples 'a successful service execution' do
it 'creates new participants', :aggregate_failures do
expect(response).to be_success
issue.reset
not... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module DeployKeys
class CreateService < Keys::BaseService
def execute(project: nil)
DeployKey.create(params.merge(user: user))
end
end
end
DeployKeys::CreateService.prepend_mod_with('DeployKeys::CreateService')
``` | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe DeployKeys::CreateService, feature_category: :continuous_delivery do
let(:user) { create(:user) }
let(:params) { attributes_for(:deploy_key) }
subject { described_class.new(user, params) }
it "creates a deploy key" do
expect { subject.ex... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module Uploads
class DestroyService < BaseService
attr_accessor :model, :current_user
def initialize(model, user = nil)
@model = model
@current_user = user
end
def execute(secret, filename)
upload... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe Uploads::DestroyService, feature_category: :shared do
let_it_be(:project) { create(:project) }
let_it_be(:user) { create(:user) }
let_it_be_with_reload(:upload) { create(:upload, :issuable_upload, model: project) }
let(:filename) { File.basen... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module ResourceAccessTokens
class RevokeService < BaseService
include Gitlab::Utils::StrongMemoize
RevokeAccessTokenError = Class.new(RuntimeError)
def initialize(current_user, resource, access_token)
@current_us... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe ResourceAccessTokens::RevokeService, feature_category: :system_access do
subject { described_class.new(user, resource, access_token).execute }
let_it_be(:user) { create(:user) }
let_it_be(:user_non_priviledged) { create(:user) }
let_it_be(:re... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module ResourceAccessTokens
class CreateService < BaseService
include Gitlab::Utils::StrongMemoize
def initialize(current_user, resource, params = {})
@resource_type = resource.class.name.downcase
@resource = re... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe ResourceAccessTokens::CreateService, feature_category: :system_access do
subject { described_class.new(user, resource, params).execute }
let_it_be(:user) { create(:user) }
let_it_be(:project) { create(:project, :private) }
let_it_be(:group) {... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module Repositories
class ReplicateService < Repositories::BaseService
Error = Class.new(StandardError)
def execute(new_repository, type)
new_repository.replicate(repository)
new_checksum = new_repository.check... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe Repositories::ReplicateService, feature_category: :source_code_management do
let(:new_checksum) { 'match' }
let(:repository) { instance_double('Gitlab::Git::Repository', checksum: 'match') }
let(:new_repository) { instance_double('Gitlab::Git::R... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
# Used for git housekeeping
#
# Ex.
# Repositories::HousekeepingService.new(project).execute
# Repositories::HousekeepingService.new(project.wiki).execute
#
module Repositories
class HousekeepingService < BaseService
# Timeo... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe Repositories::HousekeepingService, feature_category: :source_code_management do
it_behaves_like 'housekeeps repository' do
let_it_be(:resource) { create(:project, :repository) }
end
it_behaves_like 'housekeeps repository' do
let_it_be(:... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module Repositories
# A service class for generating a changelog section.
class ChangelogService
DEFAULT_TRAILER = 'Changelog'
DEFAULT_FILE = 'CHANGELOG.md'
# The maximum number of commits allowed to fetch in `from` a... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe Repositories::ChangelogService, feature_category: :source_code_management do
describe '#execute' do
let!(:project) { create(:project, :empty_repo) }
let!(:creator) { project.creator }
let!(:author1) { create(:user) }
let!(:author2) {... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
class Repositories::DestroyService < Repositories::BaseService
def execute
return success unless repository
return success unless repo_exists?(disk_path)
# Flush the cache for both repositories. This has to be done _bef... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe Repositories::DestroyService, feature_category: :source_code_management do
let_it_be(:user) { create(:user) }
let!(:project) { create(:project, :repository, namespace: user.namespace) }
let(:repository) { project.repository }
let(:path) { rep... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module Groups
# Service class for counting and caching the number of open merge requests of a group.
class MergeRequestsCountService < Groups::CountService
private
def cache_key_name
'open_merge_requests_count'
... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe Groups::MergeRequestsCountService, :use_clean_rails_memory_store_caching, feature_category: :groups_and_projects do
let_it_be(:user) { create(:user) }
let_it_be(:group) { create(:group, :public) }
let_it_be(:project) { create(:project, :reposito... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module Groups
class AutocompleteService < Groups::BaseService
include LabelsAsHash
# rubocop: disable CodeReuse/ActiveRecord
def issues(confidential_only: false, issue_types: nil)
finder_params = { group_id: group... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe Groups::AutocompleteService, feature_category: :groups_and_projects do
let_it_be(:group, refind: true) { create(:group, :nested, :private, avatar: fixture_file_upload('spec/fixtures/dk.png')) }
let_it_be(:sub_group) { create(:group, :private, pare... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module Groups
class ParticipantsService < Groups::BaseService
include Gitlab::Utils::StrongMemoize
include Users::ParticipableService
def execute(noteable)
@noteable = noteable
participants =
noteab... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe Groups::ParticipantsService, feature_category: :groups_and_projects do
describe '#execute' do
let_it_be(:developer) { create(:user) }
let_it_be(:parent_group) { create(:group) }
let_it_be(:group) { create(:group, parent: parent_group) }
... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module Groups
class TransferService < Groups::BaseService
TransferError = Class.new(StandardError)
attr_reader :error, :new_parent_group
def initialize(group, user, params = {})
super
@error = nil
end
... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe Groups::TransferService, :sidekiq_inline, feature_category: :groups_and_projects do
shared_examples 'project namespace path is in sync with project path' do
it 'keeps project and project namespace attributes in sync' do
projects_with_proje... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module Groups
class AutoDevopsService < Groups::BaseService
def execute
raise Gitlab::Access::AccessDeniedError unless can?(current_user, :admin_group, group)
group.update(auto_devops_enabled: auto_devops_enabled)
... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe Groups::AutoDevopsService, '#execute', feature_category: :auto_devops do
let_it_be(:group) { create(:group) }
let_it_be(:user) { create(:user) }
let(:group_params) { { auto_devops_enabled: '0' } }
let(:service) { described_class.new(group, use... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module Groups
class UpdateSharedRunnersService < Groups::BaseService
def execute
return error('Operation not allowed', 403) unless can?(current_user, :admin_group, group)
validate_params
update_shared_runners... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe Groups::UpdateSharedRunnersService, feature_category: :groups_and_projects do
include ReloadHelpers
let(:user) { create(:user) }
let(:params) { {} }
let(:service) { described_class.new(group, user, params) }
describe '#execute' do
subj... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module Groups
class DestroyService < Groups::BaseService
DestroyError = Class.new(StandardError)
def async_execute
job_id = GroupDestroyWorker.perform_async(group.id, current_user.id)
Gitlab::AppLogger.info("Use... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe Groups::DestroyService, feature_category: :groups_and_projects do
let!(:user) { create(:user) }
let!(:group) { create(:group) }
let!(:nested_group) { create(:group, parent: group) }
let!(:project) { create(:project, :reposi... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module Groups
class UpdateService < Groups::BaseService
include UpdateVisibilityLevel
SETTINGS_PARAMS = [:allow_mfa_for_subgroups].freeze
def execute
reject_parent_id!
remove_unallowed_params
before_... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe Groups::UpdateService, feature_category: :groups_and_projects do
let!(:user) { create(:user) }
let!(:private_group) { create(:group, :private) }
let!(:internal_group) { create(:group, :internal) }
let!(:public_group) { create(:group, :public) ... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module Groups
# Service class for counting and caching the number of open issues of a group.
class OpenIssuesCountService < Groups::CountService
PUBLIC_COUNT_KEY = 'group_public_open_issues_count'
TOTAL_COUNT_KEY = 'group_... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe Groups::OpenIssuesCountService, :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(:user) {... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module Groups
class UpdateStatisticsService
attr_reader :group, :statistics
def initialize(group, statistics: [])
@group = group
@statistics = statistics
end
def execute
unless group
retur... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe Groups::UpdateStatisticsService, feature_category: :groups_and_projects do
let_it_be(:group, reload: true) { create(:group) }
let(:statistics) { %w[wiki_size] }
subject(:service) { described_class.new(group, statistics: statistics) }
descri... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.