INSTRUCTION stringlengths 202 35.5k | RESPONSE stringlengths 75 161k |
|---|---|
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
class BulkUpdateIntegrationService
include Integrations::BulkOperationHashes
def initialize(integration, batch)
@integration = integration
@batch = batch
end
# rubocop: disable CodeReuse/ActiveRecord
def execute
... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe BulkUpdateIntegrationService, feature_category: :integrations do
include JiraIntegrationHelpers
before_all do
stub_jira_integration_test
end
let(:excluded_attributes) do
%w[
id project_id group_id inherit_from_id instance templ... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
class ServiceResponse
def self.success(message: nil, payload: {}, http_status: :ok)
new(
status: :success,
message: message,
payload: payload,
http_status: http_status
)
end
def self.error(messag... | # frozen_string_literal: true
require 'fast_spec_helper'
require 're2'
require_relative '../../app/services/service_response'
require_relative '../../lib/gitlab/error_tracking'
RSpec.describe ServiceResponse, feature_category: :shared do
describe '.success' do
it 'creates a successful response without a messa... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
class BulkCreateIntegrationService
include Integrations::BulkOperationHashes
def initialize(integration, batch, association)
@integration = integration
@batch = batch
@association = association
end
def execute
... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe BulkCreateIntegrationService, feature_category: :integrations do
include JiraIntegrationHelpers
before_all do
stub_jira_integration_test
end
let_it_be(:excluded_group) { create(:group) }
let_it_be(:excluded_project) { create(:project, ... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
# PostReceiveService class
#
# Used for scheduling related jobs after a push action has been performed
class PostReceiveService
attr_reader :user, :repository, :project, :params
def initialize(user, repository, project, params)
... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe PostReceiveService, feature_category: :team_planning do
include GitlabShellHelpers
include Gitlab::Routing
let_it_be(:user) { create(:user) }
let_it_be(:project) { create(:project, :repository, :wiki_repo, namespace: user.namespace) }
let_i... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
class PreviewMarkdownService < BaseService
def execute
text, commands = explain_quick_actions(params[:text])
users = find_user_references(text)
suggestions = find_suggestions(text)
success(
text: text,
u... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe PreviewMarkdownService, feature_category: :team_planning do
let(:user) { create(:user) }
let(:project) { create(:project, :repository) }
before do
project.add_developer(user)
end
describe 'user references' do
let(:params) { { text:... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module ProtectedBranches
class CacheService < ProtectedBranches::BaseService
CACHE_ROOT_KEY = 'cache:gitlab:protected_branch'
TTL_UNSET = -1
CACHE_EXPIRE_IN = 1.day
CACHE_LIMIT = 1000
def fetch(ref_name, dry_run... | # frozen_string_literal: true
# rubocop:disable Style/RedundantFetchBlock
#
require 'spec_helper'
RSpec.describe ProtectedBranches::CacheService, :clean_gitlab_redis_cache, feature_category: :compliance_management do
shared_examples 'execute with entity' do
subject(:service) { described_class.new(entity, user) }... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module ProtectedBranches
class DestroyService < ProtectedBranches::BaseService
def execute(protected_branch)
raise Gitlab::Access::AccessDeniedError unless can?(current_user, :destroy_protected_branch, protected_branch)
... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe ProtectedBranches::DestroyService, feature_category: :compliance_management do
shared_examples 'execute with entity' do
subject(:service) { described_class.new(entity, user) }
describe '#execute' do
it 'destroys a protected branch' do... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module ProtectedBranches
class UpdateService < ProtectedBranches::BaseService
def execute(protected_branch)
raise Gitlab::Access::AccessDeniedError unless can?(current_user, :update_protected_branch, protected_branch)
... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe ProtectedBranches::UpdateService, feature_category: :compliance_management do
shared_examples 'execute with entity' do
let(:params) { { name: new_name } }
subject(:service) { described_class.new(entity, user, params) }
describe '#execu... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module ProtectedBranches
class CreateService < ProtectedBranches::BaseService
def execute(skip_authorization: false)
raise Gitlab::Access::AccessDeniedError unless skip_authorization || authorized?
save_protected_br... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe ProtectedBranches::CreateService, feature_category: :compliance_management do
shared_examples 'execute with entity' do
let(:params) do
{
name: name,
merge_access_levels_attributes: [{ access_level: Gitlab::Access::MAINTAINE... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module ProtectedBranches
class ApiService < ProtectedBranches::BaseService
def create
::ProtectedBranches::CreateService.new(project_or_group, @current_user, protected_branch_params).execute
end
def update(protect... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe ProtectedBranches::ApiService, feature_category: :compliance_management do
shared_examples 'execute with entity' do
it 'creates a protected branch with prefilled defaults' do
expect(::ProtectedBranches::CreateService).to receive(:new).with... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module AuditEvents
class BuildService
# Handle missing attributes
MissingAttributeError = Class.new(StandardError)
# @raise [MissingAttributeError] when required attributes are blank
#
# @return [BuildService]
... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe AuditEvents::BuildService, feature_category: :audit_events do
let(:author) { build_stubbed(:author, current_sign_in_ip: '127.0.0.1') }
let(:deploy_token) { build_stubbed(:deploy_token, user: author) }
let(:scope) { build_stubbed(:group) }
let(... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module Ide
class TerminalConfigService < ::Ide::BaseConfigService
private
def success(pass_back = {})
result = super(pass_back)
result[:terminal] = config.terminal_value
result
end
end
end
``` | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe Ide::TerminalConfigService, feature_category: :web_ide do
let_it_be(:project) { create(:project, :repository) }
let_it_be(:user) { create(:user) }
let(:sha) { 'sha' }
describe '#execute' do
subject { described_class.new(project, user, sh... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module Ide
class SchemasConfigService < ::Ide::BaseConfigService
PREDEFINED_SCHEMAS = [{
uri: 'https://json.schemastore.org/gitlab-ci',
match: ['*.gitlab-ci.yml']
}].freeze
def execute
schema = predefi... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe Ide::SchemasConfigService, feature_category: :web_ide do
let_it_be(:project) { create(:project, :repository) }
let_it_be(:user) { create(:user) }
let(:filename) { 'sample.yml' }
let(:schema_content) { double(body: '{"title":"Sample schema"}')... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module Ide
class BaseConfigService < ::BaseService
ValidationError = Class.new(StandardError)
WEBIDE_CONFIG_FILE = '.gitlab/.gitlab-webide.yml'
attr_reader :config, :config_content
def execute
check_access_a... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe Ide::BaseConfigService, feature_category: :web_ide do
let_it_be(:project) { create(:project, :repository) }
let_it_be(:user) { create(:user) }
let(:sha) { 'sha' }
describe '#execute' do
subject { described_class.new(project, user, sha: s... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module Commits
class CommitPatchService < CreateService
# Requires:
# - project: `Project` to be committed into
# - user: `User` that will be the committer
# - params:
# - branch_name: `String` the branch that ... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe Commits::CommitPatchService, feature_category: :source_code_management do
describe '#execute' do
let(:patches) do
patches_folder = Rails.root.join('spec/fixtures/patchfiles')
content_1 = File.read(File.join(patches_folder, "0001-This-... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module Commits
class CherryPickService < ChangeService
def initialize(*args)
super
@start_project = params[:target_project] || @project
@source_project = params[:source_project] || @project
end
def cr... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe Commits::CherryPickService, feature_category: :source_code_management do
let(:project) { create(:project, :repository) }
# * ddd0f15ae83993f5cb66a927a28673882e99100b (HEAD -> master, origin/master, origin/HEAD) Merge branch 'po-fix-test-en
# |... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module Commits
class TagService < BaseService
def execute(commit)
unless params[:tag_name]
return error('Missing parameter tag_name')
end
tag_name = params[:tag_name]
message = params[:tag_messag... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe Commits::TagService, feature_category: :source_code_management do
let(:project) { create(:project, :repository) }
let(:user) { create(:user) }
let(:commit) { project.commit }
before do
project.add_maintainer(user)
end
describe '#exe... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module ImportCsv
class BaseService
include Gitlab::Utils::StrongMemoize
def initialize(user, project, csv_io)
@user = user
@project = project
@csv_io = csv_io
@results = { success: 0, error_lines: []... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe ImportCsv::BaseService, feature_category: :importers do
let_it_be(:user) { create(:user) }
let_it_be(:project) { create(:project) }
let_it_be(:csv_io) { double }
subject { described_class.new(user, project, csv_io) }
shared_examples 'abstr... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module ImportCsv
class PreprocessMilestonesService < BaseService
def initialize(user, project, provided_titles)
@user = user
@project = project
@provided_titles = provided_titles
@results = { success: 0,... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe ImportCsv::PreprocessMilestonesService, feature_category: :importers do
let_it_be(:group) { create(:group) }
let_it_be(:project) { create(:project, group: group) }
let_it_be(:user) { create(:user) }
let_it_be(:provided_titles) { %w[15.10 10.1]... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module AutoMerge
class MergeWhenPipelineSucceedsService < AutoMerge::BaseService
def execute(merge_request)
super do
add_system_note(merge_request)
end
end
def process(merge_request)
logger.inf... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe AutoMerge::MergeWhenPipelineSucceedsService, feature_category: :code_review_workflow do
include_context 'for auto_merge strategy context'
describe "#available_for?" do
subject { service.available_for?(mr_merge_if_green_enabled) }
let(:pi... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module AutoMerge
class BaseService < ::BaseService
include Gitlab::Utils::StrongMemoize
include MergeRequests::AssignsMergeParams
def execute(merge_request)
ApplicationRecord.transaction do
register_auto_m... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe AutoMerge::BaseService, feature_category: :code_review_workflow do
let(:project) { create(:project) }
let(:user) { create(:user) }
let(:service) { described_class.new(project, user, params) }
let(:merge_request) { create(:merge_request) }
le... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module AuthorizedProjectUpdate
class ProjectAccessChangedService
def initialize(project_ids)
@project_ids = Array.wrap(project_ids)
end
def execute
return if @project_ids.empty?
bulk_args = @project_i... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe AuthorizedProjectUpdate::ProjectAccessChangedService, feature_category: :groups_and_projects do
describe '#execute' do
it 'executes projects_authorizations refresh' do
expect(AuthorizedProjectUpdate::ProjectRecalculateWorker).to receive(:b... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module AuthorizedProjectUpdate
class ProjectRecalculatePerUserService < ProjectRecalculateService
def initialize(project, user)
@project = project
@user = user
end
private
attr_reader :user
def app... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe AuthorizedProjectUpdate::ProjectRecalculatePerUserService, '#execute', feature_category: :groups_and_projects do
let_it_be(:project) { create(:project) }
let_it_be(:user) { create(:user) }
let_it_be(:another_user) { create(:user) }
subject(:e... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module AuthorizedProjectUpdate
class PeriodicRecalculateService
BATCH_SIZE = 450
DELAY_INTERVAL = 50.seconds.to_i
def execute
# Using this approach (instead of eg. User.each_batch) keeps the arguments
# the ... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe AuthorizedProjectUpdate::PeriodicRecalculateService, feature_category: :groups_and_projects do
subject(:service) { described_class.new }
describe '#execute' do
let(:batch_size) { 2 }
let_it_be(:users) { create_list(:user, 4) }
befor... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module AuthorizedProjectUpdate
# Service for finding the authorized_projects records of a user that needs addition or removal.
#
# Usage:
#
# user = User.find_by(username: 'alice')
# service = AuthorizedProjectUpda... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe AuthorizedProjectUpdate::FindRecordsDueForRefreshService, feature_category: :groups_and_projects do
# We're using let! here so that any expectations for the service class are not
# triggered twice.
let!(:project) { create(:project) }
let(:use... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module AuthorizedProjectUpdate
class ProjectRecalculateService
# Service for refreshing all the authorizations to a particular project.
include Gitlab::Utils::StrongMemoize
BATCH_SIZE = 1000
def initialize(project)
... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe AuthorizedProjectUpdate::ProjectRecalculateService, '#execute', feature_category: :groups_and_projects do
let_it_be(:project) { create(:project) }
subject(:execute) { described_class.new(project).execute }
it 'returns success' do
expect(ex... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module SystemNotes
class IssuablesService < ::SystemNotes::BaseService
# We create cross-referenced system notes when a commit relates to an issue.
# There are two options what time to use for the system note:
# 1. The p... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe ::SystemNotes::IssuablesService, feature_category: :team_planning do
include ProjectForksHelper
let_it_be(:group) { create(:group) }
let_it_be(:project) { create(:project, :repository, group: group) }
let_it_be(:author) { create(:user) }
... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module SystemNotes
class DesignManagementService < ::SystemNotes::BaseService
include ActionView::RecordIdentifier
# Parameters:
# - version [DesignManagement::Version]
#
# Example Note text:
#
# "ad... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe SystemNotes::DesignManagementService, feature_category: :design_management do
let(:project) { create(:project) }
let(:issue) { create(:issue, project: project) }
let(:instance) { described_class.new(noteable: instance_noteable, project: instanc... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module SystemNotes
class IncidentsService < ::SystemNotes::BaseService
CHANGED_TEXT = {
occurred_at: 'the event time/date on ',
note: 'the text on ',
occurred_at_and_note: 'the event time/date and text on '
... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe SystemNotes::IncidentsService, feature_category: :incident_management do
let_it_be(:project) { create(:project) }
let_it_be(:user) { create(:user) }
let_it_be(:author) { create(:user) }
let_it_be(:incident) { create(:incident, project: project... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module SystemNotes
class CommitService < ::SystemNotes::BaseService
NEW_COMMIT_DISPLAY_LIMIT = 10
# Called when commits are added to a merge request
#
# new_commits - Array of Commits added since last push
... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe SystemNotes::CommitService, feature_category: :code_review_workflow do
let_it_be(:group) { create(:group) }
let_it_be(:project) { create(:project, :repository, group: group) }
let_it_be(:author) { create(:user) }
let(:commit_service) { ... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module SystemNotes
class AlertManagementService < ::SystemNotes::BaseService
# Called when the a new AlertManagement::Alert has been created
#
# alert - AlertManagement::Alert object.
#
# Example Note text:
#... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe ::SystemNotes::AlertManagementService, feature_category: :groups_and_projects do
let_it_be(:author) { create(:user) }
let_it_be(:project) { create(:project, :repository) }
let_it_be(:noteable) { create(:alert_management_alert, :with_incident,... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module SystemNotes
class MergeRequestsService < ::SystemNotes::BaseService
# Called when 'merge when pipeline succeeds' is executed
def merge_when_pipeline_succeeds(sha)
body = "enabled an automatic merge when the pipe... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe ::SystemNotes::MergeRequestsService, feature_category: :code_review_workflow do
include Gitlab::Routing
let_it_be(:group) { create(:group) }
let_it_be(:project) { create(:project, :repository, group: group) }
let_it_be(:author) { create(:user... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module SystemNotes
class BaseService
attr_reader :noteable, :project, :author
def initialize(noteable: nil, author: nil, project: nil)
@noteable = noteable
@project = project
@author = author
end
... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe SystemNotes::BaseService, feature_category: :groups_and_projects do
let(:noteable) { double }
let(:project) { double }
let(:author) { double }
let(:base_service) { described_class.new(noteable: noteable, project: project, author: author) }
... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module SystemNotes
class TimeTrackingService < ::SystemNotes::BaseService
# Called when the start_date or due_date of an Issue/WorkItem is changed
#
# start_date - Start date being assigned, or nil
# due_date - Due... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe ::SystemNotes::TimeTrackingService, feature_category: :team_planning do
let_it_be(:author) { create(:user) }
let_it_be(:project) { create(:project, :repository) }
describe '#change_start_date_or_due_date' do
let_it_be(:issue) { create(... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module SystemNotes
class ZoomService < ::SystemNotes::BaseService
def zoom_link_added
create_note(NoteSummary.new(noteable, project, author, _('added a Zoom call to this issue'), action: 'pinned_embed'))
end
def z... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe ::SystemNotes::ZoomService, feature_category: :integrations do
let_it_be(:project) { create(:project, :repository) }
let_it_be(:author) { create(:user) }
let(:noteable) { create(:issue, project: project) }
let(:service) { described_cla... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module SystemNotes
class IncidentService < ::SystemNotes::BaseService
# Called when the severity of an Incident has changed
#
# Example Note text:
#
# "changed the severity to Medium - S3"
#
# Returns t... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe ::SystemNotes::IncidentService, feature_category: :incident_management do
let_it_be(:author) { create(:user) }
let_it_be(:project) { create(:project) }
let_it_be(:noteable) { create(:incident, project: project) }
let_it_be(:issuable_severity) ... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module Organizations
class UpdateService < ::Organizations::BaseService
attr_reader :organization
def initialize(organization, current_user:, params: {})
@organization = organization
@current_user = current_user... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe Organizations::UpdateService, feature_category: :cell do
describe '#execute' do
let_it_be(:user) { create(:user) }
let_it_be_with_reload(:organization) { create(:organization) }
let(:current_user) { user }
let(:name) { 'Name' }
... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module Organizations
class CreateService < ::Organizations::BaseService
def execute
return error_no_permissions unless current_user&.can?(:create_organization)
organization = Organization.create(params)
retur... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe Organizations::CreateService, feature_category: :cell do
describe '#execute' do
let_it_be(:user) { create(:user) }
let(:current_user) { user }
let(:params) { attributes_for(:organization) }
subject(:response) { described_class.new(... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module Terraform
class RemoteStateHandler < BaseService
include Gitlab::OptimisticLocking
StateLockedError = Class.new(StandardError)
StateDeletedError = Class.new(StandardError)
UnauthorizedError = Class.new(Standa... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe Terraform::RemoteStateHandler, feature_category: :infrastructure_as_code do
let_it_be(:project) { create(:project) }
let_it_be(:developer) { create(:user, developer_projects: [project]) }
let_it_be(:maintainer) { create(:user, maintainer_project... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module Terraform
module States
class TriggerDestroyService
def initialize(state, current_user:)
@state = state
@current_user = current_user
end
def execute
return unauthorized_response ... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe Terraform::States::TriggerDestroyService, feature_category: :infrastructure_as_code do
let_it_be(:project) { create(:project) }
let_it_be(:user) { create(:user, maintainer_projects: [project]) }
describe '#execute', :aggregate_failures do
l... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module Terraform
module States
class DestroyService
def initialize(state)
@state = state
end
def execute
return unless state.deleted_at?
state.versions.each_batch(column: :version) do ... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe Terraform::States::DestroyService, feature_category: :infrastructure_as_code do
let_it_be(:state) { create(:terraform_state, :with_version, :deletion_in_progress) }
let(:file) { instance_double(Terraform::StateUploader, relative_path: 'path') }
... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module Snippets
class UpdateRepositoryStorageService
include UpdateRepositoryStorageMethods
delegate :snippet, to: :repository_storage_move
private
def track_repository(destination_storage_name)
snippet.trac... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe Snippets::UpdateRepositoryStorageService, feature_category: :source_code_management do
subject { described_class.new(repository_storage_move) }
describe "#execute" do
let_it_be_with_reload(:snippet) { create(:snippet, :repository) }
let_i... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module Snippets
class RepositoryValidationService
attr_reader :current_user, :snippet, :repository
RepositoryValidationError = Class.new(StandardError)
def initialize(user, snippet)
@current_user = user
@sn... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe Snippets::RepositoryValidationService, feature_category: :source_code_management do
describe '#execute' do
let_it_be(:user) { create(:user) }
let_it_be(:snippet) { create(:personal_snippet, :empty_repo, author: user) }
let(:repositor... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module Snippets
# Tries to schedule a move for every snippet with repositories on the source shard
class ScheduleBulkRepositoryShardMovesService
include ScheduleBulkRepositoryShardMovesMethods
extend ::Gitlab::Utils::Overr... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe Snippets::ScheduleBulkRepositoryShardMovesService, feature_category: :source_code_management do
it_behaves_like 'moves repository shard in bulk' do
let_it_be_with_reload(:container) { create(:snippet, :repository) }
let(:move_service_klass)... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module Snippets
class DestroyService
include Gitlab::Allowable
attr_reader :current_user, :snippet
DestroyError = Class.new(StandardError)
def initialize(user, snippet)
@current_user = user
@snippet = ... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe Snippets::DestroyService, feature_category: :source_code_management do
let_it_be(:project) { create(:project) }
let_it_be(:user) { create(:user) }
let_it_be(:other_user) { create(:user) }
describe '#execute' do
subject { described_class.n... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module Snippets
class UpdateService < Snippets::BaseService
COMMITTABLE_ATTRIBUTES = %w[file_name content].freeze
UpdateError = Class.new(StandardError)
def initialize(project:, current_user: nil, params: {}, perform_s... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe Snippets::UpdateService, feature_category: :source_code_management do
describe '#execute', :aggregate_failures do
let_it_be(:user) { create(:user) }
let_it_be(:admin) { create :user, admin: true }
let(:action) { :update }
let(:visib... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module Snippets
class BulkDestroyService
include Gitlab::Allowable
attr_reader :current_user, :snippets
DeleteRepositoryError = Class.new(StandardError)
SnippetAccessError = Class.new(StandardError)
def initia... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe Snippets::BulkDestroyService, feature_category: :source_code_management do
let_it_be(:project) { create(:project) }
let(:user) { create(:user) }
let!(:personal_snippet) { create(:personal_snippet, :repository, author: user) }
let!(:project_sn... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module Snippets
class UpdateStatisticsService
attr_reader :snippet
def initialize(snippet)
@snippet = snippet
end
def execute
unless snippet.repository_exists?
return ServiceResponse.error(messa... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe Snippets::UpdateStatisticsService, feature_category: :source_code_management do
describe '#execute' do
subject { described_class.new(snippet).execute }
shared_examples 'updates statistics' do
it 'returns a successful response' do
... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
# Service for calculating visible Snippet counts via one query
# for the given user or project.
#
# Authorisation level checks will be included, ensuring the correct
# counts will be returned for the given user (if any).
#
# Basic usa... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe Snippets::CountService, feature_category: :source_code_management do
let_it_be(:user) { create(:user) }
let_it_be(:project) { create(:project, :public) }
describe '#new' do
it 'raises an error if no author or project' do
expect { desc... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module Snippets
class CreateService < Snippets::BaseService
def initialize(project:, current_user: nil, params: {}, perform_spam_check: true)
super(project: project, current_user: current_user, params: params)
@perfo... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe Snippets::CreateService, feature_category: :source_code_management do
describe '#execute' do
let_it_be(:user) { create(:user) }
let_it_be(:admin) { create(:user, :admin) }
let(:action) { :create }
let(:opts) { base_opts.merge(extra_... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module Database
class ConsistencyFixService
def initialize(source_model:, target_model:, sync_event_class:, source_sort_key:, target_sort_key:)
@source_model = source_model
@target_model = target_model
@sync_ev... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe Database::ConsistencyFixService, feature_category: :cell do
describe '#execute' do
context 'fixing namespaces inconsistencies' do
subject(:consistency_fix_service) do
described_class.new(
source_model: Namespace,
... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module Database
class ConsistencyCheckService
CURSOR_REDIS_KEY_TTL = 7.days
EMPTY_RESULT = { matches: 0, mismatches: 0, batches: 0, mismatches_details: [] }.freeze
def initialize(source_model:, target_model:, source_col... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe Database::ConsistencyCheckService, feature_category: :cell do
let(:batch_size) { 5 }
let(:max_batches) { 2 }
before do
stub_const("Gitlab::Database::ConsistencyChecker::BATCH_SIZE", batch_size)
stub_const("Gitlab::Database::ConsistencyC... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module Database
class MarkMigrationService
def initialize(connection:, version:)
@connection = connection
@version = version
end
def execute
return error(reason: :not_found) unless migration.present?
... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe Database::MarkMigrationService, feature_category: :database do
let(:service) { described_class.new(connection: connection, version: version) }
let(:version) { 1 }
let(:connection) { ApplicationRecord.connection }
let(:migrations) do
[
... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module FeatureFlags
class HookService
HOOK_NAME = :feature_flag_hooks
def initialize(feature_flag, current_user)
@feature_flag = feature_flag
@current_user = current_user
end
def execute
project.e... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe FeatureFlags::HookService, feature_category: :feature_flags do
describe '#execute_hooks' do
let_it_be(:namespace) { create(:namespace) }
let_it_be(:project) { create(:project, :repository, namespace: namespace) }
let_it_be(:feature_flag)... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module FeatureFlags
class DestroyService < FeatureFlags::BaseService
def execute(feature_flag)
destroy_feature_flag(feature_flag)
end
private
def destroy_feature_flag(feature_flag)
return error('Access ... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe FeatureFlags::DestroyService, feature_category: :feature_flags do
include FeatureFlagHelpers
let_it_be(:project) { create(:project) }
let_it_be(:developer) { create(:user) }
let_it_be(:reporter) { create(:user) }
let(:user) { developer }
... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module FeatureFlags
class UpdateService < FeatureFlags::BaseService
AUDITABLE_STRATEGY_ATTRIBUTES_HUMAN_NAMES = {
'scopes' => 'environment scopes',
'parameters' => 'parameters'
}.freeze
def success(**args)
... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe FeatureFlags::UpdateService, :with_license, feature_category: :feature_flags do
let_it_be(:project) { create(:project) }
let_it_be(:developer) { create(:user) }
let_it_be(:reporter) { create(:user) }
let(:user) { developer }
let(:feature_fl... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module FeatureFlags
class CreateService < FeatureFlags::BaseService
def execute
return error('Access Denied', 403) unless can_create?
return error('Version is invalid', :bad_request) unless valid_version?
Appl... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe FeatureFlags::CreateService, feature_category: :feature_flags do
let_it_be(:project) { create(:project) }
let_it_be(:developer) { create(:user) }
let_it_be(:reporter) { create(:user) }
let(:user) { developer }
before_all do
project.add... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module IssueLinks
class DestroyService < IssuableLinks::DestroyService
include IncidentManagement::UsageData
private
def permission_to_remove_relation?
can?(current_user, :admin_issue_link, source) && can?(curren... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe IssueLinks::DestroyService, feature_category: :team_planning do
describe '#execute' do
let_it_be(:project) { create(:project_empty_repo, :private) }
let_it_be(:reporter) { create(:user).tap { |user| project.add_reporter(user) } }
let_it_... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module IssueLinks
class ListService < IssuableLinks::ListService
extend ::Gitlab::Utils::Override
private
def child_issuables
issuable.related_issues(current_user, preload: preload_for_collection)
end
ov... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe IssueLinks::ListService, feature_category: :team_planning do
let(:user) { create :user }
let(:project) { create(:project_empty_repo, :private) }
let(:issue) { create :issue, project: project }
let(:user_role) { :developer }
before do
pr... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module IssueLinks
class CreateService < IssuableLinks::CreateService
include IncidentManagement::UsageData
def linkable_issuables(issues)
@linkable_issuables ||= issues.select { |issue| can?(current_user, :admin_issue... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe IssueLinks::CreateService, feature_category: :team_planning do
describe '#execute' do
let_it_be(:user) { create :user }
let_it_be(:namespace) { create :namespace }
let_it_be(:project) { create :project, namespace: namespace }
let_it_... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module Spam
class SpamActionService
include SpamConstants
def initialize(spammable:, user:, action:, extra_features: {})
@target = spammable
@user = user
@action = action
@extra_features = extra_feat... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe Spam::SpamActionService, feature_category: :instance_resiliency do
include_context 'includes Spam constants'
let(:issue) { create(:issue, project: project, author: author) }
let(:personal_snippet) { create(:personal_snippet, :public, author: au... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module Spam
class HamService
include AkismetMethods
attr_accessor :spam_log, :options
def initialize(spam_log)
@spam_log = spam_log
@user = spam_log.user
@options = {
ip_address: spam_log.so... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe Spam::HamService, feature_category: :instance_resiliency do
let_it_be(:user) { create(:user) }
let!(:spam_log) { create(:spam_log, user: user, submitted_as_ham: false) }
let(:fake_akismet_service) { double(:akismet_service) }
subject { descr... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module Spam
class AkismetService
attr_accessor :text, :options
def initialize(owner_name, owner_email, text, options = {})
@owner_name = owner_name
@owner_email = owner_email
@text = text
@options = ... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe Spam::AkismetService, feature_category: :instance_resiliency do
let(:fake_akismet_client) { double(:akismet_client) }
let(:ip) { '1.2.3.4' }
let(:user_agent) { 'some user_agent' }
let(:referer) { 'some referer' }
let_it_be(:text) { "Would y... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module Spam
class SpamVerdictService
include AkismetMethods
include SpamConstants
def initialize(user:, target:, options:, context: {}, extra_features: {})
@target = target
@user = user
@options = opti... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe Spam::SpamVerdictService, feature_category: :instance_resiliency do
include_context 'includes Spam constants'
let(:fake_ip) { '1.2.3.4' }
let(:fake_user_agent) { 'fake-user-agent' }
let(:fake_referer) { 'fake-http-referer' }
let(:env) do
... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module Spam
class AkismetMarkAsSpamService
include ::AkismetMethods
attr_accessor :target, :options
def initialize(target:)
@target = target
@options = {}
end
def execute
@options[:ip_address... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe Spam::AkismetMarkAsSpamService, feature_category: :instance_resiliency do
let(:user_agent_detail) { build(:user_agent_detail) }
let(:spammable) { build(:issue, user_agent_detail: user_agent_detail) }
let(:fake_akismet_service) { double(:akismet_... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module Spam
##
# This class is a Parameter Object (https://refactoring.com/catalog/introduceParameterObject.html)
# which acts as an container abstraction for multiple values related to spam and
# captcha processing for a prov... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe Spam::SpamParams, feature_category: :instance_resiliency do
shared_examples 'constructs from a request' do
it 'constructs from a request' do
expected = ::Spam::SpamParams.new(
captcha_response: captcha_response,
spam_log_id... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module Releases
class CreateEvidenceService
def initialize(release, pipeline: nil)
@release = release
@pipeline = pipeline
end
def execute
evidence = release.evidences.build
summary = ::Evidence... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe Releases::CreateEvidenceService, feature_category: :release_orchestration do
let_it_be(:project) { create(:project) }
let(:release) { create(:release, project: project) }
let(:service) { described_class.new(release) }
it 'creates evidence' d... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module Releases
class DestroyService < Releases::BaseService
def execute
return error(_('Release does not exist'), 404) unless release
return error(_('Access Denied'), 403) unless allowed?
if release.destroy
... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe Releases::DestroyService, feature_category: :release_orchestration do
let(:project) { create(:project, :repository) }
let(:mainatiner) { create(:user) }
let(:repoter) { create(:user) }
let(:tag) { 'v1.1.0' }
let!(:release) { create(:release,... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module Releases
class UpdateService < Releases::BaseService
def execute
if error = validate
return error
end
if param_for_milestones_provided?
previous_milestones = release.milestones.map(&:id)... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe Releases::UpdateService, feature_category: :continuous_integration do
let(:project) { create(:project, :repository) }
let(:user) { create(:user) }
let(:new_name) { 'A new name' }
let(:new_description) { 'The best release!' }
let(:params) { {... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module Releases
class CreateService < Releases::BaseService
def execute
return error(_('Access Denied'), 403) unless allowed?
return error(_('You are not allowed to create this tag as it is protected.'), 403) unless ... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe Releases::CreateService, feature_category: :continuous_integration do
let(:project) { create(:project, :repository) }
let(:user) { create(:user) }
let(:tag_name) { project.repository.tag_names.first }
let(:tag_message) { nil }
let(:tag_sha) ... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module Releases
module Links
class DestroyService < BaseService
def execute(link)
return ServiceResponse.error(reason: REASON_FORBIDDEN, message: _('Access Denied')) unless allowed?
return ServiceResponse.e... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe Releases::Links::DestroyService, feature_category: :release_orchestration do
let(:service) { described_class.new(release, user, {}) }
let_it_be(:project) { create(:project, :repository) }
let_it_be(:user) { create(:user) }
let_it_be(:release) ... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module Releases
module Links
class UpdateService < BaseService
def execute(link)
return ServiceResponse.error(reason: REASON_FORBIDDEN, message: _('Access Denied')) unless allowed?
return ServiceResponse.er... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe Releases::Links::UpdateService, feature_category: :release_orchestration do
let(:service) { described_class.new(release, user, params) }
let_it_be(:project) { create(:project, :repository) }
let_it_be(:user) { create(:user) }
let_it_be(:releas... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module Releases
module Links
class CreateService < BaseService
def execute
return ServiceResponse.error(reason: REASON_FORBIDDEN, message: _('Access Denied')) unless allowed?
link = release.links.create(al... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe Releases::Links::CreateService, feature_category: :release_orchestration do
let(:service) { described_class.new(release, user, params) }
let_it_be(:project) { create(:project, :repository) }
let_it_be(:user) { create(:user) }
let_it_be(:releas... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module Releases
module Links
class Params
def initialize(params)
@params = params.with_indifferent_access
end
def allowed_params
@allowed_params ||= params.slice(:name, :url, :link_type).tap do... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe Releases::Links::Params, feature_category: :release_orchestration do
subject(:filter) { described_class.new(params) }
let(:params) { { name: name, url: url, direct_asset_path: direct_asset_path, link_type: link_type, unknown: '?' } }
let(:name)... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module ChatNames
class FindUserService
def initialize(team_id, user_id)
@team_id = team_id
@user_id = user_id
end
def execute
chat_name = find_chat_name
return unless chat_name
record_chat... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe ChatNames::FindUserService, :clean_gitlab_redis_shared_state, feature_category: :user_profile do
describe '#execute' do
subject { described_class.new(team_id, user_id).execute }
context 'find user mapping' do
let_it_be(:user) { create... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module ChatNames
class AuthorizeUserService
include Gitlab::Routing
def initialize(params)
@params = params
end
def execute
return unless chat_name_params.values.all?(&:present?)
token = request_... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe ChatNames::AuthorizeUserService, feature_category: :user_profile do
describe '#execute' do
let(:result) { subject.execute }
subject { described_class.new(params) }
context 'when all parameters are valid' do
let(:params) { { team_... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module ErrorTracking
class IssueDetailsService < ErrorTracking::BaseService
include Gitlab::Routing
include Gitlab::Utils::StrongMemoize
private
def perform
response = find_issue_details(params[:issue_id])
... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe ErrorTracking::IssueDetailsService, feature_category: :error_tracking do
include_context 'sentry error tracking context'
subject(:service) { described_class.new(project, user, params) }
describe '#execute' do
context 'with authorized user'... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module ErrorTracking
class ListProjectsService < ErrorTracking::BaseService
private
def perform
return error('Access denied', :unauthorized) unless can?(current_user, :admin_sentry, project)
unless project_erro... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe ErrorTracking::ListProjectsService, feature_category: :integrations do
let_it_be(:user) { create(:user) }
let_it_be(:project, reload: true) { create(:project) }
let(:sentry_url) { 'https://sentrytest.gitlab.com/api/0/projects/org/proj/' }
let... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module ErrorTracking
class BaseService < ::BaseProjectService
include Gitlab::Utils::UsageData
def initialize(project, user = nil, params = {})
super(project: project, current_user: user, params: params.dup)
end
... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe ErrorTracking::BaseService, feature_category: :error_tracking do
describe '#compose_response' do
let(:project) { build_stubbed(:project) }
let(:user) { build_stubbed(:user, id: non_existing_record_id) }
let(:service) { described_class.ne... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module ErrorTracking
class IssueLatestEventService < ErrorTracking::BaseService
private
def perform
response = find_issue_latest_event(params[:issue_id])
compose_response(response)
end
def parse_respon... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe ErrorTracking::IssueLatestEventService, feature_category: :error_tracking do
include_context 'sentry error tracking context'
let(:params) { {} }
subject(:service) { described_class.new(project, user, params) }
describe '#execute' do
con... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module ErrorTracking
class IssueUpdateService < ErrorTracking::BaseService
private
def perform
update_opts = {
issue_id: params[:issue_id],
params: update_params
}
response = update_issue(... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe ErrorTracking::IssueUpdateService, feature_category: :error_tracking do
include_context 'sentry error tracking context'
let(:arguments) { { issue_id: non_existing_record_id, status: 'resolved' } }
subject(:update_service) { described_class.new... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module ErrorTracking
class ListIssuesService < ErrorTracking::BaseService
DEFAULT_ISSUE_STATUS = 'unresolved'
DEFAULT_LIMIT = 20
DEFAULT_SORT = 'last_seen'
# Sentry client supports 'muted' and 'assigned' but GitLab ... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe ErrorTracking::ListIssuesService, feature_category: :error_tracking do
include_context 'sentry error tracking context'
let(:params) { {} }
subject(:service) { described_class.new(project, user, params) }
describe '#execute' do
context '... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module WebHooks
class LogExecutionService
include ::Gitlab::ExclusiveLeaseHelpers
LOCK_TTL = 15.seconds.freeze
LOCK_SLEEP = 0.25.seconds.freeze
LOCK_RETRY = 65
attr_reader :hook, :log_data, :response_category
... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe WebHooks::LogExecutionService, feature_category: :webhooks do
include ExclusiveLeaseHelpers
using RSpec::Parameterized::TableSyntax
describe '#execute' do
around do |example|
travel_to(Time.current) { example.run }
end
let_it... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module WebHooks
class LogDestroyService
BATCH_SIZE = 1000
def initialize(web_hook_id)
@web_hook_id = web_hook_id
end
def execute
next while WebHookLog.delete_batch_for(@web_hook_id, batch_size: BATCH_SI... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe WebHooks::LogDestroyService, feature_category: :webhooks do
subject(:service) { described_class.new(hook.id) }
describe '#execute' do
shared_examples 'deletes web hook logs for hook' do
before do
create_list(:web_hook_log, 3, we... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module WebHooks
# Destroy a hook, and schedule the logs for deletion.
class DestroyService
include Services::ReturnServiceResponses
attr_accessor :current_user
DENIED = 'Insufficient permissions'
def initialize(... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe WebHooks::DestroyService, feature_category: :webhooks do
let_it_be(:user) { create(:user) }
subject { described_class.new(user) }
describe '#execute' do
# Testing with a project hook only - for permission tests, see policy specs.
let!(... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module ContainerRegistry
module Protection
class CreateRuleService < BaseService
ALLOWED_ATTRIBUTES = %i[
container_path_pattern
push_protected_up_to_access_level
delete_protected_up_to_access_level... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe ContainerRegistry::Protection::CreateRuleService, '#execute', feature_category: :container_registry do
let_it_be(:project) { create(:project, :repository) }
let_it_be(:current_user) { create(:user, maintainer_projects: [project]) }
let(:service... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module LooseForeignKeys
class ProcessDeletedRecordsService
BATCH_SIZE = 1000
def initialize(connection:, modification_tracker: LooseForeignKeys::ModificationTracker.new)
@connection = connection
@modification_tr... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe LooseForeignKeys::ProcessDeletedRecordsService, feature_category: :database do
include MigrationsHelpers
def create_table_structure
migration = ActiveRecord::Migration.new.extend(Gitlab::Database::MigrationHelpers::LooseForeignKeyHelpers)
... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module LooseForeignKeys
# rubocop: disable CodeReuse/ActiveRecord
class CleanerService
DELETE_LIMIT = 1000
UPDATE_LIMIT = 500
def initialize(loose_foreign_key_definition:, connection:, deleted_parent_records:, with_sk... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe LooseForeignKeys::CleanerService, feature_category: :database do
let(:schema) { ApplicationRecord.connection.current_schema }
let(:deleted_records) do
[
LooseForeignKeys::DeletedRecord.new(fully_qualified_table_name: "#{schema}.projects"... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module LooseForeignKeys
class BatchCleanerService
CLEANUP_ATTEMPTS_BEFORE_RESCHEDULE = 3
CONSUME_AFTER_RESCHEDULE = 5.minutes
def initialize(parent_table:, loose_foreign_key_definitions:, deleted_parent_records:, modifi... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe LooseForeignKeys::BatchCleanerService, feature_category: :database do
include MigrationsHelpers
def create_table_structure
migration = ActiveRecord::Migration.new.extend(Gitlab::Database::MigrationHelpers::LooseForeignKeyHelpers)
migrati... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
#
# Used by NotificationService to determine who should receive notification
#
module NotificationRecipients
module BuildService
def self.notifiable_users(users, *args)
users.compact.map { |u| NotificationRecipient.new(u, ... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe NotificationRecipients::BuildService, feature_category: :team_planning do
let(:service) { described_class }
let(:assignee) { create(:user) }
let(:project) { create(:project, :public) }
let(:other_projects) { create_list(:project, 5, :public) }... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module NotificationRecipients
module Builder
class NewNote < Base
attr_reader :note
def initialize(note)
@note = note
end
def target
note.noteable
end
def recipients_target
... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe NotificationRecipients::Builder::NewNote, feature_category: :team_planning do
describe '#notification_recipients' do
let_it_be(:group) { create(:group, :public) }
let_it_be(:project) { create(:project, :public, group: group) }
let_it_b... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module NotificationRecipients
module Builder
class Default < Base
MENTION_TYPE_ACTIONS = [:new_issue, :new_merge_request].freeze
attr_reader :target
attr_reader :current_user
attr_reader :action
at... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe NotificationRecipients::Builder::Default, feature_category: :team_planning do
describe '#build!' do
let_it_be(:group) { create(:group, :public) }
let_it_be(:project) { create(:project, :public, group: group).tap { |p| p.add_developer(proje... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module JiraConnectInstallations
class ProxyLifecycleEventService
SUPPOERTED_EVENTS = %i[installed uninstalled].freeze
def self.execute(installation, event, instance_url)
new(installation, event, instance_url).execute
... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe JiraConnectInstallations::ProxyLifecycleEventService, feature_category: :integrations do
describe '.execute' do
let(:installation) { create(:jira_connect_installation) }
it 'creates an instance and calls execute' do
expect_next_instan... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module JiraConnectInstallations
class DestroyService
def self.execute(installation, jira_connect_base_path, jira_connect_uninstalled_event_path)
new(installation, jira_connect_base_path, jira_connect_uninstalled_event_path... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe JiraConnectInstallations::DestroyService, feature_category: :integrations do
describe '.execute' do
it 'creates an instance and calls execute' do
expect_next_instance_of(described_class, 'param1', 'param2', 'param3') do |destroy_service|
... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module JiraConnectInstallations
class UpdateService
def self.execute(installation, update_params)
new(installation, update_params).execute
end
def initialize(installation, update_params)
@installation = inst... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe JiraConnectInstallations::UpdateService, feature_category: :integrations do
describe '.execute' do
it 'creates an instance and calls execute' do
expect_next_instance_of(described_class, 'param1', 'param2') do |update_service|
expec... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module JiraConnectSubscriptions
class CreateService < ::JiraConnectSubscriptions::BaseService
include Gitlab::Utils::StrongMemoize
MERGE_REQUEST_SYNC_BATCH_SIZE = 20
MERGE_REQUEST_SYNC_BATCH_DELAY = 1.minute.freeze
... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe JiraConnectSubscriptions::CreateService, feature_category: :integrations do
let_it_be(:installation) { create(:jira_connect_installation) }
let_it_be(:current_user) { create(:user) }
let_it_be(:group) { create(:group) }
let(:path) { group.ful... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module Discussions
class ResolveService < Discussions::BaseService
include Gitlab::Utils::StrongMemoize
def initialize(project, user = nil, params = {})
@discussions = Array.wrap(params.fetch(:one_or_more_discussions)... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe Discussions::ResolveService, feature_category: :code_review_workflow do
describe '#execute' do
let_it_be(:project) { create(:project, :repository) }
let_it_be(:user) { create(:user, developer_projects: [project]) }
let_it_be(:merge_reque... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module Discussions
class UnresolveService < Discussions::BaseService
include Gitlab::Utils::StrongMemoize
def initialize(discussion, user)
@discussion = discussion
@user = user
super
end
def exec... | # frozen_string_literal: true
require "spec_helper"
RSpec.describe Discussions::UnresolveService, feature_category: :code_review_workflow do
describe "#execute" do
let_it_be(:project) { create(:project, :repository) }
let_it_be(:user) { create(:user, developer_projects: [project]) }
let_it_be(:merge_req... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module Discussions
class UpdateDiffPositionService < BaseService
def execute(discussion)
old_position = discussion.position
result = tracer.trace(old_position)
return unless result
position = result[:pos... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe Discussions::UpdateDiffPositionService, feature_category: :code_review_workflow do
let(:project) { create(:project, :repository) }
let(:current_user) { project.first_owner }
let(:create_commit) { project.commit("913c66a37b4a45b9769037c55c2d238bd... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module Discussions
class CaptureDiffNotePositionsService
def initialize(merge_request)
@merge_request = merge_request
end
def execute
return unless merge_request.has_complete_diff_refs?
discussions, p... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe Discussions::CaptureDiffNotePositionsService, feature_category: :code_review_workflow do
context 'when merge request has a discussion' do
let(:source_branch) { 'compare-with-merge-head-source' }
let(:target_branch) { 'compare-with-merge-head... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.