summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2021-07-07 15:07:24 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2021-07-07 15:07:24 +0000
commite1e58fabfa768f47ab82f87ba50b1f2793a8258a (patch)
tree1dcb7d67bb70bbfed8e3b1a632db9d9aaf38f85f /spec
parent9ceb2dbab3296721c576572e96691a19e2506069 (diff)
downloadgitlab-ce-e1e58fabfa768f47ab82f87ba50b1f2793a8258a.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
-rw-r--r--spec/lib/bulk_imports/groups/pipelines/group_avatar_pipeline_spec.rb64
-rw-r--r--spec/lib/gitlab/background_migration/update_jira_tracker_data_deployment_type_based_on_url_spec.rb2
-rw-r--r--spec/lib/gitlab/import_export/snippet_repo_restorer_spec.rb2
-rw-r--r--spec/lib/gitlab/integrations/sti_type_spec.rb8
-rw-r--r--spec/lib/gitlab/sidekiq_middleware/worker_context/client_spec.rb36
-rw-r--r--spec/migrations/rename_services_to_integrations_spec.rb255
-rw-r--r--spec/models/integration_spec.rb69
-rw-r--r--spec/models/snippet_spec.rb8
-rw-r--r--spec/requests/api/branches_spec.rb3
-rw-r--r--spec/requests/api/graphql/mutations/branches/create_spec.rb3
-rw-r--r--spec/requests/api/graphql/mutations/snippets/create_spec.rb4
-rw-r--r--spec/requests/api/project_snippets_spec.rb2
-rw-r--r--spec/requests/api/snippets_spec.rb2
-rw-r--r--spec/services/branches/create_service_spec.rb15
-rw-r--r--spec/services/commits/commit_patch_service_spec.rb2
15 files changed, 382 insertions, 93 deletions
diff --git a/spec/lib/bulk_imports/groups/pipelines/group_avatar_pipeline_spec.rb b/spec/lib/bulk_imports/groups/pipelines/group_avatar_pipeline_spec.rb
index 964e02b358a..c68284aa580 100644
--- a/spec/lib/bulk_imports/groups/pipelines/group_avatar_pipeline_spec.rb
+++ b/spec/lib/bulk_imports/groups/pipelines/group_avatar_pipeline_spec.rb
@@ -23,47 +23,55 @@ RSpec.describe BulkImports::Groups::Pipelines::GroupAvatarPipeline do
subject { described_class.new(context) }
- describe '#extract' do
- it 'downloads the group avatar' do
- expect_next_instance_of(
- BulkImports::FileDownloadService,
+ describe '#run' do
+ it 'updates the group avatar' do
+ avatar_path = 'spec/fixtures/dk.png'
+ stub_file_download(
+ avatar_path,
configuration: context.configuration,
relative_url: "/groups/source%2Ffull%2Fpath/avatar",
dir: an_instance_of(String),
file_size_limit: Avatarable::MAXIMUM_FILE_SIZE,
allowed_content_types: described_class::ALLOWED_AVATAR_DOWNLOAD_TYPES
- ) do |downloader|
- expect(downloader).to receive(:execute)
- end
+ )
- subject.run
- end
- end
+ expect { subject.run }.to change(context.group, :avatar)
- describe '#transform' do
- it 'returns the given data' do
- expect(subject.transform(nil, :value)).to eq(:value)
+ expect(context.group.avatar.filename).to eq(File.basename(avatar_path))
end
- end
- describe '#load' do
- it 'updates the group avatar' do
- avatar_path = 'spec/fixtures/dk.png'
- data = { filepath: fixture_file_upload(avatar_path) }
+ it 'raises an error when the avatar upload fails' do
+ avatar_path = 'spec/fixtures/aosp_manifest.xml'
+ stub_file_download(
+ avatar_path,
+ configuration: context.configuration,
+ relative_url: "/groups/source%2Ffull%2Fpath/avatar",
+ dir: an_instance_of(String),
+ file_size_limit: Avatarable::MAXIMUM_FILE_SIZE,
+ allowed_content_types: described_class::ALLOWED_AVATAR_DOWNLOAD_TYPES
+ )
- expect { subject.load(context, data) }.to change(group, :avatar)
+ expect_next_instance_of(Gitlab::Import::Logger) do |logger|
+ expect(logger).to receive(:error)
+ .with(
+ bulk_import_id: context.bulk_import.id,
+ bulk_import_entity_id: context.entity.id,
+ bulk_import_entity_type: context.entity.source_type,
+ context_extra: context.extra,
+ exception_class: "BulkImports::Groups::Pipelines::GroupAvatarPipeline::GroupAvatarLoadingError",
+ exception_message: "Avatar file format is not supported. Please try one of the following supported formats: image/png, image/jpeg, image/gif, image/bmp, image/tiff, image/vnd.microsoft.icon",
+ pipeline_class: "BulkImports::Groups::Pipelines::GroupAvatarPipeline",
+ pipeline_step: :loader
+ )
+ end
- expect(FileUtils.identical?(avatar_path, group.avatar.file.file)).to eq(true)
+ expect { subject.run }.to change(BulkImports::Failure, :count)
end
+ end
- it 'raises an error when the avatar upload fails' do
- avatar_path = 'spec/fixtures/aosp_manifest.xml'
- data = { filepath: fixture_file_upload(avatar_path) }
-
- expect { subject.load(context, data) }.to raise_error(
- described_class::GroupAvatarLoadingError,
- "Avatar file format is not supported. Please try one of the following supported formats: image/png, image/jpeg, image/gif, image/bmp, image/tiff, image/vnd.microsoft.icon"
- )
+ def stub_file_download(filepath = 'file/path.png', **params)
+ expect_next_instance_of(BulkImports::FileDownloadService, params.presence) do |downloader|
+ expect(downloader).to receive(:execute).and_return(filepath)
end
end
end
diff --git a/spec/lib/gitlab/background_migration/update_jira_tracker_data_deployment_type_based_on_url_spec.rb b/spec/lib/gitlab/background_migration/update_jira_tracker_data_deployment_type_based_on_url_spec.rb
index f7466a2ddfd..b96d3f7f0b5 100644
--- a/spec/lib/gitlab/background_migration/update_jira_tracker_data_deployment_type_based_on_url_spec.rb
+++ b/spec/lib/gitlab/background_migration/update_jira_tracker_data_deployment_type_based_on_url_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-RSpec.describe Gitlab::BackgroundMigration::UpdateJiraTrackerDataDeploymentTypeBasedOnUrl do
+RSpec.describe Gitlab::BackgroundMigration::UpdateJiraTrackerDataDeploymentTypeBasedOnUrl, schema: 20210421163509 do
let(:services_table) { table(:services) }
let(:service_jira_cloud) { services_table.create!(id: 1, type: 'JiraService') }
let(:service_jira_server) { services_table.create!(id: 2, type: 'JiraService') }
diff --git a/spec/lib/gitlab/import_export/snippet_repo_restorer_spec.rb b/spec/lib/gitlab/import_export/snippet_repo_restorer_spec.rb
index fe934cadedd..c1661cf02b6 100644
--- a/spec/lib/gitlab/import_export/snippet_repo_restorer_spec.rb
+++ b/spec/lib/gitlab/import_export/snippet_repo_restorer_spec.rb
@@ -29,7 +29,7 @@ RSpec.describe Gitlab::ImportExport::SnippetRepoRestorer do
expect(restorer.restore).to be_truthy
end.to change { SnippetRepository.count }.by(1)
- blob = snippet.repository.blob_at('HEAD', snippet.file_name)
+ blob = snippet.repository.blob_at(snippet.default_branch, snippet.file_name)
expect(blob).not_to be_nil
expect(blob.data).to eq(snippet.content)
end
diff --git a/spec/lib/gitlab/integrations/sti_type_spec.rb b/spec/lib/gitlab/integrations/sti_type_spec.rb
index 3154872ed04..70b93d6a4b5 100644
--- a/spec/lib/gitlab/integrations/sti_type_spec.rb
+++ b/spec/lib/gitlab/integrations/sti_type_spec.rb
@@ -9,7 +9,7 @@ RSpec.describe Gitlab::Integrations::StiType do
context 'SQL SELECT' do
let(:expected_sql) do
<<~SQL.strip
- SELECT "services".* FROM "services" WHERE "services"."type" = 'AsanaService'
+ SELECT "integrations".* FROM "integrations" WHERE "integrations"."type" = 'AsanaService'
SQL
end
@@ -25,7 +25,7 @@ RSpec.describe Gitlab::Integrations::StiType do
context 'SQL CREATE' do
let(:expected_sql) do
<<~SQL.strip
- INSERT INTO "services" ("type") VALUES ('AsanaService')
+ INSERT INTO "integrations" ("type") VALUES ('AsanaService')
SQL
end
@@ -42,7 +42,7 @@ RSpec.describe Gitlab::Integrations::StiType do
context 'SQL UPDATE' do
let(:expected_sql) do
<<~SQL.strip
- UPDATE "services" SET "type" = 'AsanaService'
+ UPDATE "integrations" SET "type" = 'AsanaService'
SQL
end
@@ -61,7 +61,7 @@ RSpec.describe Gitlab::Integrations::StiType do
context 'SQL DELETE' do
let(:expected_sql) do
<<~SQL.strip
- DELETE FROM "services" WHERE "services"."type" = 'AsanaService'
+ DELETE FROM "integrations" WHERE "integrations"."type" = 'AsanaService'
SQL
end
diff --git a/spec/lib/gitlab/sidekiq_middleware/worker_context/client_spec.rb b/spec/lib/gitlab/sidekiq_middleware/worker_context/client_spec.rb
index fff925f8532..d6cc787f53d 100644
--- a/spec/lib/gitlab/sidekiq_middleware/worker_context/client_spec.rb
+++ b/spec/lib/gitlab/sidekiq_middleware/worker_context/client_spec.rb
@@ -11,6 +11,8 @@ RSpec.describe Gitlab::SidekiqMiddleware::WorkerContext::Client do
include ApplicationWorker
+ feature_category :issue_tracking
+
def self.job_for_args(args)
jobs.find { |job| job['args'] == args }
end
@@ -41,5 +43,39 @@ RSpec.describe Gitlab::SidekiqMiddleware::WorkerContext::Client do
expect(job1['meta.user']).to eq(user_per_job['job1'].username)
expect(job2['meta.user']).to eq(user_per_job['job2'].username)
end
+
+ context 'when the feature category is set in the context_proc' do
+ it 'takes the feature category from the worker, not the caller' do
+ TestWithContextWorker.bulk_perform_async_with_contexts(
+ %w(job1 job2),
+ arguments_proc: -> (name) { [name, 1, 2, 3] },
+ context_proc: -> (_) { { feature_category: 'code_review' } }
+ )
+
+ job1 = TestWithContextWorker.job_for_args(['job1', 1, 2, 3])
+ job2 = TestWithContextWorker.job_for_args(['job2', 1, 2, 3])
+
+ expect(job1['meta.feature_category']).to eq('issue_tracking')
+ expect(job2['meta.feature_category']).to eq('issue_tracking')
+ end
+ end
+
+ context 'when the feature category is already set in the surrounding block' do
+ it 'takes the feature category from the worker, not the caller' do
+ Gitlab::ApplicationContext.with_context(feature_category: 'authentication_and_authorization') do
+ TestWithContextWorker.bulk_perform_async_with_contexts(
+ %w(job1 job2),
+ arguments_proc: -> (name) { [name, 1, 2, 3] },
+ context_proc: -> (_) { {} }
+ )
+ end
+
+ job1 = TestWithContextWorker.job_for_args(['job1', 1, 2, 3])
+ job2 = TestWithContextWorker.job_for_args(['job2', 1, 2, 3])
+
+ expect(job1['meta.feature_category']).to eq('issue_tracking')
+ expect(job2['meta.feature_category']).to eq('issue_tracking')
+ end
+ end
end
end
diff --git a/spec/migrations/rename_services_to_integrations_spec.rb b/spec/migrations/rename_services_to_integrations_spec.rb
new file mode 100644
index 00000000000..812dd5efecb
--- /dev/null
+++ b/spec/migrations/rename_services_to_integrations_spec.rb
@@ -0,0 +1,255 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+require_migration!
+
+RSpec.describe RenameServicesToIntegrations do
+ let(:migration) { described_class.new }
+ let(:namespaces) { table(:namespaces) }
+ let(:projects) { table(:projects) }
+ let(:integrations) { table(:integrations) }
+ let(:services) { table(:services) }
+
+ before do
+ @namespace = namespaces.create!(name: 'foo', path: 'foo')
+ @project = projects.create!(namespace_id: @namespace.id)
+ end
+
+ RSpec.shared_examples 'a table (or view) with triggers' do
+ describe 'INSERT tracker trigger' do
+ it 'sets `has_external_issue_tracker` to true when active `issue_tracker` is inserted' do
+ expect do
+ subject.create!(category: 'issue_tracker', active: true, project_id: @project.id)
+ end.to change { @project.reload.has_external_issue_tracker }.to(true)
+ end
+
+ it 'does not set `has_external_issue_tracker` to true when integration is for a different project' do
+ different_project = projects.create!(namespace_id: @namespace.id)
+
+ expect do
+ subject.create!(category: 'issue_tracker', active: true, project_id: different_project.id)
+ end.not_to change { @project.reload.has_external_issue_tracker }
+ end
+
+ it 'does not set `has_external_issue_tracker` to true when inactive `issue_tracker` is inserted' do
+ expect do
+ subject.create!(category: 'issue_tracker', active: false, project_id: @project.id)
+ end.not_to change { @project.reload.has_external_issue_tracker }
+ end
+
+ it 'does not set `has_external_issue_tracker` to true when a non-`issue tracker` active integration is inserted' do
+ expect do
+ subject.create!(category: 'my_type', active: true, project_id: @project.id)
+ end.not_to change { @project.reload.has_external_issue_tracker }
+ end
+ end
+
+ describe 'UPDATE tracker trigger' do
+ it 'sets `has_external_issue_tracker` to true when `issue_tracker` is made active' do
+ integration = subject.create!(category: 'issue_tracker', active: false, project_id: @project.id)
+
+ expect do
+ integration.update!(active: true)
+ end.to change { @project.reload.has_external_issue_tracker }.to(true)
+ end
+
+ it 'sets `has_external_issue_tracker` to false when `issue_tracker` is made inactive' do
+ integration = subject.create!(category: 'issue_tracker', active: true, project_id: @project.id)
+
+ expect do
+ integration.update!(active: false)
+ end.to change { @project.reload.has_external_issue_tracker }.to(false)
+ end
+
+ it 'sets `has_external_issue_tracker` to false when `issue_tracker` is made inactive, and an inactive `issue_tracker` exists' do
+ subject.create!(category: 'issue_tracker', active: false, project_id: @project.id)
+ integration = subject.create!(category: 'issue_tracker', active: true, project_id: @project.id)
+
+ expect do
+ integration.update!(active: false)
+ end.to change { @project.reload.has_external_issue_tracker }.to(false)
+ end
+
+ it 'does not change `has_external_issue_tracker` when `issue_tracker` is made inactive, if an active `issue_tracker` exists' do
+ subject.create!(category: 'issue_tracker', active: true, project_id: @project.id)
+ integration = subject.create!(category: 'issue_tracker', active: true, project_id: @project.id)
+
+ expect do
+ integration.update!(active: false)
+ end.not_to change { @project.reload.has_external_issue_tracker }
+ end
+
+ it 'does not change `has_external_issue_tracker` when integration is for a different project' do
+ different_project = projects.create!(namespace_id: @namespace.id)
+ integration = subject.create!(category: 'issue_tracker', active: false, project_id: different_project.id)
+
+ expect do
+ integration.update!(active: true)
+ end.not_to change { @project.reload.has_external_issue_tracker }
+ end
+ end
+
+ describe 'DELETE tracker trigger' do
+ it 'sets `has_external_issue_tracker` to false when `issue_tracker` is deleted' do
+ integration = subject.create!(category: 'issue_tracker', active: true, project_id: @project.id)
+
+ expect do
+ integration.delete
+ end.to change { @project.reload.has_external_issue_tracker }.to(false)
+ end
+
+ it 'sets `has_external_issue_tracker` to false when `issue_tracker` is deleted, if an inactive `issue_tracker` still exists' do
+ subject.create!(category: 'issue_tracker', active: false, project_id: @project.id)
+ integration = subject.create!(category: 'issue_tracker', active: true, project_id: @project.id)
+
+ expect do
+ integration.delete
+ end.to change { @project.reload.has_external_issue_tracker }.to(false)
+ end
+
+ it 'does not change `has_external_issue_tracker` when `issue_tracker` is deleted, if an active `issue_tracker` still exists' do
+ subject.create!(category: 'issue_tracker', active: true, project_id: @project.id)
+ integration = subject.create!(category: 'issue_tracker', active: true, project_id: @project.id)
+
+ expect do
+ integration.delete
+ end.not_to change { @project.reload.has_external_issue_tracker }
+ end
+
+ it 'does not change `has_external_issue_tracker` when integration is for a different project' do
+ different_project = projects.create!(namespace_id: @namespace.id)
+ integration = subject.create!(category: 'issue_tracker', active: true, project_id: different_project.id)
+
+ expect do
+ integration.delete
+ end.not_to change { @project.reload.has_external_issue_tracker }
+ end
+ end
+
+ describe 'INSERT wiki trigger' do
+ it 'sets `has_external_wiki` to true when active `ExternalWikiService` is inserted' do
+ expect do
+ subject.create!(type: 'ExternalWikiService', active: true, project_id: @project.id)
+ end.to change { @project.reload.has_external_wiki }.to(true)
+ end
+
+ it 'does not set `has_external_wiki` to true when integration is for a different project' do
+ different_project = projects.create!(namespace_id: @namespace.id)
+
+ expect do
+ subject.create!(type: 'ExternalWikiService', active: true, project_id: different_project.id)
+ end.not_to change { @project.reload.has_external_wiki }
+ end
+
+ it 'does not set `has_external_wiki` to true when inactive `ExternalWikiService` is inserted' do
+ expect do
+ subject.create!(type: 'ExternalWikiService', active: false, project_id: @project.id)
+ end.not_to change { @project.reload.has_external_wiki }
+ end
+
+ it 'does not set `has_external_wiki` to true when active other integration is inserted' do
+ expect do
+ subject.create!(type: 'MyService', active: true, project_id: @project.id)
+ end.not_to change { @project.reload.has_external_wiki }
+ end
+ end
+
+ describe 'UPDATE wiki trigger' do
+ it 'sets `has_external_wiki` to true when `ExternalWikiService` is made active' do
+ integration = subject.create!(type: 'ExternalWikiService', active: false, project_id: @project.id)
+
+ expect do
+ integration.update!(active: true)
+ end.to change { @project.reload.has_external_wiki }.to(true)
+ end
+
+ it 'sets `has_external_wiki` to false when `ExternalWikiService` is made inactive' do
+ integration = subject.create!(type: 'ExternalWikiService', active: true, project_id: @project.id)
+
+ expect do
+ integration.update!(active: false)
+ end.to change { @project.reload.has_external_wiki }.to(false)
+ end
+
+ it 'does not change `has_external_wiki` when integration is for a different project' do
+ different_project = projects.create!(namespace_id: @namespace.id)
+ integration = subject.create!(type: 'ExternalWikiService', active: false, project_id: different_project.id)
+
+ expect do
+ integration.update!(active: true)
+ end.not_to change { @project.reload.has_external_wiki }
+ end
+ end
+
+ describe 'DELETE wiki trigger' do
+ it 'sets `has_external_wiki` to false when `ExternalWikiService` is deleted' do
+ integration = subject.create!(type: 'ExternalWikiService', active: true, project_id: @project.id)
+
+ expect do
+ integration.delete
+ end.to change { @project.reload.has_external_wiki }.to(false)
+ end
+
+ it 'does not change `has_external_wiki` when integration is for a different project' do
+ different_project = projects.create!(namespace_id: @namespace.id)
+ integration = subject.create!(type: 'ExternalWikiService', active: true, project_id: different_project.id)
+
+ expect do
+ integration.delete
+ end.not_to change { @project.reload.has_external_wiki }
+ end
+ end
+ end
+
+ RSpec.shared_examples 'a table (or view) without triggers' do
+ specify do
+ number_of_triggers = ActiveRecord::Base.connection
+ .execute("SELECT count(*) FROM information_schema.triggers WHERE event_object_table = '#{subject.table_name}'")
+ .first['count']
+
+ expect(number_of_triggers).to eq(0)
+ end
+ end
+
+ describe '#up' do
+ before do
+ # LOCK TABLE statements must be in a transaction
+ ActiveRecord::Base.transaction { migrate! }
+ end
+
+ context 'the integrations table' do
+ subject { integrations }
+
+ it_behaves_like 'a table (or view) with triggers'
+ end
+
+ context 'the services table' do
+ subject { services }
+
+ it_behaves_like 'a table (or view) without triggers'
+ end
+ end
+
+ describe '#down' do
+ before do
+ # LOCK TABLE statements must be in a transaction
+ ActiveRecord::Base.transaction do
+ migration.up
+ migration.down
+ end
+ end
+
+ context 'the services table' do
+ subject { services }
+
+ it_behaves_like 'a table (or view) with triggers'
+ end
+
+ context 'the integrations table' do
+ subject { integrations }
+
+ it_behaves_like 'a table (or view) without triggers'
+ end
+ end
+end
diff --git a/spec/models/integration_spec.rb b/spec/models/integration_spec.rb
index 9ff32a7a1a0..b9bafbed468 100644
--- a/spec/models/integration_spec.rb
+++ b/spec/models/integration_spec.rb
@@ -139,61 +139,40 @@ RSpec.describe Integration do
end
end
- describe "Test Button" do
- let(:integration) { build(:service, project: project) }
-
- describe '#can_test?' do
- subject { integration.can_test? }
-
- context 'when project-level integration' do
- let(:project) { create(:project) }
-
- it { is_expected.to be true }
- end
-
- context 'when instance-level integration' do
- Integration.available_integration_types.each do |type|
- let(:integration) do
- described_class.send(:integration_type_to_model, type).new(instance: true)
- end
-
- it { is_expected.to be false }
- end
- end
+ describe '#can_test?' do
+ subject { integration.can_test? }
- context 'when group-level integration' do
- Integration.available_integration_types.each do |type|
- let(:integration) do
- described_class.send(:integration_type_to_model, type).new(group_id: group.id)
- end
+ context 'when integration is project-level' do
+ let(:integration) { build(:service, project: project) }
- it { is_expected.to be false }
- end
- end
+ it { is_expected.to be true }
end
- describe '#test' do
- let(:data) { 'test' }
+ context 'when integration is not project-level' do
+ let(:integration) { build(:service, project: nil) }
- context 'when repository is not empty' do
- let(:project) { build(:project, :repository) }
+ it { is_expected.to be false }
+ end
+ end
- it 'test runs execute' do
- expect(integration).to receive(:execute).with(data)
+ describe '#test' do
+ let(:integration) { build(:service, project: project) }
+ let(:data) { 'test' }
- integration.test(data)
- end
- end
+ it 'calls #execute' do
+ expect(integration).to receive(:execute).with(data)
- context 'when repository is empty' do
- let(:project) { build(:project) }
+ integration.test(data)
+ end
- it 'test runs execute' do
- expect(integration).to receive(:execute).with(data)
+ it 'returns a result' do
+ result = 'foo'
+ allow(integration).to receive(:execute).with(data).and_return(result)
- integration.test(data)
- end
- end
+ expect(integration.test(data)).to eq(
+ success: true,
+ result: result
+ )
end
end
diff --git a/spec/models/snippet_spec.rb b/spec/models/snippet_spec.rb
index 474a73a4df1..19d3895177f 100644
--- a/spec/models/snippet_spec.rb
+++ b/spec/models/snippet_spec.rb
@@ -828,14 +828,10 @@ RSpec.describe Snippet do
end
context 'when default branch in settings is different from "master"' do
- let(:default_branch) { 'main' }
+ let(:default_branch) { 'custom-branch' }
it 'changes the HEAD reference to the default branch' do
- expect(File.read(head_path).squish).to eq 'ref: refs/heads/master'
-
- subject
-
- expect(File.read(head_path).squish).to eq "ref: refs/heads/#{default_branch}"
+ expect { subject }.to change { File.read(head_path).squish }.to("ref: refs/heads/#{default_branch}")
end
end
end
diff --git a/spec/requests/api/branches_spec.rb b/spec/requests/api/branches_spec.rb
index 77bb2a5100f..54223291b25 100644
--- a/spec/requests/api/branches_spec.rb
+++ b/spec/requests/api/branches_spec.rb
@@ -727,10 +727,11 @@ RSpec.describe API::Branches do
end
it 'returns 400 if ref name is invalid' do
+ error_message = 'Failed to create branch \'new_design3\': invalid reference name \'foo\''
post api(route, user), params: { branch: 'new_design3', ref: 'foo' }
expect(response).to have_gitlab_http_status(:bad_request)
- expect(json_response['message']).to eq('Invalid reference name: foo')
+ expect(json_response['message']).to eq(error_message)
end
end
diff --git a/spec/requests/api/graphql/mutations/branches/create_spec.rb b/spec/requests/api/graphql/mutations/branches/create_spec.rb
index 2f19de2af54..6a098002963 100644
--- a/spec/requests/api/graphql/mutations/branches/create_spec.rb
+++ b/spec/requests/api/graphql/mutations/branches/create_spec.rb
@@ -35,11 +35,12 @@ RSpec.describe 'Creation of a new branch' do
end
context 'when ref is not correct' do
+ err_msg = 'Failed to create branch \'another_branch\': invalid reference name \'unknown\''
let(:new_branch) { 'another_branch' }
let(:ref) { 'unknown' }
it_behaves_like 'a mutation that returns errors in the response',
- errors: ['Invalid reference name: unknown']
+ errors: [err_msg]
end
end
end
diff --git a/spec/requests/api/graphql/mutations/snippets/create_spec.rb b/spec/requests/api/graphql/mutations/snippets/create_spec.rb
index d329b9aea6a..9a3cea3ca14 100644
--- a/spec/requests/api/graphql/mutations/snippets/create_spec.rb
+++ b/spec/requests/api/graphql/mutations/snippets/create_spec.rb
@@ -85,8 +85,8 @@ RSpec.describe 'Creating a Snippet' do
end.to change { Snippet.count }.by(1)
snippet = Snippet.last
- created_file_1 = snippet.repository.blob_at('HEAD', file_1[:filePath])
- created_file_2 = snippet.repository.blob_at('HEAD', file_2[:filePath])
+ created_file_1 = snippet.repository.blob_at(snippet.default_branch, file_1[:filePath])
+ created_file_2 = snippet.repository.blob_at(snippet.default_branch, file_2[:filePath])
expect(created_file_1.data).to match(file_1[:content])
expect(created_file_2.data).to match(file_2[:content])
diff --git a/spec/requests/api/project_snippets_spec.rb b/spec/requests/api/project_snippets_spec.rb
index 6a9cf6e16e2..8cd1f15a88d 100644
--- a/spec/requests/api/project_snippets_spec.rb
+++ b/spec/requests/api/project_snippets_spec.rb
@@ -138,7 +138,7 @@ RSpec.describe API::ProjectSnippets do
aggregate_failures do
expect(snippet.repository.exists?).to be_truthy
- blob = snippet.repository.blob_at('master', file_path)
+ blob = snippet.repository.blob_at(snippet.default_branch, file_path)
expect(blob.data).to eq file_content
end
diff --git a/spec/requests/api/snippets_spec.rb b/spec/requests/api/snippets_spec.rb
index 227c53f8fb9..f4d15d0525e 100644
--- a/spec/requests/api/snippets_spec.rb
+++ b/spec/requests/api/snippets_spec.rb
@@ -223,7 +223,7 @@ RSpec.describe API::Snippets, factory_default: :keep do
it 'commit the files to the repository' do
subject
- blob = snippet.repository.blob_at('master', file_path)
+ blob = snippet.repository.blob_at(snippet.default_branch, file_path)
expect(blob.data).to eq file_content
end
diff --git a/spec/services/branches/create_service_spec.rb b/spec/services/branches/create_service_spec.rb
index 5cf0d5af75f..1962aca35e1 100644
--- a/spec/services/branches/create_service_spec.rb
+++ b/spec/services/branches/create_service_spec.rb
@@ -38,10 +38,23 @@ RSpec.describe Branches::CreateService do
end
it 'returns an error with a reference name' do
+ err_msg = 'Failed to create branch \'new-feature\': invalid reference name \'unknown\''
result = service.execute('new-feature', 'unknown')
expect(result[:status]).to eq(:error)
- expect(result[:message]).to eq('Invalid reference name: unknown')
+ expect(result[:message]).to eq(err_msg)
+ end
+ end
+
+ context 'when an ambiguous branch name is provided' do
+ it 'returns an error that branch could not be created' do
+ err_msg = 'Failed to create branch \'feature\': 13:reference is ambiguous.'
+
+ service.execute('feature/widget', 'master')
+ result = service.execute('feature', 'master')
+
+ expect(result[:status]).to eq(:error)
+ expect(result[:message]).to eq(err_msg)
end
end
diff --git a/spec/services/commits/commit_patch_service_spec.rb b/spec/services/commits/commit_patch_service_spec.rb
index 55cbd0e5d66..edd0918e488 100644
--- a/spec/services/commits/commit_patch_service_spec.rb
+++ b/spec/services/commits/commit_patch_service_spec.rb
@@ -87,7 +87,7 @@ RSpec.describe Commits::CommitPatchService do
context 'when specifying a non existent start branch' do
let(:start_branch) { 'does-not-exist' }
- it_behaves_like 'an error response', 'Invalid reference name'
+ it_behaves_like 'an error response', 'Failed to create branch'
end
end
end