summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2022-12-21 18:07:13 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2022-12-21 18:07:13 +0000
commitd380b256b976811e54dc4eb7c9ba3ecc5a9ab5be (patch)
tree08e2636afd8c045961c04b05361ad4880c767aa2 /spec
parentd4aa95428e9ae63a476196bc8c1193d3de253530 (diff)
downloadgitlab-ce-d380b256b976811e54dc4eb7c9ba3ecc5a9ab5be.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
-rw-r--r--spec/lib/gitlab/ci/pipeline/chain/populate_spec.rb5
-rw-r--r--spec/lib/gitlab/ci/status/bridge/factory_spec.rb8
-rw-r--r--spec/lib/gitlab/ci/templates/Jobs/code_quality_gitlab_ci_yaml_spec.rb11
-rw-r--r--spec/lib/gitlab/ci/templates/Jobs/sast_iac_gitlab_ci_yaml_spec.rb8
-rw-r--r--spec/lib/gitlab/ci/templates/Jobs/sast_iac_latest_gitlab_ci_yaml_spec.rb8
-rw-r--r--spec/lib/gitlab/ci/templates/Jobs/test_gitlab_ci_yaml_spec.rb11
-rw-r--r--spec/lib/gitlab/ci/templates/npm_spec.rb5
-rw-r--r--spec/lib/gitlab/ci/templates/terraform_latest_gitlab_ci_yaml_spec.rb9
-rw-r--r--spec/lib/gitlab/ci/templates/themekit_gitlab_ci_yaml_spec.rb5
-rw-r--r--spec/models/event_spec.rb15
-rw-r--r--spec/models/members/member_role_spec.rb23
-rw-r--r--spec/requests/api/import_github_spec.rb104
-rw-r--r--spec/requests/users_controller_spec.rb12
-rw-r--r--spec/services/ci/create_downstream_pipeline_service_spec.rb6
-rw-r--r--spec/services/ci/create_pipeline_service/rules_spec.rb5
-rw-r--r--spec/services/ci/create_pipeline_service_spec.rb26
-rw-r--r--spec/services/import/github/gists_import_service_spec.rb24
17 files changed, 221 insertions, 64 deletions
diff --git a/spec/lib/gitlab/ci/pipeline/chain/populate_spec.rb b/spec/lib/gitlab/ci/pipeline/chain/populate_spec.rb
index 62de4d2e96d..91bb94bbb11 100644
--- a/spec/lib/gitlab/ci/pipeline/chain/populate_spec.rb
+++ b/spec/lib/gitlab/ci/pipeline/chain/populate_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-RSpec.describe Gitlab::Ci::Pipeline::Chain::Populate do
+RSpec.describe Gitlab::Ci::Pipeline::Chain::Populate, feature_category: :continuous_integration do
let_it_be(:project) { create(:project, :repository) }
let_it_be(:user) { create(:user) }
@@ -90,7 +90,8 @@ RSpec.describe Gitlab::Ci::Pipeline::Chain::Populate do
it 'appends an error about missing stages' do
expect(pipeline.errors.to_a)
- .to include 'No stages / jobs for this pipeline.'
+ .to include 'Pipeline will not run for the selected trigger. ' \
+ 'The rules configuration prevented any jobs from being added to the pipeline.'
end
it 'wastes pipeline iid' do
diff --git a/spec/lib/gitlab/ci/status/bridge/factory_spec.rb b/spec/lib/gitlab/ci/status/bridge/factory_spec.rb
index 6081f104e42..c13901a4776 100644
--- a/spec/lib/gitlab/ci/status/bridge/factory_spec.rb
+++ b/spec/lib/gitlab/ci/status/bridge/factory_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-RSpec.describe Gitlab::Ci::Status::Bridge::Factory do
+RSpec.describe Gitlab::Ci::Status::Bridge::Factory, feature_category: :continuous_integration do
let(:user) { create(:user) }
let(:project) { bridge.project }
let(:status) { factory.fabricate! }
@@ -59,13 +59,15 @@ RSpec.describe Gitlab::Ci::Status::Bridge::Factory do
context 'failed with downstream_pipeline_creation_failed' do
before do
- bridge.options = { downstream_errors: ['No stages / jobs for this pipeline.', 'other error'] }
+ bridge.options = { downstream_errors: ['Pipeline will not run for the selected trigger. ' \
+ 'The rules configuration prevented any jobs from being added to the pipeline.', 'other error'] }
bridge.failure_reason = 'downstream_pipeline_creation_failed'
end
it 'fabricates correct status_tooltip' do
expect(status.status_tooltip).to eq(
- "#{s_('CiStatusText|failed')} - (downstream pipeline can not be created, No stages / jobs for this pipeline., other error)"
+ "#{s_('CiStatusText|failed')} - (downstream pipeline can not be created, Pipeline will not run for the selected trigger. " \
+ "The rules configuration prevented any jobs from being added to the pipeline., other error)"
)
end
end
diff --git a/spec/lib/gitlab/ci/templates/Jobs/code_quality_gitlab_ci_yaml_spec.rb b/spec/lib/gitlab/ci/templates/Jobs/code_quality_gitlab_ci_yaml_spec.rb
index 16c5d7a4b6d..286f3d10b7f 100644
--- a/spec/lib/gitlab/ci/templates/Jobs/code_quality_gitlab_ci_yaml_spec.rb
+++ b/spec/lib/gitlab/ci/templates/Jobs/code_quality_gitlab_ci_yaml_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-RSpec.describe 'Jobs/Code-Quality.gitlab-ci.yml' do
+RSpec.describe 'Jobs/Code-Quality.gitlab-ci.yml', feature_category: :continuous_integration do
subject(:template) { Gitlab::Template::GitlabCiYmlTemplate.find('Jobs/Code-Quality') }
describe 'the created pipeline' do
@@ -63,7 +63,8 @@ RSpec.describe 'Jobs/Code-Quality.gitlab-ci.yml' do
context 'on master' do
it 'has no jobs' do
expect(build_names).to be_empty
- expect(pipeline.errors.full_messages).to match_array(["No stages / jobs for this pipeline."])
+ expect(pipeline.errors.full_messages).to match_array(['Pipeline will not run for the selected trigger. ' \
+ 'The rules configuration prevented any jobs from being added to the pipeline.'])
end
end
@@ -72,7 +73,8 @@ RSpec.describe 'Jobs/Code-Quality.gitlab-ci.yml' do
it 'has no jobs' do
expect(build_names).to be_empty
- expect(pipeline.errors.full_messages).to match_array(["No stages / jobs for this pipeline."])
+ expect(pipeline.errors.full_messages).to match_array(['Pipeline will not run for the selected trigger. ' \
+ 'The rules configuration prevented any jobs from being added to the pipeline.'])
end
end
@@ -81,7 +83,8 @@ RSpec.describe 'Jobs/Code-Quality.gitlab-ci.yml' do
it 'has no jobs' do
expect(build_names).to be_empty
- expect(pipeline.errors.full_messages).to match_array(["No stages / jobs for this pipeline."])
+ expect(pipeline.errors.full_messages).to match_array(['Pipeline will not run for the selected trigger. ' \
+ 'The rules configuration prevented any jobs from being added to the pipeline.'])
end
end
end
diff --git a/spec/lib/gitlab/ci/templates/Jobs/sast_iac_gitlab_ci_yaml_spec.rb b/spec/lib/gitlab/ci/templates/Jobs/sast_iac_gitlab_ci_yaml_spec.rb
index 8a5aea7c0f0..68d249e31f9 100644
--- a/spec/lib/gitlab/ci/templates/Jobs/sast_iac_gitlab_ci_yaml_spec.rb
+++ b/spec/lib/gitlab/ci/templates/Jobs/sast_iac_gitlab_ci_yaml_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-RSpec.describe 'Jobs/SAST-IaC.gitlab-ci.yml' do
+RSpec.describe 'Jobs/SAST-IaC.gitlab-ci.yml', feature_category: :continuous_integration do
subject(:template) { Gitlab::Template::GitlabCiYmlTemplate.find('Jobs/SAST-IaC') }
describe 'the created pipeline' do
@@ -50,7 +50,8 @@ RSpec.describe 'Jobs/SAST-IaC.gitlab-ci.yml' do
context 'on default branch' do
it 'has no jobs' do
expect(build_names).to be_empty
- expect(pipeline.errors.full_messages).to match_array(["No stages / jobs for this pipeline."])
+ expect(pipeline.errors.full_messages).to match_array(['Pipeline will not run for the selected trigger. ' \
+ 'The rules configuration prevented any jobs from being added to the pipeline.'])
end
end
@@ -59,7 +60,8 @@ RSpec.describe 'Jobs/SAST-IaC.gitlab-ci.yml' do
it 'has no jobs' do
expect(build_names).to be_empty
- expect(pipeline.errors.full_messages).to match_array(["No stages / jobs for this pipeline."])
+ expect(pipeline.errors.full_messages).to match_array(['Pipeline will not run for the selected trigger. ' \
+ 'The rules configuration prevented any jobs from being added to the pipeline.'])
end
end
end
diff --git a/spec/lib/gitlab/ci/templates/Jobs/sast_iac_latest_gitlab_ci_yaml_spec.rb b/spec/lib/gitlab/ci/templates/Jobs/sast_iac_latest_gitlab_ci_yaml_spec.rb
index d540b035f81..039a6a739dd 100644
--- a/spec/lib/gitlab/ci/templates/Jobs/sast_iac_latest_gitlab_ci_yaml_spec.rb
+++ b/spec/lib/gitlab/ci/templates/Jobs/sast_iac_latest_gitlab_ci_yaml_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-RSpec.describe 'Jobs/SAST-IaC.latest.gitlab-ci.yml' do
+RSpec.describe 'Jobs/SAST-IaC.latest.gitlab-ci.yml', feature_category: :continuous_integration do
subject(:template) { Gitlab::Template::GitlabCiYmlTemplate.find('Jobs/SAST-IaC.latest') }
describe 'the created pipeline' do
@@ -51,7 +51,8 @@ RSpec.describe 'Jobs/SAST-IaC.latest.gitlab-ci.yml' do
context 'on default branch' do
it 'has no jobs' do
expect(build_names).to be_empty
- expect(pipeline.errors.full_messages).to match_array(["No stages / jobs for this pipeline."])
+ expect(pipeline.errors.full_messages).to match_array(['Pipeline will not run for the selected trigger. ' \
+ 'The rules configuration prevented any jobs from being added to the pipeline.'])
end
end
@@ -60,7 +61,8 @@ RSpec.describe 'Jobs/SAST-IaC.latest.gitlab-ci.yml' do
it 'has no jobs' do
expect(build_names).to be_empty
- expect(pipeline.errors.full_messages).to match_array(["No stages / jobs for this pipeline."])
+ expect(pipeline.errors.full_messages).to match_array(['Pipeline will not run for the selected trigger. ' \
+ 'The rules configuration prevented any jobs from being added to the pipeline.'])
end
end
end
diff --git a/spec/lib/gitlab/ci/templates/Jobs/test_gitlab_ci_yaml_spec.rb b/spec/lib/gitlab/ci/templates/Jobs/test_gitlab_ci_yaml_spec.rb
index 7cf0cf3ed33..d73d8a15feb 100644
--- a/spec/lib/gitlab/ci/templates/Jobs/test_gitlab_ci_yaml_spec.rb
+++ b/spec/lib/gitlab/ci/templates/Jobs/test_gitlab_ci_yaml_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-RSpec.describe 'Jobs/Test.gitlab-ci.yml' do
+RSpec.describe 'Jobs/Test.gitlab-ci.yml', feature_category: :continuous_integration do
subject(:template) { Gitlab::Template::GitlabCiYmlTemplate.find('Jobs/Test') }
describe 'the created pipeline' do
@@ -63,7 +63,8 @@ RSpec.describe 'Jobs/Test.gitlab-ci.yml' do
context 'on master' do
it 'has no jobs' do
expect(build_names).to be_empty
- expect(pipeline.errors.full_messages).to match_array(["No stages / jobs for this pipeline."])
+ expect(pipeline.errors.full_messages).to match_array(['Pipeline will not run for the selected trigger. ' \
+ 'The rules configuration prevented any jobs from being added to the pipeline.'])
end
end
@@ -72,7 +73,8 @@ RSpec.describe 'Jobs/Test.gitlab-ci.yml' do
it 'has no jobs' do
expect(build_names).to be_empty
- expect(pipeline.errors.full_messages).to match_array(["No stages / jobs for this pipeline."])
+ expect(pipeline.errors.full_messages).to match_array(['Pipeline will not run for the selected trigger. ' \
+ 'The rules configuration prevented any jobs from being added to the pipeline.'])
end
end
@@ -81,7 +83,8 @@ RSpec.describe 'Jobs/Test.gitlab-ci.yml' do
it 'has no jobs' do
expect(build_names).to be_empty
- expect(pipeline.errors.full_messages).to match_array(["No stages / jobs for this pipeline."])
+ expect(pipeline.errors.full_messages).to match_array(['Pipeline will not run for the selected trigger. ' \
+ 'The rules configuration prevented any jobs from being added to the pipeline.'])
end
end
end
diff --git a/spec/lib/gitlab/ci/templates/npm_spec.rb b/spec/lib/gitlab/ci/templates/npm_spec.rb
index 55fd4675f11..a949a7ccfb1 100644
--- a/spec/lib/gitlab/ci/templates/npm_spec.rb
+++ b/spec/lib/gitlab/ci/templates/npm_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-RSpec.describe 'npm.gitlab-ci.yml' do
+RSpec.describe 'npm.gitlab-ci.yml', feature_category: :continuous_integration do
subject(:template) { Gitlab::Template::GitlabCiYmlTemplate.find('npm') }
describe 'the created pipeline' do
@@ -43,7 +43,8 @@ RSpec.describe 'npm.gitlab-ci.yml' do
shared_examples 'no pipeline created' do
it 'does not create a pipeline because the only job (publish) is not created' do
expect(build_names).to be_empty
- expect(pipeline.errors.full_messages).to match_array(["No stages / jobs for this pipeline."])
+ expect(pipeline.errors.full_messages).to match_array(['Pipeline will not run for the selected trigger. ' \
+ 'The rules configuration prevented any jobs from being added to the pipeline.'])
end
end
diff --git a/spec/lib/gitlab/ci/templates/terraform_latest_gitlab_ci_yaml_spec.rb b/spec/lib/gitlab/ci/templates/terraform_latest_gitlab_ci_yaml_spec.rb
index 6ae51f9783b..a81f29d0d01 100644
--- a/spec/lib/gitlab/ci/templates/terraform_latest_gitlab_ci_yaml_spec.rb
+++ b/spec/lib/gitlab/ci/templates/terraform_latest_gitlab_ci_yaml_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-RSpec.describe 'Terraform.latest.gitlab-ci.yml' do
+RSpec.describe 'Terraform.latest.gitlab-ci.yml', feature_category: :continuous_integration do
before do
allow(Gitlab::Template::GitlabCiYmlTemplate).to receive(:excluded_patterns).and_return([])
end
@@ -66,7 +66,12 @@ RSpec.describe 'Terraform.latest.gitlab-ci.yml' do
it 'does not create a branch pipeline', :aggregate_failures do
expect(branch_build_names).to be_empty
- expect(branch_pipeline.errors.full_messages).to match_array(["No stages / jobs for this pipeline."])
+ expect(branch_pipeline.errors.full_messages).to match_array(
+ [
+ 'Pipeline will not run for the selected trigger. ' \
+ 'The rules configuration prevented any jobs from being added to the pipeline.'
+ ]
+ )
end
end
end
diff --git a/spec/lib/gitlab/ci/templates/themekit_gitlab_ci_yaml_spec.rb b/spec/lib/gitlab/ci/templates/themekit_gitlab_ci_yaml_spec.rb
index 157fd39f1cc..607db33f61a 100644
--- a/spec/lib/gitlab/ci/templates/themekit_gitlab_ci_yaml_spec.rb
+++ b/spec/lib/gitlab/ci/templates/themekit_gitlab_ci_yaml_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-RSpec.describe 'ThemeKit.gitlab-ci.yml' do
+RSpec.describe 'ThemeKit.gitlab-ci.yml', feature_category: :continuous_integration do
before do
allow(Gitlab::Template::GitlabCiYmlTemplate).to receive(:excluded_patterns).and_return([])
end
@@ -52,7 +52,8 @@ RSpec.describe 'ThemeKit.gitlab-ci.yml' do
it 'has no jobs' do
expect(build_names).to be_empty
- expect(pipeline.errors.full_messages).to match_array(["No stages / jobs for this pipeline."])
+ expect(pipeline.errors.full_messages).to match_array(['Pipeline will not run for the selected trigger. ' \
+ 'The rules configuration prevented any jobs from being added to the pipeline.'])
end
end
end
diff --git a/spec/models/event_spec.rb b/spec/models/event_spec.rb
index 667f3ddff72..f170eeb5841 100644
--- a/spec/models/event_spec.rb
+++ b/spec/models/event_spec.rb
@@ -102,7 +102,20 @@ RSpec.describe Event, feature_category: :users do
end
describe 'scopes' do
- describe 'created_at' do
+ describe '.for_issue' do
+ let(:issue_event) { create(:event, :for_issue, project: project) }
+ let(:work_item_event) { create(:event, :for_work_item, project: project) }
+
+ before do
+ create(:event, :for_design, project: project)
+ end
+
+ it 'returns events for Issue and WorkItem target_type' do
+ expect(described_class.for_issue).to contain_exactly(issue_event, work_item_event)
+ end
+ end
+
+ describe '.created_at' do
it 'can find the right event' do
time = 1.day.ago
event = create(:event, created_at: time, project: project)
diff --git a/spec/models/members/member_role_spec.rb b/spec/models/members/member_role_spec.rb
index f9d6757bb90..b118a3c0968 100644
--- a/spec/models/members/member_role_spec.rb
+++ b/spec/models/members/member_role_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-RSpec.describe MemberRole do
+RSpec.describe MemberRole, feature_category: :authentication_and_authorization do
describe 'associations' do
it { is_expected.to belong_to(:namespace) }
it { is_expected.to have_many(:members) }
@@ -14,6 +14,27 @@ RSpec.describe MemberRole do
it { is_expected.to validate_presence_of(:namespace) }
it { is_expected.to validate_presence_of(:base_access_level) }
+ context 'for attributes_locked_after_member_associated' do
+ context 'when assigned to member' do
+ it 'cannot be changed' do
+ member_role.save!
+ member_role.members << create(:project_member)
+
+ expect(member_role).not_to be_valid
+ expect(member_role.errors.messages[:base]).to include(
+ s_("MemberRole|cannot be changed because it is already assigned to a user. "\
+ "Please create a new Member Role instead")
+ )
+ end
+ end
+
+ context 'when not assigned to member' do
+ it 'can be changed' do
+ expect(member_role).to be_valid
+ end
+ end
+ end
+
context 'when for namespace' do
let_it_be(:root_group) { create(:group) }
diff --git a/spec/requests/api/import_github_spec.rb b/spec/requests/api/import_github_spec.rb
index dce82f1cf37..ccf16434ad9 100644
--- a/spec/requests/api/import_github_spec.rb
+++ b/spec/requests/api/import_github_spec.rb
@@ -6,33 +6,35 @@ RSpec.describe API::ImportGithub, feature_category: :importers do
let(:token) { "asdasd12345" }
let(:provider) { :github }
let(:access_params) { { github_access_token: token } }
+ let(:provider_username) { user.username }
+ let(:provider_user) { double('provider', login: provider_username).as_null_object }
+ let(:provider_repo) do
+ {
+ name: 'vim',
+ full_name: "#{provider_username}/vim",
+ owner: double('provider', login: provider_username),
+ description: 'provider',
+ private: false,
+ clone_url: 'https://fake.url/vim.git',
+ has_wiki: true
+ }
+ end
- describe "POST /import/github" do
- let(:user) { create(:user) }
- let(:project) { create(:project) }
- let(:provider_username) { user.username }
- let(:provider_user) { double('provider', login: provider_username) }
- let(:provider_repo) do
- {
- name: 'vim',
- full_name: "#{provider_username}/vim",
- owner: double('provider', login: provider_username),
- description: 'provider',
- private: false,
- clone_url: 'https://fake.url/vim.git',
- has_wiki: true
- }
- end
+ let(:client) { double('client', user: provider_user, repository: provider_repo) }
- before do
- Grape::Endpoint.before_each do |endpoint|
- allow(endpoint).to receive(:client).and_return(double('client', user: provider_user, repository: provider_repo).as_null_object)
- end
+ before do
+ Grape::Endpoint.before_each do |endpoint|
+ allow(endpoint).to receive(:client).and_return(client)
end
+ end
- after do
- Grape::Endpoint.before_each nil
- end
+ after do
+ Grape::Endpoint.before_each nil
+ end
+
+ describe "POST /import/github" do
+ let_it_be(:user) { create(:user) }
+ let_it_be(:project) { create(:project) }
it 'rejects requests when Github Importer is disabled' do
stub_application_setting(import_sources: nil)
@@ -150,4 +152,60 @@ RSpec.describe API::ImportGithub, feature_category: :importers do
end
end
end
+
+ describe 'POST /import/github/gists' do
+ let_it_be(:user) { create(:user) }
+ let(:params) { { personal_access_token: token } }
+
+ context 'when gists import was started' do
+ before do
+ allow(Import::Github::GistsImportService)
+ .to receive(:new).with(user, client, access_params)
+ .and_return(double(execute: { status: :success }))
+ end
+
+ it 'returns 202' do
+ post api('/import/github/gists', user), params: params
+
+ expect(response).to have_gitlab_http_status(:accepted)
+ end
+ end
+
+ context 'when gists import is in progress' do
+ before do
+ allow(Import::Github::GistsImportService)
+ .to receive(:new).with(user, client, access_params)
+ .and_return(double(execute: { status: :error, message: 'Import already in progress', http_status: :unprocessable_entity }))
+ end
+
+ it 'returns 422 error' do
+ post api('/import/github/gists', user), params: params
+
+ expect(response).to have_gitlab_http_status(:unprocessable_entity)
+ expect(json_response['errors']).to eq('Import already in progress')
+ end
+ end
+
+ context 'when unauthenticated user' do
+ it 'returns 403 error' do
+ post api('/import/github/gists'), params: params
+
+ expect(response).to have_gitlab_http_status(:unauthorized)
+ end
+ end
+
+ context 'when rate limit reached' do
+ before do
+ allow(Import::Github::GistsImportService)
+ .to receive(:new).with(user, client, access_params)
+ .and_raise(Gitlab::GithubImport::RateLimitError)
+ end
+
+ it 'returns 429 error' do
+ post api('/import/github/gists', user), params: params
+
+ expect(response).to have_gitlab_http_status(:too_many_requests)
+ end
+ end
+ end
end
diff --git a/spec/requests/users_controller_spec.rb b/spec/requests/users_controller_spec.rb
index 608284c05f3..11d8be24e06 100644
--- a/spec/requests/users_controller_spec.rb
+++ b/spec/requests/users_controller_spec.rb
@@ -464,6 +464,18 @@ RSpec.describe UsersController, feature_category: :user_management do
expect(response.body).not_to be_empty
end
+ it 'renders the correct url for issues and work items' do
+ work_item = create(:work_item, :task, project: project)
+ issue = create(:issue, project: project)
+ EventCreateService.new.open_issue(work_item, public_user)
+ EventCreateService.new.open_issue(issue, public_user)
+
+ get user_calendar_activities_url public_user.username
+
+ expect(response.body).to include(project_work_items_path(project, work_item.iid, iid_path: true))
+ expect(response.body).to include(project_issue_path(project, issue))
+ end
+
it 'avoids N+1 queries', :request_store do
get user_calendar_activities_url public_user.username
diff --git a/spec/services/ci/create_downstream_pipeline_service_spec.rb b/spec/services/ci/create_downstream_pipeline_service_spec.rb
index bcdb2b4f796..6046f9b8e19 100644
--- a/spec/services/ci/create_downstream_pipeline_service_spec.rb
+++ b/spec/services/ci/create_downstream_pipeline_service_spec.rb
@@ -825,11 +825,13 @@ RSpec.describe Ci::CreateDownstreamPipelineService, '#execute', feature_category
it 'does not create a pipeline and drops the bridge' do
expect { subject }.not_to change(downstream_project.ci_pipelines, :count)
expect(subject).to be_error
- expect(subject.message).to match_array(["No stages / jobs for this pipeline."])
+ expect(subject.message).to match_array(['Pipeline will not run for the selected trigger. ' \
+ 'The rules configuration prevented any jobs from being added to the pipeline.'])
expect(bridge.reload).to be_failed
expect(bridge.failure_reason).to eq('downstream_pipeline_creation_failed')
- expect(bridge.options[:downstream_errors]).to eq(['No stages / jobs for this pipeline.'])
+ expect(bridge.options[:downstream_errors]).to match_array(['Pipeline will not run for the selected trigger. ' \
+ 'The rules configuration prevented any jobs from being added to the pipeline.'])
end
end
diff --git a/spec/services/ci/create_pipeline_service/rules_spec.rb b/spec/services/ci/create_pipeline_service/rules_spec.rb
index b866293393b..26bb8b7d006 100644
--- a/spec/services/ci/create_pipeline_service/rules_spec.rb
+++ b/spec/services/ci/create_pipeline_service/rules_spec.rb
@@ -1,7 +1,7 @@
# frozen_string_literal: true
require 'spec_helper'
-RSpec.describe Ci::CreatePipelineService, :yaml_processor_feature_flag_corectness do
+RSpec.describe Ci::CreatePipelineService, :yaml_processor_feature_flag_corectness, feature_category: :pipeline_authoring do
let(:project) { create(:project, :repository) }
let(:user) { project.first_owner }
let(:ref) { 'refs/heads/master' }
@@ -1166,7 +1166,8 @@ RSpec.describe Ci::CreatePipelineService, :yaml_processor_feature_flag_corectnes
let(:ref) { 'refs/heads/master' }
it 'invalidates the pipeline with an empty jobs error' do
- expect(pipeline.errors[:base]).to include('No stages / jobs for this pipeline.')
+ expect(pipeline.errors[:base]).to include('Pipeline will not run for the selected trigger. ' \
+ 'The rules configuration prevented any jobs from being added to the pipeline.')
expect(pipeline).not_to be_persisted
end
end
diff --git a/spec/services/ci/create_pipeline_service_spec.rb b/spec/services/ci/create_pipeline_service_spec.rb
index 8628e95ba80..3d143f1142a 100644
--- a/spec/services/ci/create_pipeline_service_spec.rb
+++ b/spec/services/ci/create_pipeline_service_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-RSpec.describe Ci::CreatePipelineService, :yaml_processor_feature_flag_corectness, :clean_gitlab_redis_cache do
+RSpec.describe Ci::CreatePipelineService, :yaml_processor_feature_flag_corectness, :clean_gitlab_redis_cache, feature_category: :continuous_integration do
include ProjectForksHelper
let_it_be_with_refind(:project) { create(:project, :repository) }
@@ -684,7 +684,8 @@ RSpec.describe Ci::CreatePipelineService, :yaml_processor_feature_flag_corectnes
result = execute_service
expect(result).to be_error
- expect(result.message).to eq('No stages / jobs for this pipeline.')
+ expect(result.message).to eq('Pipeline will not run for the selected trigger. ' \
+ 'The rules configuration prevented any jobs from being added to the pipeline.')
expect(result.payload).not_to be_persisted
expect(Ci::Build.all).to be_empty
expect(Ci::Pipeline.count).to eq(0)
@@ -1423,9 +1424,11 @@ RSpec.describe Ci::CreatePipelineService, :yaml_processor_feature_flag_corectnes
it 'does not create a detached merge request pipeline', :aggregate_failures do
expect(response).to be_error
- expect(response.message).to eq('No stages / jobs for this pipeline.')
+ expect(response.message).to eq('Pipeline will not run for the selected trigger. ' \
+ 'The rules configuration prevented any jobs from being added to the pipeline.')
expect(pipeline).not_to be_persisted
- expect(pipeline.errors[:base]).to eq(['No stages / jobs for this pipeline.'])
+ expect(pipeline.errors[:base]).to eq(['Pipeline will not run for the selected trigger. ' \
+ 'The rules configuration prevented any jobs from being added to the pipeline.'])
end
end
end
@@ -1633,7 +1636,8 @@ RSpec.describe Ci::CreatePipelineService, :yaml_processor_feature_flag_corectnes
it 'does not create a detached merge request pipeline', :aggregate_failures do
expect(response).to be_error
- expect(response.message).to eq('No stages / jobs for this pipeline.')
+ expect(response.message).to eq('Pipeline will not run for the selected trigger. ' \
+ 'The rules configuration prevented any jobs from being added to the pipeline.')
expect(pipeline).not_to be_persisted
end
end
@@ -1669,7 +1673,8 @@ RSpec.describe Ci::CreatePipelineService, :yaml_processor_feature_flag_corectnes
it 'does not create a detached merge request pipeline', :aggregate_failures do
expect(response).to be_error
- expect(response.message).to eq('No stages / jobs for this pipeline.')
+ expect(response.message).to eq('Pipeline will not run for the selected trigger. ' \
+ 'The rules configuration prevented any jobs from being added to the pipeline.')
expect(pipeline).not_to be_persisted
end
end
@@ -1697,7 +1702,8 @@ RSpec.describe Ci::CreatePipelineService, :yaml_processor_feature_flag_corectnes
it 'does not create a detached merge request pipeline', :aggregate_failures do
expect(response).to be_error
- expect(response.message).to eq('No stages / jobs for this pipeline.')
+ expect(response.message).to eq('Pipeline will not run for the selected trigger. ' \
+ 'The rules configuration prevented any jobs from being added to the pipeline.')
expect(pipeline).not_to be_persisted
end
end
@@ -1727,7 +1733,8 @@ RSpec.describe Ci::CreatePipelineService, :yaml_processor_feature_flag_corectnes
it 'does not create a detached merge request pipeline', :aggregate_failures do
expect(response).to be_error
- expect(response.message).to eq('No stages / jobs for this pipeline.')
+ expect(response.message).to eq('Pipeline will not run for the selected trigger. ' \
+ 'The rules configuration prevented any jobs from being added to the pipeline.')
expect(pipeline).not_to be_persisted
end
end
@@ -1755,7 +1762,8 @@ RSpec.describe Ci::CreatePipelineService, :yaml_processor_feature_flag_corectnes
it 'does not create a detached merge request pipeline', :aggregate_failures do
expect(response).to be_error
- expect(response.message).to eq('No stages / jobs for this pipeline.')
+ expect(response.message).to eq('Pipeline will not run for the selected trigger. ' \
+ 'The rules configuration prevented any jobs from being added to the pipeline.')
expect(pipeline).not_to be_persisted
end
end
diff --git a/spec/services/import/github/gists_import_service_spec.rb b/spec/services/import/github/gists_import_service_spec.rb
index c5d73e6479d..4edb38145ed 100644
--- a/spec/services/import/github/gists_import_service_spec.rb
+++ b/spec/services/import/github/gists_import_service_spec.rb
@@ -3,15 +3,18 @@
require 'spec_helper'
RSpec.describe Import::Github::GistsImportService, feature_category: :importer do
- subject(:import) { described_class.new(user, params) }
+ subject(:import) { described_class.new(user, client, params) }
let_it_be(:user) { create(:user) }
let(:params) { { github_access_token: 'token' } }
let(:import_status) { instance_double('Gitlab::GithubGistsImport::Status') }
+ let(:client) { Gitlab::GithubImport::Client.new(params[:github_access_token]) }
+ let(:octokit_user) { { login: 'user_login' } }
describe '#execute', :aggregate_failures do
before do
allow(Gitlab::GithubGistsImport::Status).to receive(:new).and_return(import_status)
+ allow(client.octokit).to receive(:user).and_return(octokit_user)
end
context 'when import in progress' do
@@ -43,5 +46,24 @@ RSpec.describe Import::Github::GistsImportService, feature_category: :importer d
expect(import.execute).to eq({ status: :success })
end
end
+
+ context 'when user token is invalid' do
+ before do
+ allow(client.octokit).to receive(:user).and_raise(Octokit::Unauthorized)
+ allow(import_status).to receive(:started?).and_return(false)
+ end
+
+ let(:expected_result) do
+ {
+ http_status: 401,
+ message: 'Access denied to the GitHub account.',
+ status: :error
+ }
+ end
+
+ it 'returns 401 error' do
+ expect(import.execute).to eq(expected_result)
+ end
+ end
end
end