INSTRUCTION stringlengths 202 35.5k | RESPONSE stringlengths 75 161k |
|---|---|
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
# Performs the initial handling of event payloads sent from Slack to GitLab.
# See `API::Integrations::Slack::Events` which calls this service.
module Integrations
class SlackEventService
URL_VERIFICATION_EVENT = 'url_verificati... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe Integrations::SlackEventService, feature_category: :integrations do
describe '#execute' do
subject(:execute) { described_class.new(params).execute }
let(:params) do
{
type: 'event_callback',
event: {
type: 'a... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module Integrations
class PropagateService
BATCH_SIZE = 10_000
def initialize(integration)
@integration = integration
end
def propagate
if integration.instance_level?
update_inherited_integratio... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe Integrations::PropagateService, feature_category: :integrations do
describe '.propagate' do
include JiraIntegrationHelpers
before do
stub_jira_integration_test
end
let(:group) { create(:group) }
let_it_be(:project) { cre... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module Integrations
class SlackInteractionService
UnknownInteractionError = Class.new(StandardError)
INTERACTIONS = {
'view_closed' => SlackInteractions::IncidentManagement::IncidentModalClosedService,
'view_sub... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe Integrations::SlackInteractionService, feature_category: :integrations do
describe '#execute' do
subject(:execute) { described_class.new(params).execute }
let(:params) do
{
type: slack_interaction,
foo: 'bar'
}
... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module Integrations
module SlackOptions
class UserSearchHandler # rubocop:disable Search/NamespacedClass
include Gitlab::Utils::StrongMemoize
def initialize(current_user, search_value, view_id)
@current_user... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe Integrations::SlackOptions::UserSearchHandler, feature_category: :integrations do
describe '#execute' do
let_it_be(:project) { create(:project, :private) }
let_it_be(:current_user) { create(:user) }
let_it_be(:chat_name) { create(:chat_n... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module Integrations
module SlackOptions
class LabelSearchHandler # rubocop:disable Search/NamespacedClass
include Gitlab::Utils::StrongMemoize
def initialize(current_user, search_value, view_id)
@current_use... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe Integrations::SlackOptions::LabelSearchHandler, feature_category: :integrations do
describe '#execute' do
let_it_be(:group) { create(:group) }
let_it_be(:project) { create(:project, :private, namespace: group) }
let_it_be(:current_user) ... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module Integrations
module Test
class ProjectService < Integrations::Test::BaseService
include Integrations::ProjectTestData
include Gitlab::Utils::StrongMemoize
def project
strong_memoize(:project) do... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe Integrations::Test::ProjectService, feature_category: :integrations do
include AfterNextHelpers
describe '#execute' do
let_it_be(:project) { create(:project) }
let(:integration) { create(:integrations_slack, project: project) }
let(:... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
# Handles the Slack `app_home_opened` event sent from Slack to GitLab.
# Responds with a POST to the Slack API 'views.publish' method.
#
# See:
# - https://api.slack.com/methods/views.publish
# - https://api.slack.com/events/app_home_... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe Integrations::SlackEvents::AppHomeOpenedService, feature_category: :integrations do
describe '#execute' do
let_it_be(:slack_installation) { create(:slack_integration) }
let(:slack_workspace_id) { slack_installation.team_id }
let(:slack_... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
# Returns the special URL verification response expected by Slack when the
# GitLab Slack app is first configured to receive Slack events.
#
# Slack will issue the challenge request to the endpoint that receives events
# and expect it... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe Integrations::SlackEvents::UrlVerificationService, feature_category: :integrations do
describe '#execute' do
it 'returns the challenge' do
expect(described_class.new({ challenge: 'foo' }).execute).to eq({ challenge: 'foo' })
end
end
... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module Integrations
module SlackInteractions
class BlockActionService
ALLOWED_UPDATES_HANDLERS = {
'incident_management_project' => SlackInteractions::SlackBlockActions::IncidentManagement::ProjectUpdateHandler
... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe Integrations::SlackInteractions::BlockActionService, feature_category: :integrations do
describe '#execute' do
let_it_be(:slack_installation) { create(:slack_integration) }
let(:params) do
{
view: {
team_id: slack_in... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module Integrations
module SlackInteractions
module IncidentManagement
class IncidentModalSubmitService
include GitlabRoutingHelper
include Gitlab::Routing
IssueCreateError = Class.new(StandardErro... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe Integrations::SlackInteractions::IncidentManagement::IncidentModalSubmitService,
feature_category: :incident_management do
include Gitlab::Routing
describe '#execute' do
let_it_be(:slack_installation) { create(:slack_integration) }
let_... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module Integrations
module SlackInteractions
module IncidentManagement
class IncidentModalOpenedService
MAX_PROJECTS = 100
CACHE_EXPIRES_IN = 5.minutes
def initialize(slack_installation, current_us... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe Integrations::SlackInteractions::IncidentManagement::IncidentModalOpenedService,
feature_category: :incident_management do
describe '#execute' do
let_it_be(:slack_installation) { create(:slack_integration) }
let_it_be(:project) { create(:p... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module Integrations
module SlackInteractions
module IncidentManagement
class IncidentModalClosedService
def initialize(params)
@params = params
end
def execute
begin
... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe Integrations::SlackInteractions::IncidentManagement::IncidentModalClosedService,
feature_category: :integrations do
describe '#execute' do
let_it_be(:request_body) do
{
replace_original: 'true',
text: 'Incident creation c... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module Integrations
module SlackInteractions
module SlackBlockActions
module IncidentManagement
class ProjectUpdateHandler
include Gitlab::Utils::StrongMemoize
def initialize(params, action)
... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe Integrations::SlackInteractions::SlackBlockActions::IncidentManagement::ProjectUpdateHandler,
feature_category: :incident_management do
describe '#execute' do
let_it_be(:slack_installation) { create(:slack_integration) }
let_it_be(:old_pro... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module GpgKeys
class DestroyService < Keys::BaseService
BATCH_SIZE = 1000
def execute(key)
nullify_signatures(key)
key.destroy
end
private
# When a GPG key is deleted, the related signatures have t... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe GpgKeys::DestroyService, feature_category: :source_code_management do
let_it_be(:user) { create(:user) }
let_it_be(:gpg_key) { create(:gpg_key) }
subject { described_class.new(user) }
it 'destroys the GPG key' do
expect { subject.execute... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module GpgKeys
class CreateService < Keys::BaseService
def execute
key = create(params)
notification_service.new_gpg_key(key) if key.persisted?
key
end
private
def create(params)
user.gpg_ke... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe GpgKeys::CreateService, feature_category: :source_code_management do
let(:user) { create(:user) }
let(:params) { attributes_for(:gpg_key) }
subject { described_class.new(user, params) }
context 'notification', :mailer do
it 'sends a noti... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module GoogleCloud
class EnableVisionAiService < ::GoogleCloud::BaseService
def execute
gcp_project_ids = unique_gcp_project_ids
if gcp_project_ids.empty?
error("No GCP projects found. Configure a service ac... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe GoogleCloud::EnableVisionAiService, feature_category: :deployment_management do
describe 'when a project does not have any gcp projects' do
let_it_be(:project) { create(:project) }
it 'returns error' do
result = described_class.new(pr... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module GoogleCloud
class GcpRegionAddOrReplaceService < ::GoogleCloud::BaseService
def execute(environment, region)
gcp_region_key = Projects::GoogleCloud::GcpRegionsController::GCP_REGION_CI_VAR_KEY
change_params =... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe GoogleCloud::GcpRegionAddOrReplaceService, feature_category: :deployment_management do
it 'adds and replaces GCP region vars' do
project = create(:project, :public)
service = described_class.new(project)
service.execute('env_1', 'loc_1'... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module GoogleCloud
class SetupCloudsqlInstanceService < ::GoogleCloud::BaseService
INSTANCE_STATE_RUNNABLE = 'RUNNABLE'
OPERATION_STATE_DONE = 'DONE'
DEFAULT_DATABASE_NAME = 'main_db'
DEFAULT_DATABASE_USER = 'main_us... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe GoogleCloud::SetupCloudsqlInstanceService, feature_category: :deployment_management do
let(:random_user) { create(:user) }
let(:project) { create(:project) }
let(:list_databases_empty) { Google::Apis::SqladminV1beta4::ListDatabasesResponse.new(i... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module GoogleCloud
class GetCloudsqlInstancesService < ::GoogleCloud::BaseService
CLOUDSQL_KEYS = %w[GCP_PROJECT_ID GCP_CLOUDSQL_INSTANCE_NAME GCP_CLOUDSQL_VERSION].freeze
def execute
group_vars_by_environment(CLOUDSQ... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe GoogleCloud::GetCloudsqlInstancesService, feature_category: :deployment_management do
let(:service) { described_class.new(project) }
let(:project) { create(:project) }
context 'when project has no registered cloud sql instances' do
it 'resu... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module GoogleCloud
class FetchGoogleIpListService
include BaseServiceUtility
GOOGLE_IP_RANGES_URL = 'https://www.gstatic.com/ipranges/cloud.json'
RESPONSE_BODY_LIMIT = 1.megabyte
EXPECTED_CONTENT_TYPE = 'application... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe GoogleCloud::FetchGoogleIpListService, :use_clean_rails_memory_store_caching,
:clean_gitlab_redis_rate_limiting, feature_category: :build_artifacts do
include StubRequests
let(:google_cloud_ips) { File.read(Rails.root.join('spec/fixtures/cdn/go... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module GoogleCloud
class GeneratePipelineService < ::GoogleCloud::BaseService
ACTION_DEPLOY_TO_CLOUD_RUN = 'DEPLOY_TO_CLOUD_RUN'
ACTION_DEPLOY_TO_CLOUD_STORAGE = 'DEPLOY_TO_CLOUD_STORAGE'
ACTION_VISION_AI_PIPELINE = 'VIS... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe GoogleCloud::GeneratePipelineService, feature_category: :deployment_management do
describe 'for cloud-run' do
describe 'when there is no existing pipeline' do
let_it_be(:project) { create(:project, :repository) }
let_it_be(:maintaine... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module GoogleCloud
class EnableCloudRunService < ::GoogleCloud::BaseService
def execute
gcp_project_ids = unique_gcp_project_ids
if gcp_project_ids.empty?
error("No GCP projects found. Configure a service ac... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe GoogleCloud::EnableCloudRunService, feature_category: :deployment_management do
describe 'when a project does not have any gcp projects' do
let_it_be(:project) { create(:project) }
it 'returns error' do
result = described_class.new(pr... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module GoogleCloud
class EnableCloudsqlService < ::GoogleCloud::BaseService
def execute
create_or_replace_project_vars(environment_name, 'GCP_PROJECT_ID', gcp_project_id, ci_var_protected?)
unique_gcp_project_ids.ea... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe GoogleCloud::EnableCloudsqlService, feature_category: :deployment_management do
let_it_be(:project) { create(:project) }
let_it_be(:user) { create(:user) }
let_it_be(:params) do
{
google_oauth2_token: 'mock-token',
gcp_project_id... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module GoogleCloud
class CreateServiceAccountsService < ::GoogleCloud::BaseService
def execute
service_account = google_api_client.create_service_account(gcp_project_id, service_account_name, service_account_desc)
se... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe GoogleCloud::CreateServiceAccountsService, feature_category: :deployment_management do
describe '#execute' do
before do
mock_google_oauth2_creds = Struct.new(:app_id, :app_secret)
.new('mock-app-id', '... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module GoogleCloud
DEFAULT_REGION = 'us-east1'
class CreateCloudsqlInstanceService < ::GoogleCloud::BaseService
WORKER_INTERVAL = 30.seconds
def execute
create_cloud_instance
trigger_instance_setup_worker
... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe GoogleCloud::CreateCloudsqlInstanceService, feature_category: :deployment_management do
let(:project) { create(:project) }
let(:user) { create(:user) }
let(:gcp_project_id) { 'gcp_project_120' }
let(:environment_name) { 'test_env_42' }
let(:... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module GoogleCloud
##
# GCP keys used to store Google Cloud Service Accounts
GCP_KEYS = %w[GCP_PROJECT_ID GCP_SERVICE_ACCOUNT GCP_SERVICE_ACCOUNT_KEY].freeze
##
# This service deals with GCP Service Accounts in GitLab
cl... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe GoogleCloud::ServiceAccountsService, feature_category: :deployment_management do
let(:service) { described_class.new(project) }
describe 'find_for_project' do
let_it_be(:project) { create(:project) }
context 'when a project does not have... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module ResourceEvents
class ChangeMilestoneService < BaseChangeTimeboxService
attr_reader :milestone, :old_milestone
def initialize(resource, user, old_milestone:)
super(resource, user)
@milestone = resource&.m... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe ResourceEvents::ChangeMilestoneService, feature_category: :team_planning do
let_it_be(:timebox) { create(:milestone) }
let(:created_at_time) { Time.utc(2019, 12, 30) }
let(:add_timebox_args) { { old_milestone: nil } }
let(:remove_timebox_args... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
# We store events about issuable label changes and weight changes in separate tables (not as
# other system notes), but we still want to display notes about label and weight changes
# as classic system notes in UI. This service merge... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe ResourceEvents::MergeIntoNotesService, feature_category: :team_planning do
def create_event(params)
event_params = { action: :add, label: label, issue: resource,
user: user }
create(:resource_label_event, event_params.m... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module ResourceEvents
class ChangeLabelsService
attr_reader :resource, :user
def initialize(resource, user)
@resource = resource
@user = user
end
def execute(added_labels: [], removed_labels: [])
... | # frozen_string_literal: true
require 'spec_helper'
# feature category is shared among plan(issues, epics), monitor(incidents), create(merge request) stages
RSpec.describe ResourceEvents::ChangeLabelsService, feature_category: :team_planning do
let_it_be(:project) { create(:project) }
let_it_be(:author) { create... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module ResourceEvents
class ChangeStateService
attr_reader :resource, :user
def initialize(user:, resource:)
@user = user
@resource = resource
end
def execute(params)
@params = params
Resou... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe ResourceEvents::ChangeStateService, feature_category: :team_planning do
let_it_be(:project) { create(:project) }
let_it_be(:user) { create(:user) }
let(:issue) { create(:issue, project: project) }
let(:merge_request) { create(:merge_request, ... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
# We store events about resource milestone changes in a separate table,
# but we still want to display notes about milestone changes
# as classic system notes in UI. This service generates "synthetic" notes for
# milestone event chang... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe ResourceEvents::SyntheticMilestoneNotesBuilderService, feature_category: :team_planning do
describe '#execute' do
let_it_be(:user) { create(:user) }
let_it_be(:issue) { create(:issue, author: user) }
let_it_be(:milestone) { create(:miles... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
# We store events about issuable label changes in a separate table (not as
# other system notes), but we still want to display notes about label changes
# as classic system notes in UI. This service generates "synthetic" notes for
# ... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe ResourceEvents::SyntheticLabelNotesBuilderService, feature_category: :team_planning do
describe '#execute' do
let_it_be(:user) { create(:user) }
let_it_be(:issue) { create(:issue, author: user) }
let_it_be(:event1) { create(:resource_l... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module ResourceEvents
class SyntheticStateNotesBuilderService < BaseSyntheticNotesBuilderService
private
def synthetic_notes
state_change_events.map do |event|
StateNote.from_event(event, resource: resource, r... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe ResourceEvents::SyntheticStateNotesBuilderService, feature_category: :team_planning do
describe '#execute' do
let_it_be(:user) { create(:user) }
it_behaves_like 'filters by paginated notes', :resource_state_event
end
end
|
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module DraftNotes
class PublishService < DraftNotes::BaseService
def execute(draft = nil)
return error('Not allowed to create notes') unless can?(current_user, :create_note, merge_request)
if draft
publish_d... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe DraftNotes::PublishService, feature_category: :code_review_workflow do
include RepoHelpers
let_it_be(:merge_request) { create(:merge_request, reviewers: create_list(:user, 1)) }
let(:project) { merge_request.target_project }
let(:user) { merge... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module DraftNotes
class DestroyService < DraftNotes::BaseService
# If no `draft` is given it fallsback to all
# draft notes of the given merge request and user.
def execute(draft = nil)
drafts = draft || draft_note... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe DraftNotes::DestroyService, feature_category: :code_review_workflow do
let(:merge_request) { create(:merge_request) }
let(:project) { merge_request.target_project }
let(:user) { merge_request.author }
def destroy(draft_note = nil)
DraftNot... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module DraftNotes
class CreateService < DraftNotes::BaseService
attr_accessor :in_draft_mode, :in_reply_to_discussion_id
def initialize(merge_request, current_user, params = nil)
@in_reply_to_discussion_id = params.de... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe DraftNotes::CreateService, feature_category: :code_review_workflow do
let(:merge_request) { create(:merge_request) }
let(:project) { merge_request.target_project }
let(:user) { merge_request.author }
def create_draft(params)
described_clas... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module Markup
class RenderingService
def initialize(text, file_name: nil, context: {}, postprocess_context: {})
@text = text
@file_name = file_name
@context = context
@postprocess_context = postprocess_co... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe Markup::RenderingService, feature_category: :groups_and_projects do
describe '#execute' do
let_it_be(:project) { create(:project, :repository) }
let_it_be(:user) do
user = create(:user, username: 'gfm')
project.add_maintainer(use... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module ServiceDesk
module CustomEmailVerifications
class UpdateService < BaseService
EMAIL_TOKEN_REGEXP = /Verification token: ([A-Za-z0-9_-]{12})/
def execute
return error_parameter_missing if settings.blan... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe ServiceDesk::CustomEmailVerifications::UpdateService, feature_category: :service_desk do
describe '#execute' do
let_it_be_with_reload(:project) { create(:project) }
let_it_be(:user) { create(:user) }
let!(:credential) { create(:service_... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module ServiceDesk
module CustomEmailVerifications
class CreateService < BaseService
attr_reader :ramp_up_error
def execute
return error_settings_missing unless settings.present?
return error_user_no... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe ServiceDesk::CustomEmailVerifications::CreateService, feature_category: :service_desk do
describe '#execute' do
let_it_be_with_reload(:project) { create(:project) }
let_it_be(:user) { create(:user) }
let!(:credential) { create(:service_... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module ServiceDesk
module CustomEmails
class DestroyService < BaseService
def execute
return error_user_not_authorized unless legitimate_user?
return error_does_not_exist unless verification? || credential?... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe ServiceDesk::CustomEmails::DestroyService, feature_category: :service_desk do
describe '#execute' do
let_it_be_with_reload(:project) { create(:project) }
let(:user) { build_stubbed(:user) }
let(:service) { described_class.new(project: p... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module ServiceDesk
module CustomEmails
class CreateService < BaseService
def execute
return error_user_not_authorized unless legitimate_user?
return error_params_missing unless has_required_params?
... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe ServiceDesk::CustomEmails::CreateService, feature_category: :service_desk do
describe '#execute' do
let_it_be_with_reload(:project) { create(:project) }
let_it_be(:user) { create(:user) }
let(:service) { described_class.new(project: pro... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module DependencyProxy
class AuthTokenService < DependencyProxy::BaseService
attr_reader :token
def initialize(token)
@token = token
end
def execute
JSONWebToken::HMACToken.decode(token, ::Auth::Depende... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe DependencyProxy::AuthTokenService, feature_category: :dependency_proxy do
include DependencyProxyHelpers
let_it_be(:user) { create(:user) }
let_it_be(:deploy_token) { create(:deploy_token) }
describe '.user_or_deploy_token_from_jwt' do
su... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module DependencyProxy
class RequestTokenService < DependencyProxy::BaseService
def initialize(image)
@image = image
end
def execute
response = Gitlab::HTTP.get(auth_url)
if response.success?
... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe DependencyProxy::RequestTokenService, feature_category: :dependency_proxy do
include DependencyProxyHelpers
let(:image) { 'alpine:3.9' }
let(:token) { Digest::SHA256.hexdigest('123') }
subject { described_class.new(image).execute }
context... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module DependencyProxy
class HeadManifestService < DependencyProxy::BaseService
ACCEPT_HEADERS = DependencyProxy::Manifest::ACCEPTED_TYPES.join(',')
def initialize(image, tag, token)
@image = image
@tag = tag
... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe DependencyProxy::HeadManifestService, feature_category: :dependency_proxy do
include DependencyProxyHelpers
let(:image) { 'alpine' }
let(:tag) { 'latest' }
let(:token) { Digest::SHA256.hexdigest('123') }
let(:digest) { '12345' }
let(:conte... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module DependencyProxy
class FindCachedManifestService < DependencyProxy::BaseService
def initialize(group, image, tag, token)
@group = group
@image = image
@tag = tag
@token = token
@file_name = "#... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe DependencyProxy::FindCachedManifestService, feature_category: :dependency_proxy do
include DependencyProxyHelpers
let_it_be(:image) { 'alpine' }
let_it_be(:tag) { 'latest' }
let_it_be(:dependency_proxy_manifest) { create(:dependency_proxy_mani... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module DependencyProxy
module ImageTtlGroupPolicies
class UpdateService < BaseContainerService
include Gitlab::Utils::StrongMemoize
ALLOWED_ATTRIBUTES = %i[enabled ttl].freeze
def execute
return Servi... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe ::DependencyProxy::ImageTtlGroupPolicies::UpdateService, feature_category: :dependency_proxy do
using RSpec::Parameterized::TableSyntax
let_it_be_with_reload(:group) { create(:group) }
let_it_be(:user) { create(:user) }
let_it_be(:params) { {... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module DependencyProxy
module GroupSettings
class UpdateService < BaseContainerService
ALLOWED_ATTRIBUTES = %i[enabled].freeze
def execute
return ServiceResponse.error(message: 'Access Denied', http_status: ... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe ::DependencyProxy::GroupSettings::UpdateService, feature_category: :dependency_proxy do
using RSpec::Parameterized::TableSyntax
let_it_be_with_reload(:group) { create(:group) }
let_it_be_with_reload(:group_settings) { create(:dependency_proxy_g... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module Jira
module Requests
module Projects
class ListService < Base
extend ::Gitlab::Utils::Override
def initialize(jira_integration, params = {})
super(jira_integration, params)
@que... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe Jira::Requests::Projects::ListService, feature_category: :groups_and_projects do
include AfterNextHelpers
let(:jira_integration) { create(:jira_integration) }
let(:params) { {} }
describe '#execute' do
let(:service) { described_class.new... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module ContainerExpirationPolicies
class CleanupService
attr_reader :repository
SERVICE_RESULT_FIELDS = %i[original_size before_truncate_size after_truncate_size before_delete_size deleted_size cached_tags_count].freeze
... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe ContainerExpirationPolicies::CleanupService, feature_category: :container_registry do
let_it_be(:repository, reload: true) { create(:container_repository, expiration_policy_started_at: 30.minutes.ago) }
let_it_be(:project) { repository.project }
... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module ContainerExpirationPolicies
class UpdateService < BaseContainerService
include Gitlab::Utils::StrongMemoize
ALLOWED_ATTRIBUTES = %i[enabled cadence older_than keep_n name_regex name_regex_keep].freeze
def execut... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe ContainerExpirationPolicies::UpdateService, feature_category: :container_registry do
using RSpec::Parameterized::TableSyntax
let_it_be(:project, reload: true) { create(:project) }
let_it_be(:user) { create(:user) }
let_it_be(:params) { { cade... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module Notes
class ResolveService < ::BaseService
def execute(note)
note.resolve!(current_user)
::MergeRequests::ResolvedDiscussionNotificationService.new(project: project, current_user: current_user).execute(note.n... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe Notes::ResolveService, feature_category: :team_planning do
let(:merge_request) { create(:merge_request) }
let(:note) { create(:diff_note_on_merge_request, noteable: merge_request, project: merge_request.project) }
let(:user) { merge_request.auth... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
# This service copies Notes from one Noteable to another.
#
# It expects the calling code to have performed the necessary authorization
# checks in order to allow the copy to happen.
module Notes
class CopyService
def initialize... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe Notes::CopyService, feature_category: :team_planning do
describe '#initialize' do
let_it_be(:noteable) { create(:issue) }
it 'validates that we cannot copy notes to the same Noteable' do
expect { described_class.new(nil, noteable, not... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module Notes
class PostProcessService
attr_accessor :note
def initialize(note)
@note = note
end
def execute
# Skip system notes, like status changes and cross-references and awards
unless note.sys... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe Notes::PostProcessService, feature_category: :team_planning do
let(:project) { create(:project) }
let(:issue) { create(:issue, project: project) }
let(:user) { create(:user) }
describe '#execute' do
before do
project.add_maintainer(... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
# QuickActionsService class
#
# Executes quick actions commands extracted from note text
#
# Most commands returns parameters to be applied later
# using QuickActionService#apply_updates
#
module Notes
class QuickActionsService < Ba... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe Notes::QuickActionsService, feature_category: :team_planning do
shared_context 'note on noteable' do
let_it_be(:project) { create(:project, :repository) }
let_it_be(:maintainer) { create(:user).tap { |u| project.add_maintainer(u) } }
let... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module Notes
class BuildService < ::BaseService
def execute
in_reply_to_discussion_id = params.delete(:in_reply_to_discussion_id)
external_author = params.delete(:external_author)
discussion = nil
if ex... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe Notes::BuildService, feature_category: :team_planning do
include AdminModeHelper
let_it_be(:project) { create(:project, :repository) }
let_it_be(:note) { create(:discussion_note_on_issue, project: project) }
let_it_be(:author) { note.author }... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module Notes
class DestroyService < ::Notes::BaseService
def execute(note)
TodoService.new.destroy_target(note) do |note|
note.destroy
end
clear_noteable_diffs_cache(note)
track_note_removal_usag... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe Notes::DestroyService, feature_category: :team_planning do
let_it_be(:project) { create(:project, :public) }
let_it_be(:issue) { create(:issue, project: project) }
let(:user) { issue.author }
describe '#execute' do
it 'deletes a note' do... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module Notes
class UpdateService < BaseService
def execute(note)
return note unless note.editable? && params.present?
old_mentioned_users = note.mentioned_users(current_user).to_a
note.assign_attributes(param... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe Notes::UpdateService, feature_category: :team_planning do
let(:group) { create(:group, :public) }
let(:project) { create(:project, :public, group: group) }
let(:private_group) { create(:group, :private) }
let(:private_project) { create(:projec... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module Notes
class RenderService < BaseRenderer
# Renders a collection of Note instances.
#
# notes - The notes to render.
#
# Possible options:
#
# requested_path - The request path.
# project_wiki -... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe Notes::RenderService, feature_category: :team_planning do
describe '#execute' do
it 'renders a Note' do
note = double(:note)
wiki = double(:wiki)
user = double(:user)
expect(Banzai::ObjectRenderer)
.to receive(:n... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module Notes
class CreateService < ::Notes::BaseService
include IncidentManagement::UsageData
def execute(skip_capture_diff_note_position: false, skip_merge_status_trigger: false, skip_set_reviewed: false)
note = Note... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe Notes::CreateService, feature_category: :team_planning do
let_it_be(:group) { create(:group) }
let_it_be(:project) { create(:project, :repository, group: group) }
let_it_be(:issue) { create(:issue, project: project) }
let_it_be(:user) { create... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module ProtectedTags
class DestroyService < BaseService
def execute(protected_tag)
protected_tag.destroy
end
end
end
``` | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe ProtectedTags::DestroyService, feature_category: :compliance_management do
let(:protected_tag) { create(:protected_tag) }
let(:project) { protected_tag.project }
let(:user) { project.first_owner }
describe '#execute' do
subject(:service) ... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module ProtectedTags
class UpdateService < ::BaseService
def execute(protected_tag)
raise Gitlab::Access::AccessDeniedError unless can?(current_user, :admin_project, project)
protected_tag.update(params)
prote... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe ProtectedTags::UpdateService, feature_category: :compliance_management do
let(:protected_tag) { create(:protected_tag) }
let(:project) { protected_tag.project }
let(:user) { project.first_owner }
let(:params) { { name: new_name } }
describe... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module ProtectedTags
class CreateService < ::BaseService
attr_reader :protected_tag
def execute
raise Gitlab::Access::AccessDeniedError unless can?(current_user, :admin_project, project)
project.protected_tags.... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe ProtectedTags::CreateService, feature_category: :compliance_management do
let(:project) { create(:project) }
let(:user) { project.first_owner }
let(:params) do
{
name: name,
create_access_levels_attributes: [{ access_level: Gitla... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module Ml
class CreateCandidateService
def initialize(experiment, params = {})
@experiment = experiment
@name = params[:name]
@user = params[:user]
@start_time = params[:start_time]
@model_version =... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe ::Ml::CreateCandidateService, feature_category: :mlops do
describe '#execute' do
let_it_be(:model_version) { create(:ml_model_versions, candidate: nil) }
let_it_be(:experiment) { create(:ml_experiments, project: model_version.project) }
... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module Ml
class CreateModelVersionService
def initialize(model, params = {})
@model = model
@version = params[:version]
@package = params[:package]
@description = params[:description]
@user = params... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe ::Ml::CreateModelVersionService, feature_category: :mlops do
let(:model) { create(:ml_models) }
let(:params) { {} }
subject(:service) { described_class.new(model, params).execute }
context 'when no versions exist' do
it 'creates a model ... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module Ml
class FindOrCreateExperimentService
def initialize(project, experiment_name, user = nil)
@project = project
@name = experiment_name
@user = user
end
def execute
Ml::Experiment.find_or_c... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe ::Ml::FindOrCreateExperimentService, feature_category: :mlops do
let_it_be(:project) { create(:project) }
let_it_be(:user) { project.first_owner }
let_it_be(:existing_experiment) { create(:ml_experiments, project: project, user: user) }
let(:... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module Ml
class DestroyModelService
def initialize(model, user)
@model = model
@user = user
end
def execute
return unless @model.destroy
::Packages::MarkPackagesForDestructionService.new(
... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe ::Ml::DestroyModelService, feature_category: :mlops do
let_it_be(:user) { create(:user) }
let_it_be(:model) { create(:ml_models, :with_latest_version_and_package) }
let(:service) { described_class.new(model, user) }
describe '#execute' do
... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module Ml
class CreateModelService
def initialize(project, name, user = nil, description = nil, metadata = [])
@project = project
@name = name
@description = description
@metadata = metadata
@user =... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe ::Ml::CreateModelService, feature_category: :mlops do
let_it_be(:user) { create(:user) }
let_it_be(:existing_model) { create(:ml_models) }
let_it_be(:another_project) { create(:project) }
let_it_be(:description) { 'description' }
let_it_be(:... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module Ml
class UpdateModelService
def initialize(model, description)
@model = model
@description = description
end
def execute
@model.update!(description: @description)
@model
end
end
end... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe ::Ml::UpdateModelService, feature_category: :mlops do
let_it_be(:model) { create(:ml_models) }
let_it_be(:description) { 'updated model description' }
let(:service) { described_class.new(model, description) }
describe '#execute' do
contex... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module Ml
INITIAL_VERSION = '1.0.0'
ALLOWED_INCREMENT_TYPES = [:patch, :minor, :major].freeze
class IncrementVersionService
def initialize(version, increment_type = nil)
@version = version
@increment_type = incr... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe ::Ml::IncrementVersionService, feature_category: :mlops do
describe '#execute' do
let(:increment_type) { nil }
let(:finder) { described_class.new(version, increment_type) }
context 'when given an invalid version format' do
let(:ve... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module Ml
class FindOrCreateModelService
def initialize(project, name, user = nil, description = nil, metadata = [])
@project = project
@name = name
@description = description
@metadata = metadata
@... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe ::Ml::FindOrCreateModelService, feature_category: :mlops do
let_it_be(:user) { create(:user) }
let_it_be(:existing_model) { create(:ml_models) }
let_it_be(:another_project) { create(:project) }
let_it_be(:description) { 'description' }
let_i... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module Ml
class FindOrCreateModelVersionService
def initialize(project, params = {})
@project = project
@name = params[:model_name]
@version = params[:version]
@package = params[:package]
@descripti... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe ::Ml::FindOrCreateModelVersionService, feature_category: :mlops do
let_it_be(:existing_version) { create(:ml_model_versions) }
let_it_be(:another_project) { create(:project) }
let_it_be(:user) { create(:user) }
let(:package) { nil }
let(:de... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module Ml
class FindModelService
def initialize(project, name)
@project = project
@name = name
end
def execute
Ml::Model.by_project_id_and_name(@project.id, @name)
end
end
end
``` | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe ::Ml::FindModelService, feature_category: :mlops do
let_it_be(:user) { create(:user) }
let_it_be(:existing_model) { create(:ml_models) }
let(:finder) { described_class.new(project, name) }
describe '#execute' do
context 'when model name d... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module Ml
module ExperimentTracking
class CandidateRepository
attr_accessor :project, :user, :experiment, :candidate
def initialize(project, user = nil)
@project = project
@user = user
end
... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe ::Ml::ExperimentTracking::CandidateRepository, feature_category: :activation do
let_it_be(:project) { create(:project) }
let_it_be(:user) { create(:user) }
let_it_be(:experiment) { create(:ml_experiments, user: user, project: project) }
let_it... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module Ml
module ExperimentTracking
class HandleCandidateGitlabMetadataService
def initialize(candidate, metadata)
@candidate = candidate
@metadata = metadata.index_by { |m| m[:key] }
end
def e... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe ::Ml::ExperimentTracking::HandleCandidateGitlabMetadataService, feature_category: :activation do
let_it_be(:project) { create(:project, :repository) }
let_it_be(:user) { project.owner }
let_it_be(:pipeline) { create(:ci_pipeline, project: projec... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module Ml
module ExperimentTracking
class ExperimentRepository
attr_accessor :project, :user
def initialize(project, user = nil)
@project = project
@user = user
end
def by_iid_or_name(ii... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe ::Ml::ExperimentTracking::ExperimentRepository, feature_category: :activation do
let_it_be(:project) { create(:project) }
let_it_be(:user) { create(:user) }
let_it_be(:experiment) { create(:ml_experiments, user: user, project: project) }
let_i... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module Ml
module ModelVersions
class UpdateModelVersionService
def initialize(project, name, version, description)
@project = project
@name = name
@version = version
@description = descripti... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe Ml::ModelVersions::UpdateModelVersionService, feature_category: :mlops do
let_it_be(:existing_version) { create(:ml_model_versions) }
let(:project) { existing_version.project }
let(:name) { existing_version.name }
let(:version) { existing_ver... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module Ml
module ModelVersions
class GetModelVersionService
def initialize(project, name, version)
@project = project
@name = name
@version = version
end
def execute
Ml::ModelVe... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe Ml::ModelVersions::GetModelVersionService, feature_category: :mlops do
let_it_be(:existing_version) { create(:ml_model_versions) }
let_it_be(:another_project) { create(:project) }
subject(:model_version) { described_class.new(project, name, ver... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module Ml
module ModelVersions
class DeleteService
def initialize(project, name, version, user)
@project = project
@name = name
@version = version
@user = user
end
def execute
... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe Ml::ModelVersions::DeleteService, feature_category: :mlops do
let_it_be(:valid_model_version) do
create(:ml_model_versions, :with_package)
end
let(:project) { valid_model_version.project }
let(:user) { valid_model_version.project.owner }
... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module DesignManagement
class MoveDesignsService < DesignService
# @param user [User] The current user
# @param [Hash] params
# @option params [DesignManagement::Design] :current_design
# @option params [DesignManage... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe DesignManagement::MoveDesignsService, feature_category: :design_management do
include DesignManagementTestHelpers
let_it_be(:issue) { create(:issue) }
let_it_be(:developer) { create(:user, developer_projects: [issue.project]) }
let_it_be(:desi... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module DesignManagement
# Service class for counting and caching the number of unresolved
# notes of a Design
class DesignUserNotesCountService < ::BaseCountService
# The version of the cache format. This should be bumped wh... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe DesignManagement::DesignUserNotesCountService, :use_clean_rails_memory_store_caching, feature_category: :design_management do
let_it_be(:design) { create(:design, :with_file) }
subject { described_class.new(design) }
it_behaves_like 'a counter... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module DesignManagement
class SaveDesignsService < DesignService
include RunsDesignActions
include OnSuccessCallbacks
MAX_FILES = 10
def initialize(project, user, params = {})
super
@files = params.fet... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe DesignManagement::SaveDesignsService, feature_category: :design_management do
include DesignManagementTestHelpers
include ConcurrentHelpers
let_it_be_with_reload(:issue) { create(:issue) }
let_it_be(:developer) { create(:user, developer_projec... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module DesignManagement
class DeleteDesignsService < DesignService
include RunsDesignActions
include OnSuccessCallbacks
def initialize(project, user, params = {})
super
@designs = params.fetch(:designs)
... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe DesignManagement::DeleteDesignsService, feature_category: :design_management do
include DesignManagementTestHelpers
let_it_be(:project) { create(:project) }
let_it_be(:issue) { create(:issue, project: project) }
let_it_be(:user) { create(:user... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module DesignManagement
# This service generates smaller image versions for `DesignManagement::Design`
# records within a given `DesignManagement::Version`.
class GenerateImageVersionsService < DesignService
# We limit proce... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe DesignManagement::GenerateImageVersionsService, feature_category: :design_management do
let_it_be(:project) { create(:project) }
let_it_be(:issue) { create(:issue, project: project) }
let_it_be(:version) { create(:design, :with_lfs_file, issue: ... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
# Service to copy a DesignCollection from one Issue to another.
# Copies the DesignCollection's Designs, Versions, and Notes on Designs.
module DesignManagement
module CopyDesignCollection
class CopyService < DesignService
... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe DesignManagement::CopyDesignCollection::CopyService, :clean_gitlab_redis_shared_state, feature_category: :portfolio_management do
include DesignManagementTestHelpers
let_it_be(:user) { create(:user) }
let_it_be(:project) { create(:project) }
l... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
# Service for setting the initial copy_state on the target DesignCollection
# and queuing a CopyDesignCollectionWorker.
module DesignManagement
module CopyDesignCollection
class QueueService
def initialize(current_user, is... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe DesignManagement::CopyDesignCollection::QueueService, :clean_gitlab_redis_shared_state,
feature_category: :design_management do
include DesignManagementTestHelpers
let_it_be(:user) { create(:user) }
let_it_be(:issue) { create(:issue) }
let_i... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module UserPreferences
class UpdateService < BaseService
def initialize(user, params = {})
@preferences = user.user_preference
@params = params.to_h.dup.with_indifferent_access
end
def execute
if @pref... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe UserPreferences::UpdateService, feature_category: :user_profile do
let(:user) { create(:user) }
let(:params) { { view_diffs_file_by_file: false, pass_user_identities_to_ci_jwt: true } }
describe '#execute' do
subject(:service) { described_c... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module Users
class ValidateManualOtpService < BaseService
include ::Gitlab::Auth::Otp::Fortinet
include ::Gitlab::Auth::Otp::DuoAuth
def initialize(current_user)
@current_user = current_user
@strategy = if f... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe Users::ValidateManualOtpService, feature_category: :user_profile do
let_it_be(:user) { create(:user) }
let(:otp_code) { 42 }
subject(:validate) { described_class.new(user).execute(otp_code) }
context 'Devise' do
it 'calls Devise strateg... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module Users
class ActivityService
LEASE_TIMEOUT = 1.minute.to_i
def initialize(author:, namespace: nil, project: nil)
@user = if author.respond_to?(:username)
author
elsif author.respond... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe Users::ActivityService, feature_category: :user_profile do
include ExclusiveLeaseHelpers
let(:user) { create(:user, last_activity_on: last_activity_on) }
subject { described_class.new(author: user) }
describe '#execute', :clean_gitlab_redis... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module Users
class SetNamespaceCommitEmailService
include Gitlab::Allowable
attr_reader :current_user, :target_user, :namespace, :email_id
def initialize(current_user, namespace, email_id, params)
@current_user =... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe Users::SetNamespaceCommitEmailService, feature_category: :user_profile do
include AfterNextHelpers
let_it_be(:user) { create(:user) }
let_it_be(:group) { create(:group) }
let_it_be(:email) { create(:email, user: user) }
let_it_be(:existing_... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module Users
class BannedUserBaseService < BaseService
def initialize(current_user)
@current_user = current_user
end
def execute(user)
return permission_error unless allowed?
return state_error(user) u... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe Users::BannedUserBaseService, feature_category: :user_management do
let(:admin) { create(:admin) }
let(:base_service) { described_class.new(admin) }
describe '#initialize' do
it 'sets the current_user instance value' do
expect(base_se... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module Users
class TrustService < BaseService
def initialize(current_user)
@current_user = current_user
end
def execute(user)
UserCustomAttribute.set_trusted_by(user: user, trusted_by: @current_user)
s... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe Users::TrustService, feature_category: :user_management do
let_it_be(:current_user) { create(:admin) }
subject(:service) { described_class.new(current_user) }
describe '#execute' do
let(:user) { create(:user) }
subject(:operation) { s... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module Users
class BlockService < BaseService
def initialize(current_user)
@current_user = current_user
end
def execute(user)
return error('An internal user cannot be blocked', 403) if user.internal?
... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe Users::BlockService, feature_category: :user_management do
let_it_be(:current_user) { create(:admin) }
subject(:service) { described_class.new(current_user) }
describe '#execute' do
subject(:operation) { service.execute(user) }
contex... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module Users
# Service for refreshing the authorized projects of a user.
#
# This particular service class can not be used to update data for the same
# user concurrently. Doing so could lead to an incorrect state. To ensure t... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe Users::RefreshAuthorizedProjectsService, feature_category: :user_management do
include ExclusiveLeaseHelpers
# We're using let! here so that any expectations for the service class are not
# triggered twice.
let!(:project) { create(:project) }... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
# When a user is destroyed, some of their associated records are
# moved to a "Ghost User", to prevent these associated records from
# being destroyed.
#
# For example, all the issues/MRs a user has created are _not_ destroyed
# when ... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe Users::MigrateRecordsToGhostUserService, feature_category: :user_management do
include BatchDestroyDependentAssociationsHelper
let!(:user) { create(:user) }
let(:service) { described_class.new(user, admin, execution_tracker) }
let(:execution_... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module Users
class AuthorizedBuildService < BuildService
extend ::Gitlab::Utils::Override
private
override :validate_access!
def validate_access!
# no-op
end
def signup_params
super + [:skip_co... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe Users::AuthorizedBuildService, feature_category: :user_management do
describe '#execute' do
let_it_be(:current_user) { create(:user) }
let(:params) { build_stubbed(:user).slice(:first_name, :last_name, :username, :email, :password) }
s... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module Users
class RejectService < BaseService
def initialize(current_user)
@current_user = current_user
end
def execute(user)
return error(_('You are not allowed to reject a user'), :forbidden) unless allow... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe Users::RejectService, feature_category: :user_management do
let_it_be(:current_user) { create(:admin) }
let(:user) { create(:user, :blocked_pending_approval) }
subject(:execute) { described_class.new(current_user).execute(user) }
describe '... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module Users
# Service class for caching and retrieving the last push event of a user.
class LastPushEventService
EXPIRATION = 2.hours
def initialize(user)
@user = user
end
# Caches the given push event for... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe Users::LastPushEventService, feature_category: :source_code_management do
let(:user) { build(:user, id: 1) }
let(:project) { build(:project, id: 2) }
let(:event) { build(:push_event, id: 3, author: user, project: project) }
let(:service) { des... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module Users
class UpsertCreditCardValidationService < BaseService
attr_reader :params
def initialize(params)
@params = params.to_h.with_indifferent_access
end
def execute
credit_card = Users::CreditCar... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe Users::UpsertCreditCardValidationService, feature_category: :user_profile do
include CryptoHelpers
let_it_be(:user) { create(:user) }
let(:user_id) { user.id }
let(:network) { 'American Express' }
let(:holder_name) { 'John Smith' }
let... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module Users
class SetStatusService
include Gitlab::Allowable
attr_reader :current_user, :target_user, :params
def initialize(current_user, params)
@current_user = current_user
@params = params.dup
@t... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe Users::SetStatusService, feature_category: :user_management do
let(:current_user) { create(:user) }
subject(:service) { described_class.new(current_user, params) }
describe '#execute' do
shared_examples_for 'bumps user' do
it 'bumps ... |
Write RSpec test file for following ruby class
```ruby
# frozen_string_literal: true
module Users
class InProductMarketingEmailRecords
attr_reader :records
def initialize
@records = []
end
def save!
Users::InProductMarketingEmail.bulk_insert!(@records)
@records = []
end
d... | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe Users::InProductMarketingEmailRecords, feature_category: :onboarding do
let_it_be(:user) { create :user }
subject(:records) { described_class.new }
it 'initializes records' do
expect(subject.records).to match_array []
end
describe '#s... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.