summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
Diffstat (limited to 'spec')
-rw-r--r--spec/controllers/admin/application_settings_controller_spec.rb7
-rw-r--r--spec/controllers/projects/issues_controller_spec.rb4
-rw-r--r--spec/controllers/projects/merge_requests_controller_spec.rb4
-rw-r--r--spec/fixtures/container_registry/config_blob_helm.json8
-rw-r--r--spec/fixtures/container_registry/tag_manifest_helm.json15
-rw-r--r--spec/frontend/fixtures/static/projects.json9
-rw-r--r--spec/frontend/lib/utils/suppress_ajax_errors_during_navigation_spec.js18
-rw-r--r--spec/lib/container_registry/tag_spec.rb23
-rw-r--r--spec/lib/gitlab/ci/config/entry/job_spec.rb46
-rw-r--r--spec/lib/gitlab/ci/config_spec.rb4
-rw-r--r--spec/lib/gitlab/ci/yaml_processor_spec.rb86
-rw-r--r--spec/lib/gitlab/diff/highlight_cache_spec.rb25
-rw-r--r--spec/lib/gitlab/diff/highlight_spec.rb4
-rw-r--r--spec/lib/gitlab/error_tracking_spec.rb (renamed from spec/lib/gitlab/sentry_spec.rb)14
-rw-r--r--spec/lib/gitlab/file_detector_spec.rb16
-rw-r--r--spec/lib/gitlab/gitaly_client_spec.rb2
-rw-r--r--spec/lib/gitlab/github_import/importer/pull_request_importer_spec.rb2
-rw-r--r--spec/lib/gitlab/gpg_spec.rb4
-rw-r--r--spec/lib/gitlab/import_export/avatar_restorer_spec.rb10
-rw-r--r--spec/lib/gitlab/import_export/avatar_saver_spec.rb4
-rw-r--r--spec/lib/gitlab/import_export/file_importer_spec.rb16
-rw-r--r--spec/lib/gitlab/import_export/fork_spec.rb4
-rw-r--r--spec/lib/gitlab/import_export/lfs_saver_spec.rb4
-rw-r--r--spec/lib/gitlab/import_export/merge_request_parser_spec.rb8
-rw-r--r--spec/lib/gitlab/import_export/reader_spec.rb19
-rw-r--r--spec/lib/gitlab/import_export/repo_restorer_spec.rb4
-rw-r--r--spec/lib/gitlab/import_export/repo_saver_spec.rb4
-rw-r--r--spec/lib/gitlab/import_export/saver_spec.rb4
-rw-r--r--spec/lib/gitlab/import_export/shared_spec.rb2
-rw-r--r--spec/lib/gitlab/import_export/uploads_manager_spec.rb4
-rw-r--r--spec/lib/gitlab/import_export/uploads_restorer_spec.rb4
-rw-r--r--spec/lib/gitlab/import_export/uploads_saver_spec.rb4
-rw-r--r--spec/lib/gitlab/import_export/wiki_repo_saver_spec.rb4
-rw-r--r--spec/lib/gitlab/mail_room/mail_room_spec.rb106
-rw-r--r--spec/lib/gitlab/metrics/instrumentation_spec.rb8
-rw-r--r--spec/lib/gitlab/query_limiting/middleware_spec.rb5
-rw-r--r--spec/lib/gitlab/sanitizers/svg_spec.rb4
-rw-r--r--spec/lib/gitlab/sherlock/transaction_spec.rb5
-rw-r--r--spec/lib/gitlab/sidekiq_middleware/correlation_injector_spec.rb4
-rw-r--r--spec/lib/gitlab/slash_commands/run_spec.rb35
-rw-r--r--spec/migrations/update_minimum_password_length_spec.rb30
-rw-r--r--spec/models/application_setting_spec.rb6
-rw-r--r--spec/models/ci/build_spec.rb16
-rw-r--r--spec/models/ci/pipeline_spec.rb1
-rw-r--r--spec/models/clusters/cluster_spec.rb2
-rw-r--r--spec/models/concerns/group_descendant_spec.rb4
-rw-r--r--spec/models/namespace_spec.rb2
-rw-r--r--spec/models/upload_spec.rb2
-rw-r--r--spec/models/user_spec.rb75
-rw-r--r--spec/requests/api/branches_spec.rb8
-rw-r--r--spec/requests/api/files_spec.rb9
-rw-r--r--spec/requests/api/graphql_spec.rb4
-rw-r--r--spec/requests/api/groups_spec.rb5
-rw-r--r--spec/requests/api/helpers_spec.rb4
-rw-r--r--spec/requests/api/jobs_spec.rb8
-rw-r--r--spec/requests/api/project_snippets_spec.rb8
-rw-r--r--spec/requests/api/snippets_spec.rb8
-rw-r--r--spec/requests/api/tags_spec.rb4
-rw-r--r--spec/requests/jwt_controller_spec.rb4
-rw-r--r--spec/requests/rack_attack_global_spec.rb4
-rw-r--r--spec/rubocop/cop/avoid_break_from_strong_memoize_spec.rb4
-rw-r--r--spec/rubocop/cop/avoid_return_from_blocks_spec.rb4
-rw-r--r--spec/serializers/analytics_summary_serializer_spec.rb5
-rw-r--r--spec/services/auth/container_registry_authentication_service_spec.rb4
-rw-r--r--spec/services/boards/issues/create_service_spec.rb4
-rw-r--r--spec/services/ci/archive_trace_service_spec.rb6
-rw-r--r--spec/services/ci/create_pipeline_service/rules_spec.rb59
-rw-r--r--spec/services/ci/create_pipeline_service_spec.rb4
-rw-r--r--spec/services/ci/pipeline_trigger_service_spec.rb8
-rw-r--r--spec/services/ci/play_manual_stage_service_spec.rb5
-rw-r--r--spec/services/ci/prepare_build_service_spec.rb2
-rw-r--r--spec/services/ci/process_pipeline_service_spec.rb4
-rw-r--r--spec/services/ci/register_job_service_spec.rb4
-rw-r--r--spec/services/clusters/applications/check_installation_progress_service_spec.rb7
-rw-r--r--spec/services/clusters/applications/check_uninstall_progress_service_spec.rb7
-rw-r--r--spec/services/clusters/gcp/verify_provision_status_service_spec.rb4
-rw-r--r--spec/services/clusters/kubernetes/create_or_update_namespace_service_spec.rb8
-rw-r--r--spec/services/discussions/resolve_service_spec.rb4
-rw-r--r--spec/services/event_create_service_spec.rb6
-rw-r--r--spec/services/groups/destroy_service_spec.rb4
-rw-r--r--spec/services/groups/transfer_service_spec.rb4
-rw-r--r--spec/services/issues/import_csv_service_spec.rb16
-rw-r--r--spec/services/issues/move_service_spec.rb4
-rw-r--r--spec/services/lfs/lock_file_service_spec.rb4
-rw-r--r--spec/services/lfs/locks_finder_service_spec.rb4
-rw-r--r--spec/services/merge_requests/create_pipeline_service_spec.rb62
-rw-r--r--spec/services/projects/fork_service_spec.rb29
-rw-r--r--spec/services/system_note_service_spec.rb4
-rw-r--r--spec/support/shared_examples/mail_room_shared_examples.rb35
-rw-r--r--spec/support/shared_examples/services/base_helm_service_shared_examples.rb2
-rw-r--r--spec/workers/ci/archive_traces_cron_worker_spec.rb2
-rw-r--r--spec/workers/run_pipeline_schedule_worker_spec.rb2
-rw-r--r--spec/workers/stuck_ci_jobs_worker_spec.rb2
93 files changed, 850 insertions, 230 deletions
diff --git a/spec/controllers/admin/application_settings_controller_spec.rb b/spec/controllers/admin/application_settings_controller_spec.rb
index bc14e9112a1..fa575ba2eae 100644
--- a/spec/controllers/admin/application_settings_controller_spec.rb
+++ b/spec/controllers/admin/application_settings_controller_spec.rb
@@ -95,6 +95,13 @@ describe Admin::ApplicationSettingsController do
expect(ApplicationSetting.current.default_project_creation).to eq(::Gitlab::Access::MAINTAINER_PROJECT_ACCESS)
end
+ it 'updates minimum_password_length setting' do
+ put :update, params: { application_setting: { minimum_password_length: 10 } }
+
+ expect(response).to redirect_to(admin_application_settings_path)
+ expect(ApplicationSetting.current.minimum_password_length).to eq(10)
+ end
+
context 'external policy classification settings' do
let(:settings) do
{
diff --git a/spec/controllers/projects/issues_controller_spec.rb b/spec/controllers/projects/issues_controller_spec.rb
index 68b73150b31..f64e928098d 100644
--- a/spec/controllers/projects/issues_controller_spec.rb
+++ b/spec/controllers/projects/issues_controller_spec.rb
@@ -1159,7 +1159,7 @@ describe Projects::IssuesController do
end
it "prevents deletion if destroy_confirm is not set" do
- expect(Gitlab::Sentry).to receive(:track_exception).and_call_original
+ expect(Gitlab::ErrorTracking).to receive(:track_exception).and_call_original
delete :destroy, params: { namespace_id: project.namespace, project_id: project, id: issue.iid }
@@ -1168,7 +1168,7 @@ describe Projects::IssuesController do
end
it "prevents deletion in JSON format if destroy_confirm is not set" do
- expect(Gitlab::Sentry).to receive(:track_exception).and_call_original
+ expect(Gitlab::ErrorTracking).to receive(:track_exception).and_call_original
delete :destroy, params: { namespace_id: project.namespace, project_id: project, id: issue.iid, format: 'json' }
diff --git a/spec/controllers/projects/merge_requests_controller_spec.rb b/spec/controllers/projects/merge_requests_controller_spec.rb
index 4b1304a9103..3b7d8adb8e5 100644
--- a/spec/controllers/projects/merge_requests_controller_spec.rb
+++ b/spec/controllers/projects/merge_requests_controller_spec.rb
@@ -620,7 +620,7 @@ describe Projects::MergeRequestsController do
end
it "prevents deletion if destroy_confirm is not set" do
- expect(Gitlab::Sentry).to receive(:track_exception).and_call_original
+ expect(Gitlab::ErrorTracking).to receive(:track_exception).and_call_original
delete :destroy, params: { namespace_id: project.namespace, project_id: project, id: merge_request.iid }
@@ -629,7 +629,7 @@ describe Projects::MergeRequestsController do
end
it "prevents deletion in JSON format if destroy_confirm is not set" do
- expect(Gitlab::Sentry).to receive(:track_exception).and_call_original
+ expect(Gitlab::ErrorTracking).to receive(:track_exception).and_call_original
delete :destroy, params: { namespace_id: project.namespace, project_id: project, id: merge_request.iid, format: 'json' }
diff --git a/spec/fixtures/container_registry/config_blob_helm.json b/spec/fixtures/container_registry/config_blob_helm.json
new file mode 100644
index 00000000000..c2fc68c2e8b
--- /dev/null
+++ b/spec/fixtures/container_registry/config_blob_helm.json
@@ -0,0 +1,8 @@
+{
+ "name": "mychart",
+ "version": "0.1.0",
+ "description": "A Helm chart for Kubernetes",
+ "apiVersion": "v2",
+ "appVersion": "1.16.0",
+ "type": "application"
+}
diff --git a/spec/fixtures/container_registry/tag_manifest_helm.json b/spec/fixtures/container_registry/tag_manifest_helm.json
new file mode 100644
index 00000000000..8097d9f3f7a
--- /dev/null
+++ b/spec/fixtures/container_registry/tag_manifest_helm.json
@@ -0,0 +1,15 @@
+{
+ "schemaVersion": 2,
+ "config": {
+ "mediaType": "application/vnd.cncf.helm.config.v1+json",
+ "digest": "sha256:65a07b841ece031e6d0ec5eb948eacb17aa6d7294cdeb01d5348e86242951487",
+ "size": 141
+ },
+ "layers": [
+ {
+ "mediaType": "application/tar+gzip",
+ "digest": "sha256:896935a875c8fe8f8b9b81e5862413de316f8da3d6d9a7e0f6f1e90f6204f551",
+ "size": 2801
+ }
+ ]
+}
diff --git a/spec/frontend/fixtures/static/projects.json b/spec/frontend/fixtures/static/projects.json
index f28d9899099..d92d3acdea0 100644
--- a/spec/frontend/fixtures/static/projects.json
+++ b/spec/frontend/fixtures/static/projects.json
@@ -99,15 +99,6 @@
"access_level": 50,
"notification_level": 3
}
- },
- "_links": {
- "self": "https://gitlab.com/api/v4/projects/278964",
- "issues": "https://gitlab.com/api/v4/projects/278964/issues",
- "merge_requests": "https://gitlab.com/api/v4/projects/278964/merge_requests",
- "repo_branches": "https://gitlab.com/api/v4/projects/278964/repository/branches",
- "labels": "https://gitlab.com/api/v4/projects/278964/labels",
- "events": "https://gitlab.com/api/v4/projects/278964/events",
- "members": "https://gitlab.com/api/v4/projects/278964/members"
}
}, {
"id": 7,
diff --git a/spec/frontend/lib/utils/suppress_ajax_errors_during_navigation_spec.js b/spec/frontend/lib/utils/suppress_ajax_errors_during_navigation_spec.js
index b9c1d65738d..da10e0e618d 100644
--- a/spec/frontend/lib/utils/suppress_ajax_errors_during_navigation_spec.js
+++ b/spec/frontend/lib/utils/suppress_ajax_errors_during_navigation_spec.js
@@ -6,24 +6,20 @@ describe('suppressAjaxErrorsDuringNavigation', () => {
const NAV_ERR_CODE = 'ECONNABORTED';
it.each`
- isFeatureFlagEnabled | isUserNavigating | code
- ${false} | ${false} | ${OTHER_ERR_CODE}
- ${false} | ${false} | ${NAV_ERR_CODE}
- ${false} | ${true} | ${OTHER_ERR_CODE}
- ${false} | ${true} | ${NAV_ERR_CODE}
- ${true} | ${false} | ${OTHER_ERR_CODE}
- ${true} | ${false} | ${NAV_ERR_CODE}
- ${true} | ${true} | ${OTHER_ERR_CODE}
- `('should return a rejected Promise', ({ isFeatureFlagEnabled, isUserNavigating, code }) => {
+ isUserNavigating | code
+ ${false} | ${OTHER_ERR_CODE}
+ ${false} | ${NAV_ERR_CODE}
+ ${true} | ${OTHER_ERR_CODE}
+ `('should return a rejected Promise', ({ isUserNavigating, code }) => {
const err = { code };
- const actual = suppressAjaxErrorsDuringNavigation(err, isUserNavigating, isFeatureFlagEnabled);
+ const actual = suppressAjaxErrorsDuringNavigation(err, isUserNavigating);
return expect(actual).rejects.toBe(err);
});
it('should return a Promise that never resolves', () => {
const err = { code: NAV_ERR_CODE };
- const actual = suppressAjaxErrorsDuringNavigation(err, true, true);
+ const actual = suppressAjaxErrorsDuringNavigation(err, true);
const thenCallback = jest.fn();
const catchCallback = jest.fn();
diff --git a/spec/lib/container_registry/tag_spec.rb b/spec/lib/container_registry/tag_spec.rb
index 3115dfe852f..9447112e4a8 100644
--- a/spec/lib/container_registry/tag_spec.rb
+++ b/spec/lib/container_registry/tag_spec.rb
@@ -97,6 +97,29 @@ describe ContainerRegistry::Tag do
end
end
+ context 'image is a helm chart' do
+ before do
+ stub_request(:get, 'http://registry.gitlab/v2/group/test/manifests/tag')
+ .with(headers: headers)
+ .to_return(
+ status: 200,
+ body: File.read(Rails.root + 'spec/fixtures/container_registry/tag_manifest_helm.json'),
+ headers: { 'Content-Type' => 'application/vnd.docker.distribution.manifest.v2+json' })
+
+ stub_request(:get, 'http://registry.gitlab/v2/group/test/blobs/sha256:65a07b841ece031e6d0ec5eb948eacb17aa6d7294cdeb01d5348e86242951487')
+ .with(headers: { 'Accept' => 'application/vnd.cncf.helm.config.v1+json' })
+ .to_return(
+ status: 200,
+ body: File.read(Rails.root + 'spec/fixtures/container_registry/config_blob_helm.json'))
+ end
+
+ context '#created_at' do
+ subject { tag.created_at }
+
+ it { is_expected.to be_nil }
+ end
+ end
+
context 'schema v2' do
before do
stub_request(:get, 'http://registry.gitlab/v2/group/test/manifests/tag')
diff --git a/spec/lib/gitlab/ci/config/entry/job_spec.rb b/spec/lib/gitlab/ci/config/entry/job_spec.rb
index 6e077aa00d7..cc1ee63ff04 100644
--- a/spec/lib/gitlab/ci/config/entry/job_spec.rb
+++ b/spec/lib/gitlab/ci/config/entry/job_spec.rb
@@ -461,7 +461,8 @@ describe Gitlab::Ci::Config::Entry::Job do
let(:unspecified) { double('unspecified', 'specified?' => false) }
let(:default) { double('default', '[]' => unspecified) }
- let(:deps) { double('deps', 'default' => default, '[]' => unspecified) }
+ let(:workflow) { double('workflow', 'has_rules?' => false) }
+ let(:deps) { double('deps', 'default' => default, '[]' => unspecified, 'workflow' => workflow) }
context 'when job config overrides default config' do
before do
@@ -492,6 +493,49 @@ describe Gitlab::Ci::Config::Entry::Job do
expect(entry[:cache].value).to eq(key: 'test', policy: 'pull-push')
end
end
+
+ context 'with workflow rules' do
+ using RSpec::Parameterized::TableSyntax
+
+ where(:name, :has_workflow_rules?, :only, :rules, :result) do
+ "uses default only" | false | nil | nil | { refs: %w[branches tags] }
+ "uses user only" | false | %w[branches] | nil | { refs: %w[branches] }
+ "does not define only" | false | nil | [] | nil
+ "does not define only" | true | nil | nil | nil
+ "uses user only" | true | %w[branches] | nil | { refs: %w[branches] }
+ "does not define only" | true | nil | [] | nil
+ end
+
+ with_them do
+ let(:config) { { script: 'ls', rules: rules, only: only }.compact }
+
+ it "#{name}" do
+ expect(workflow).to receive(:has_rules?) { has_workflow_rules? }
+
+ entry.compose!(deps)
+
+ expect(entry.only_value).to eq(result)
+ end
+ end
+ end
+
+ context 'when workflow rules is used' do
+ context 'when rules are used' do
+ let(:config) { { script: 'ls', cache: { key: 'test' }, rules: [] } }
+
+ it 'does not define only' do
+ expect(entry).not_to be_only_defined
+ end
+ end
+
+ context 'when rules are not used' do
+ let(:config) { { script: 'ls', cache: { key: 'test' }, only: [] } }
+
+ it 'does not define only' do
+ expect(entry).not_to be_only_defined
+ end
+ end
+ end
end
context 'when composed' do
diff --git a/spec/lib/gitlab/ci/config_spec.rb b/spec/lib/gitlab/ci/config_spec.rb
index b039c572677..63a36995284 100644
--- a/spec/lib/gitlab/ci/config_spec.rb
+++ b/spec/lib/gitlab/ci/config_spec.rb
@@ -157,7 +157,7 @@ describe Gitlab::Ci::Config do
describe '.new' do
it 'raises error' do
- expect(Gitlab::Sentry).to receive(:track_and_raise_for_dev_exception)
+ expect(Gitlab::ErrorTracking).to receive(:track_and_raise_for_dev_exception)
expect { config }.to raise_error(
described_class::ConfigError,
@@ -367,7 +367,7 @@ describe Gitlab::Ci::Config do
end
it 'raises error TimeoutError' do
- expect(Gitlab::Sentry).to receive(:track_and_raise_for_dev_exception)
+ expect(Gitlab::ErrorTracking).to receive(:track_and_raise_for_dev_exception)
expect { config }.to raise_error(
described_class::ConfigError,
diff --git a/spec/lib/gitlab/ci/yaml_processor_spec.rb b/spec/lib/gitlab/ci/yaml_processor_spec.rb
index 6083aac44f5..f61b28b06c8 100644
--- a/spec/lib/gitlab/ci/yaml_processor_spec.rb
+++ b/spec/lib/gitlab/ci/yaml_processor_spec.rb
@@ -28,6 +28,7 @@ module Gitlab
stage: "test",
stage_idx: 2,
name: "rspec",
+ only: { refs: %w[branches tags] },
options: {
before_script: ["pwd"],
script: ["rspec"]
@@ -120,6 +121,7 @@ module Gitlab
stage: "test",
stage_idx: 2,
name: "rspec",
+ only: { refs: %w[branches tags] },
options: { script: ["rspec"] },
interruptible: true,
allow_failure: false,
@@ -281,8 +283,7 @@ module Gitlab
when: "on_success",
yaml_variables: [],
options: { script: ["rspec"] },
- only: { refs: ["branches"] },
- except: {} }] },
+ only: { refs: ["branches"] } }] },
{ name: "deploy",
index: 3,
builds:
@@ -293,8 +294,7 @@ module Gitlab
when: "on_success",
yaml_variables: [],
options: { script: ["cap prod"] },
- only: { refs: ["tags"] },
- except: {} }] },
+ only: { refs: ["tags"] } }] },
{ name: ".post",
index: 4,
builds: [] }]
@@ -631,6 +631,7 @@ module Gitlab
stage: "test",
stage_idx: 2,
name: "rspec",
+ only: { refs: %w[branches tags] },
options: {
before_script: ["pwd"],
script: ["rspec"],
@@ -662,6 +663,7 @@ module Gitlab
stage: "test",
stage_idx: 2,
name: "rspec",
+ only: { refs: %w[branches tags] },
options: {
before_script: ["pwd"],
script: ["rspec"],
@@ -691,6 +693,7 @@ module Gitlab
stage: "test",
stage_idx: 2,
name: "rspec",
+ only: { refs: %w[branches tags] },
options: {
before_script: ["pwd"],
script: ["rspec"],
@@ -716,6 +719,7 @@ module Gitlab
stage: "test",
stage_idx: 2,
name: "rspec",
+ only: { refs: %w[branches tags] },
options: {
before_script: ["pwd"],
script: ["rspec"],
@@ -1230,6 +1234,7 @@ module Gitlab
stage: "test",
stage_idx: 2,
name: "rspec",
+ only: { refs: %w[branches tags] },
options: {
before_script: ["pwd"],
script: ["rspec"],
@@ -1527,6 +1532,7 @@ module Gitlab
stage: "build",
stage_idx: 1,
name: "build1",
+ only: { refs: %w[branches tags] },
options: {
script: ["test"]
},
@@ -1538,6 +1544,7 @@ module Gitlab
stage: "test",
stage_idx: 2,
name: "test1",
+ only: { refs: %w[branches tags] },
options: { script: ["test"] },
needs_attributes: [
{ name: "build1", artifacts: true },
@@ -1565,6 +1572,7 @@ module Gitlab
stage: "build",
stage_idx: 1,
name: "build1",
+ only: { refs: %w[branches tags] },
options: {
script: ["test"]
},
@@ -1576,6 +1584,7 @@ module Gitlab
stage: "test",
stage_idx: 2,
name: "test1",
+ only: { refs: %w[branches tags] },
options: { script: ["test"] },
needs_attributes: [
{ name: "parallel 1/2", artifacts: false },
@@ -1599,6 +1608,7 @@ module Gitlab
stage: "test",
stage_idx: 2,
name: "test1",
+ only: { refs: %w[branches tags] },
options: { script: ["test"] },
needs_attributes: [
{ name: "parallel 1/2", artifacts: true },
@@ -1626,6 +1636,7 @@ module Gitlab
stage: "test",
stage_idx: 2,
name: "test1",
+ only: { refs: %w[branches tags] },
options: { script: ["test"] },
needs_attributes: [
{ name: "build1", artifacts: true },
@@ -1733,6 +1744,7 @@ module Gitlab
stage: "test",
stage_idx: 2,
name: "normal_job",
+ only: { refs: %w[branches tags] },
options: {
script: ["test"]
},
@@ -1778,6 +1790,7 @@ module Gitlab
stage: "build",
stage_idx: 1,
name: "job1",
+ only: { refs: %w[branches tags] },
options: {
script: ["execute-script-for-job"]
},
@@ -1789,6 +1802,7 @@ module Gitlab
stage: "build",
stage_idx: 1,
name: "job2",
+ only: { refs: %w[branches tags] },
options: {
script: ["execute-script-for-job"]
},
@@ -2235,6 +2249,70 @@ module Gitlab
it { is_expected.to be_nil }
end
end
+
+ describe '.new_with_validation_errors' do
+ subject { Gitlab::Ci::YamlProcessor.new_with_validation_errors(content) }
+
+ context 'when the YAML could not be parsed' do
+ let(:content) { YAML.dump('invalid: yaml: test') }
+
+ it 'returns errors and empty configuration' do
+ expect(subject.valid?).to eq(false)
+ expect(subject.errors).to eq(['Invalid configuration format'])
+ expect(subject.content).to be_blank
+ end
+ end
+
+ context 'when the tags parameter is invalid' do
+ let(:content) { YAML.dump({ rspec: { script: 'test', tags: 'mysql' } }) }
+
+ it 'returns errors and empty configuration' do
+ expect(subject.valid?).to eq(false)
+ expect(subject.errors).to eq(['jobs:rspec:tags config should be an array of strings'])
+ expect(subject.content).to be_blank
+ end
+ end
+
+ context 'when the configuration contains multiple keyword-syntax errors' do
+ let(:content) { YAML.dump({ rspec: { script: 'test', bad_tags: 'mysql', rules: { wrong: 'format' } } }) }
+
+ it 'returns errors and empty configuration' do
+ expect(subject.valid?).to eq(false)
+ expect(subject.errors).to eq(['jobs:rspec config contains unknown keys: bad_tags', 'jobs:rspec rules should be an array of hashes'])
+ expect(subject.content).to be_blank
+ end
+ end
+
+ context 'when YAML content is empty' do
+ let(:content) { '' }
+
+ it 'returns errors and empty configuration' do
+ expect(subject.valid?).to eq(false)
+ expect(subject.errors).to eq(['Please provide content of .gitlab-ci.yml'])
+ expect(subject.content).to be_blank
+ end
+ end
+
+ context 'when the YAML contains an unknown alias' do
+ let(:content) { 'steps: *bad_alias' }
+
+ it 'returns errors and empty configuration' do
+ expect(subject.valid?).to eq(false)
+ expect(subject.errors).to eq(['Unknown alias: bad_alias'])
+ expect(subject.content).to be_blank
+ end
+ end
+
+ context 'when the YAML is valid' do
+ let(:content) { File.read(Rails.root.join('spec/support/gitlab_stubs/gitlab_ci.yml')) }
+
+ it 'returns errors and empty configuration' do
+ expect(subject.valid?).to eq(true)
+ expect(subject.errors).to be_empty
+ expect(subject.content).to be_present
+ end
+ end
+ end
end
end
end
diff --git a/spec/lib/gitlab/diff/highlight_cache_spec.rb b/spec/lib/gitlab/diff/highlight_cache_spec.rb
index 7daf086843b..c73ec84e332 100644
--- a/spec/lib/gitlab/diff/highlight_cache_spec.rb
+++ b/spec/lib/gitlab/diff/highlight_cache_spec.rb
@@ -79,10 +79,8 @@ describe Gitlab::Diff::HighlightCache, :clean_gitlab_redis_cache do
end
end
- describe '#write_if_empty' do
+ shared_examples 'caches missing entries' do
it 'filters the key/value list of entries to be caches for each invocation' do
- paths = merge_request.diffs.diff_files.select(&:text?).map(&:file_path)
-
expect(cache).to receive(:write_to_redis_hash)
.with(hash_including(*paths))
.once
@@ -96,6 +94,12 @@ describe Gitlab::Diff::HighlightCache, :clean_gitlab_redis_cache do
cache.write_if_empty
end
+ end
+
+ describe '#write_if_empty' do
+ it_behaves_like 'caches missing entries' do
+ let(:paths) { merge_request.diffs.raw_diff_files.select(&:text?).map(&:file_path) }
+ end
context 'different diff_collections for the same diffable' do
before do
@@ -109,6 +113,21 @@ describe Gitlab::Diff::HighlightCache, :clean_gitlab_redis_cache do
.to change { Gitlab::Redis::Cache.with { |r| r.hgetall(cache_key) } }
end
end
+
+ context 'when cache initialized with MergeRequestDiffBatch' do
+ let(:merge_request_diff_batch) do
+ Gitlab::Diff::FileCollection::MergeRequestDiffBatch.new(
+ merge_request.merge_request_diff,
+ 1,
+ 10,
+ diff_options: nil)
+ end
+
+ it_behaves_like 'caches missing entries' do
+ let(:cache) { described_class.new(merge_request_diff_batch) }
+ let(:paths) { merge_request_diff_batch.raw_diff_files.select(&:text?).map(&:file_path) }
+ end
+ end
end
describe '#write_to_redis_hash' do
diff --git a/spec/lib/gitlab/diff/highlight_spec.rb b/spec/lib/gitlab/diff/highlight_spec.rb
index 1a14f6d4f67..ff4ec75358e 100644
--- a/spec/lib/gitlab/diff/highlight_spec.rb
+++ b/spec/lib/gitlab/diff/highlight_spec.rb
@@ -105,7 +105,7 @@ describe Gitlab::Diff::Highlight do
end
it 'keeps the original rich line' do
- allow(Gitlab::Sentry).to receive(:track_and_raise_for_dev_exception)
+ allow(Gitlab::ErrorTracking).to receive(:track_and_raise_for_dev_exception)
code = %q{+ raise RuntimeError, "System commands must be given as an array of strings"}
@@ -114,7 +114,7 @@ describe Gitlab::Diff::Highlight do
end
it 'reports to Sentry if configured' do
- expect(Gitlab::Sentry).to receive(:track_and_raise_for_dev_exception).and_call_original
+ expect(Gitlab::ErrorTracking).to receive(:track_and_raise_for_dev_exception).and_call_original
expect { subject }. to raise_exception(RangeError)
end
diff --git a/spec/lib/gitlab/sentry_spec.rb b/spec/lib/gitlab/error_tracking_spec.rb
index 6d05241e72d..08718bc92a1 100644
--- a/spec/lib/gitlab/sentry_spec.rb
+++ b/spec/lib/gitlab/error_tracking_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe Gitlab::Sentry do
+describe Gitlab::ErrorTracking do
let(:exception) { RuntimeError.new('boom') }
let(:issue_url) { 'http://gitlab.com/gitlab-org/gitlab-foss/issues/1' }
@@ -76,8 +76,8 @@ describe Gitlab::Sentry do
)
end
- it 'calls Gitlab::Sentry::Logger.error with formatted payload' do
- expect(Gitlab::Sentry::Logger).to receive(:error)
+ it 'calls Gitlab::ErrorTracking::Logger.error with formatted payload' do
+ expect(Gitlab::ErrorTracking::Logger).to receive(:error)
.with(a_hash_including(*expected_payload_includes))
described_class.track_and_raise_for_dev_exception(
@@ -97,8 +97,8 @@ describe Gitlab::Sentry do
.to raise_error(RuntimeError)
end
- it 'calls Gitlab::Sentry::Logger.error with formatted payload' do
- expect(Gitlab::Sentry::Logger).to receive(:error)
+ it 'calls Gitlab::ErrorTracking::Logger.error with formatted payload' do
+ expect(Gitlab::ErrorTracking::Logger).to receive(:error)
.with(a_hash_including(*expected_payload_includes))
expect do
@@ -134,8 +134,8 @@ describe Gitlab::Sentry do
)
end
- it 'calls Gitlab::Sentry::Logger.error with formatted payload' do
- expect(Gitlab::Sentry::Logger).to receive(:error)
+ it 'calls Gitlab::ErrorTracking::Logger.error with formatted payload' do
+ expect(Gitlab::ErrorTracking::Logger).to receive(:error)
.with(a_hash_including(*expected_payload_includes))
described_class.track_exception(
diff --git a/spec/lib/gitlab/file_detector_spec.rb b/spec/lib/gitlab/file_detector_spec.rb
index f3a9f706e86..23f7deba7f7 100644
--- a/spec/lib/gitlab/file_detector_spec.rb
+++ b/spec/lib/gitlab/file_detector_spec.rb
@@ -82,5 +82,21 @@ describe Gitlab::FileDetector do
it 'returns nil for an unknown file' do
expect(described_class.type_of('foo.txt')).to be_nil
end
+
+ it 'returns the type of an OpenAPI spec if file name is correct' do
+ openapi_types = [
+ 'openapi.yml', 'openapi.yaml', 'openapi.json',
+ 'swagger.yml', 'swagger.yaml', 'swagger.json',
+ 'gitlab_swagger.yml', 'openapi_gitlab.yml',
+ 'OpenAPI.YML', 'openapi.Yaml', 'openapi.JSON',
+ 'openapi.gitlab.yml', 'gitlab.openapi.yml'
+ ]
+
+ openapi_types.each do |type_name|
+ expect(described_class.type_of(type_name)).to eq(:openapi)
+ end
+
+ expect(described_class.type_of('openapiyml')).to be_nil
+ end
end
end
diff --git a/spec/lib/gitlab/gitaly_client_spec.rb b/spec/lib/gitlab/gitaly_client_spec.rb
index b7ad6cebf81..0d9719a5663 100644
--- a/spec/lib/gitlab/gitaly_client_spec.rb
+++ b/spec/lib/gitlab/gitaly_client_spec.rb
@@ -86,7 +86,7 @@ describe Gitlab::GitalyClient do
describe '.stub_certs' do
it 'skips certificates if OpenSSLError is raised and report it' do
- expect(Gitlab::Sentry)
+ expect(Gitlab::ErrorTracking)
.to receive(:track_and_raise_for_dev_exception)
.with(
a_kind_of(OpenSSL::X509::CertificateError),
diff --git a/spec/lib/gitlab/github_import/importer/pull_request_importer_spec.rb b/spec/lib/gitlab/github_import/importer/pull_request_importer_spec.rb
index 7065b3f9bcb..877b4d4bbaf 100644
--- a/spec/lib/gitlab/github_import/importer/pull_request_importer_spec.rb
+++ b/spec/lib/gitlab/github_import/importer/pull_request_importer_spec.rb
@@ -301,7 +301,7 @@ describe Gitlab::GithubImport::Importer::PullRequestImporter, :clean_gitlab_redi
it 'ignores Git command errors when creating a branch' do
expect(project.repository).to receive(:add_branch).and_raise(Gitlab::Git::CommandError)
- expect(Gitlab::Sentry).to receive(:track_exception).and_call_original
+ expect(Gitlab::ErrorTracking).to receive(:track_exception).and_call_original
mr = insert_git_data
diff --git a/spec/lib/gitlab/gpg_spec.rb b/spec/lib/gitlab/gpg_spec.rb
index c073d86b4a5..27a3010eeed 100644
--- a/spec/lib/gitlab/gpg_spec.rb
+++ b/spec/lib/gitlab/gpg_spec.rb
@@ -182,14 +182,14 @@ describe Gitlab::Gpg do
expected_tmp_dir = nil
expect(described_class).to receive(:cleanup_tmp_dir).and_raise(expected_exception)
- allow(Gitlab::Sentry).to receive(:track_and_raise_for_dev_exception)
+ allow(Gitlab::ErrorTracking).to receive(:track_and_raise_for_dev_exception)
described_class.using_tmp_keychain do
expected_tmp_dir = described_class.current_home_dir
FileUtils.touch(File.join(expected_tmp_dir, 'dummy.file'))
end
- expect(Gitlab::Sentry).to have_received(:track_and_raise_for_dev_exception).with(
+ expect(Gitlab::ErrorTracking).to have_received(:track_and_raise_for_dev_exception).with(
expected_exception,
issue_url: 'https://gitlab.com/gitlab-org/gitlab/issues/20918',
tmp_dir: expected_tmp_dir, contents: ['dummy.file']
diff --git a/spec/lib/gitlab/import_export/avatar_restorer_spec.rb b/spec/lib/gitlab/import_export/avatar_restorer_spec.rb
index 77f551eeca1..662e1a5eaab 100644
--- a/spec/lib/gitlab/import_export/avatar_restorer_spec.rb
+++ b/spec/lib/gitlab/import_export/avatar_restorer_spec.rb
@@ -14,8 +14,9 @@ describe Gitlab::ImportExport::AvatarRestorer do
context 'with avatar' do
before do
- allow_any_instance_of(described_class).to receive(:avatar_export_file)
- .and_return(uploaded_image_temp_path)
+ allow_next_instance_of(described_class) do |instance|
+ allow(instance).to receive(:avatar_export_file).and_return(uploaded_image_temp_path)
+ end
end
it 'restores a project avatar' do
@@ -33,8 +34,9 @@ describe Gitlab::ImportExport::AvatarRestorer do
Dir.mktmpdir do |tmpdir|
FileUtils.mkdir_p("#{tmpdir}/a/b")
- allow_any_instance_of(described_class).to receive(:avatar_export_path)
- .and_return("#{tmpdir}/a")
+ allow_next_instance_of(described_class) do |instance|
+ allow(instance).to receive(:avatar_export_path).and_return("#{tmpdir}/a")
+ end
expect(described_class.new(project: project, shared: shared).restore).to be true
end
diff --git a/spec/lib/gitlab/import_export/avatar_saver_spec.rb b/spec/lib/gitlab/import_export/avatar_saver_spec.rb
index a84406f9784..d2349e47c0a 100644
--- a/spec/lib/gitlab/import_export/avatar_saver_spec.rb
+++ b/spec/lib/gitlab/import_export/avatar_saver_spec.rb
@@ -10,7 +10,9 @@ describe Gitlab::ImportExport::AvatarSaver do
before do
FileUtils.mkdir_p("#{shared.export_path}/avatar/")
- allow_any_instance_of(Gitlab::ImportExport::Shared).to receive(:export_path).and_return(export_path)
+ allow_next_instance_of(Gitlab::ImportExport::Shared) do |instance|
+ allow(instance).to receive(:export_path).and_return(export_path)
+ end
end
after do
diff --git a/spec/lib/gitlab/import_export/file_importer_spec.rb b/spec/lib/gitlab/import_export/file_importer_spec.rb
index 737bedab844..7c54c5f2da1 100644
--- a/spec/lib/gitlab/import_export/file_importer_spec.rb
+++ b/spec/lib/gitlab/import_export/file_importer_spec.rb
@@ -18,9 +18,15 @@ describe Gitlab::ImportExport::FileImporter do
stub_const('Gitlab::ImportExport::FileImporter::MAX_RETRIES', 0)
stub_uploads_object_storage(FileUploader)
- allow_any_instance_of(Gitlab::ImportExport).to receive(:storage_path).and_return(storage_path)
- allow_any_instance_of(Gitlab::ImportExport::CommandLineUtil).to receive(:untar_zxf).and_return(true)
- allow_any_instance_of(Gitlab::ImportExport::Shared).to receive(:relative_archive_path).and_return('test')
+ allow_next_instance_of(Gitlab::ImportExport) do |instance|
+ allow(instance).to receive(:storage_path).and_return(storage_path)
+ end
+ allow_next_instance_of(Gitlab::ImportExport::CommandLineUtil) do |instance|
+ allow(instance).to receive(:untar_zxf).and_return(true)
+ end
+ allow_next_instance_of(Gitlab::ImportExport::Shared) do |instance|
+ allow(instance).to receive(:relative_archive_path).and_return('test')
+ end
allow(SecureRandom).to receive(:hex).and_return('abcd')
setup_files
end
@@ -69,7 +75,9 @@ describe Gitlab::ImportExport::FileImporter do
context 'error' do
before do
- allow_any_instance_of(described_class).to receive(:wait_for_archived_file).and_raise(StandardError)
+ allow_next_instance_of(described_class) do |instance|
+ allow(instance).to receive(:wait_for_archived_file).and_raise(StandardError)
+ end
described_class.import(importable: build(:project), archive_file: '', shared: shared)
end
diff --git a/spec/lib/gitlab/import_export/fork_spec.rb b/spec/lib/gitlab/import_export/fork_spec.rb
index 10197330527..09e4f62c686 100644
--- a/spec/lib/gitlab/import_export/fork_spec.rb
+++ b/spec/lib/gitlab/import_export/fork_spec.rb
@@ -32,7 +32,9 @@ describe 'forked project import' do
end
before do
- allow_any_instance_of(Gitlab::ImportExport).to receive(:storage_path).and_return(export_path)
+ allow_next_instance_of(Gitlab::ImportExport) do |instance|
+ allow(instance).to receive(:storage_path).and_return(export_path)
+ end
saver.save
repo_saver.save
diff --git a/spec/lib/gitlab/import_export/lfs_saver_spec.rb b/spec/lib/gitlab/import_export/lfs_saver_spec.rb
index 89493c3bf27..a8ff7867410 100644
--- a/spec/lib/gitlab/import_export/lfs_saver_spec.rb
+++ b/spec/lib/gitlab/import_export/lfs_saver_spec.rb
@@ -10,7 +10,9 @@ describe Gitlab::ImportExport::LfsSaver do
subject(:saver) { described_class.new(project: project, shared: shared) }
before do
- allow_any_instance_of(Gitlab::ImportExport).to receive(:storage_path).and_return(export_path)
+ allow_next_instance_of(Gitlab::ImportExport) do |instance|
+ allow(instance).to receive(:storage_path).and_return(export_path)
+ end
FileUtils.mkdir_p(shared.export_path)
end
diff --git a/spec/lib/gitlab/import_export/merge_request_parser_spec.rb b/spec/lib/gitlab/import_export/merge_request_parser_spec.rb
index e7f039d7a6f..c437efede4c 100644
--- a/spec/lib/gitlab/import_export/merge_request_parser_spec.rb
+++ b/spec/lib/gitlab/import_export/merge_request_parser_spec.rb
@@ -35,9 +35,11 @@ describe Gitlab::ImportExport::MergeRequestParser do
end
it 'parses a MR that has no source branch' do
- allow_any_instance_of(described_class).to receive(:branch_exists?).and_call_original
- allow_any_instance_of(described_class).to receive(:branch_exists?).with(merge_request.source_branch).and_return(false)
- allow_any_instance_of(described_class).to receive(:fork_merge_request?).and_return(true)
+ allow_next_instance_of(described_class) do |instance|
+ allow(instance).to receive(:branch_exists?).and_call_original
+ allow(instance).to receive(:branch_exists?).with(merge_request.source_branch).and_return(false)
+ allow(instance).to receive(:fork_merge_request?).and_return(true)
+ end
allow(Gitlab::GitalyClient).to receive(:migrate).and_call_original
allow(Gitlab::GitalyClient).to receive(:migrate).with(:fetch_ref).and_return([nil, 0])
diff --git a/spec/lib/gitlab/import_export/reader_spec.rb b/spec/lib/gitlab/import_export/reader_spec.rb
index 802c00bed74..e37ad281eb5 100644
--- a/spec/lib/gitlab/import_export/reader_spec.rb
+++ b/spec/lib/gitlab/import_export/reader_spec.rb
@@ -9,19 +9,18 @@ describe Gitlab::ImportExport::Reader do
subject { described_class.new(shared: shared).project_tree }
it 'delegates to AttributesFinder#find_root' do
- expect_any_instance_of(Gitlab::ImportExport::AttributesFinder)
- .to receive(:find_root)
- .with(:project)
+ expect_next_instance_of(Gitlab::ImportExport::AttributesFinder) do |instance|
+ expect(instance).to receive(:find_root).with(:project)
+ end
subject
end
context 'when exception raised' do
before do
- expect_any_instance_of(Gitlab::ImportExport::AttributesFinder)
- .to receive(:find_root)
- .with(:project)
- .and_raise(StandardError)
+ expect_next_instance_of(Gitlab::ImportExport::AttributesFinder) do |instance|
+ expect(instance).to receive(:find_root).with(:project).and_raise(StandardError)
+ end
end
it { is_expected.to be false }
@@ -38,9 +37,9 @@ describe Gitlab::ImportExport::Reader do
subject { described_class.new(shared: shared).group_members_tree }
it 'delegates to AttributesFinder#find_root' do
- expect_any_instance_of(Gitlab::ImportExport::AttributesFinder)
- .to receive(:find_root)
- .with(:group_members)
+ expect_next_instance_of(Gitlab::ImportExport::AttributesFinder) do |instance|
+ expect(instance).to receive(:find_root).with(:group_members)
+ end
subject
end
diff --git a/spec/lib/gitlab/import_export/repo_restorer_spec.rb b/spec/lib/gitlab/import_export/repo_restorer_spec.rb
index 4f8075d9704..a61d966bdfa 100644
--- a/spec/lib/gitlab/import_export/repo_restorer_spec.rb
+++ b/spec/lib/gitlab/import_export/repo_restorer_spec.rb
@@ -20,7 +20,9 @@ describe Gitlab::ImportExport::RepoRestorer do
end
before do
- allow_any_instance_of(Gitlab::ImportExport).to receive(:storage_path).and_return(export_path)
+ allow_next_instance_of(Gitlab::ImportExport) do |instance|
+ allow(instance).to receive(:storage_path).and_return(export_path)
+ end
bundler.save
end
diff --git a/spec/lib/gitlab/import_export/repo_saver_spec.rb b/spec/lib/gitlab/import_export/repo_saver_spec.rb
index 54dbefdb535..fc1f782bfdd 100644
--- a/spec/lib/gitlab/import_export/repo_saver_spec.rb
+++ b/spec/lib/gitlab/import_export/repo_saver_spec.rb
@@ -12,7 +12,9 @@ describe Gitlab::ImportExport::RepoSaver do
before do
project.add_maintainer(user)
- allow_any_instance_of(Gitlab::ImportExport).to receive(:storage_path).and_return(export_path)
+ allow_next_instance_of(Gitlab::ImportExport) do |instance|
+ allow(instance).to receive(:storage_path).and_return(export_path)
+ end
end
after do
diff --git a/spec/lib/gitlab/import_export/saver_spec.rb b/spec/lib/gitlab/import_export/saver_spec.rb
index 450ae2a2083..a59cf7a1260 100644
--- a/spec/lib/gitlab/import_export/saver_spec.rb
+++ b/spec/lib/gitlab/import_export/saver_spec.rb
@@ -11,7 +11,9 @@ describe Gitlab::ImportExport::Saver do
subject { described_class.new(exportable: project, shared: shared) }
before do
- allow_any_instance_of(Gitlab::ImportExport).to receive(:storage_path).and_return(export_path)
+ allow_next_instance_of(Gitlab::ImportExport) do |instance|
+ allow(instance).to receive(:storage_path).and_return(export_path)
+ end
FileUtils.mkdir_p(shared.export_path)
FileUtils.touch("#{shared.export_path}/tmp.bundle")
diff --git a/spec/lib/gitlab/import_export/shared_spec.rb b/spec/lib/gitlab/import_export/shared_spec.rb
index 9a2339e576a..8c16243576d 100644
--- a/spec/lib/gitlab/import_export/shared_spec.rb
+++ b/spec/lib/gitlab/import_export/shared_spec.rb
@@ -49,7 +49,7 @@ describe Gitlab::ImportExport::Shared do
it 'updates the import JID' do
import_state = create(:import_state, project: project, jid: 'jid-test')
- expect(Gitlab::Sentry)
+ expect(Gitlab::ErrorTracking)
.to receive(:track_exception)
.with(error, hash_including(import_jid: import_state.jid))
diff --git a/spec/lib/gitlab/import_export/uploads_manager_spec.rb b/spec/lib/gitlab/import_export/uploads_manager_spec.rb
index 04a94954187..e6d6ba840be 100644
--- a/spec/lib/gitlab/import_export/uploads_manager_spec.rb
+++ b/spec/lib/gitlab/import_export/uploads_manager_spec.rb
@@ -12,7 +12,9 @@ describe Gitlab::ImportExport::UploadsManager do
subject(:manager) { described_class.new(project: project, shared: shared) }
before do
- allow_any_instance_of(Gitlab::ImportExport).to receive(:storage_path).and_return(export_path)
+ allow_next_instance_of(Gitlab::ImportExport) do |instance|
+ allow(instance).to receive(:storage_path).and_return(export_path)
+ end
FileUtils.mkdir_p(shared.export_path)
end
diff --git a/spec/lib/gitlab/import_export/uploads_restorer_spec.rb b/spec/lib/gitlab/import_export/uploads_restorer_spec.rb
index 5c456d6f3b1..077ece87b31 100644
--- a/spec/lib/gitlab/import_export/uploads_restorer_spec.rb
+++ b/spec/lib/gitlab/import_export/uploads_restorer_spec.rb
@@ -8,7 +8,9 @@ describe Gitlab::ImportExport::UploadsRestorer do
let(:shared) { project.import_export_shared }
before do
- allow_any_instance_of(Gitlab::ImportExport).to receive(:storage_path).and_return(export_path)
+ allow_next_instance_of(Gitlab::ImportExport) do |instance|
+ allow(instance).to receive(:storage_path).and_return(export_path)
+ end
FileUtils.mkdir_p(File.join(shared.export_path, 'uploads/random'))
FileUtils.touch(File.join(shared.export_path, 'uploads/random', 'dummy.txt'))
end
diff --git a/spec/lib/gitlab/import_export/uploads_saver_spec.rb b/spec/lib/gitlab/import_export/uploads_saver_spec.rb
index 98b00cceada..8a36caef316 100644
--- a/spec/lib/gitlab/import_export/uploads_saver_spec.rb
+++ b/spec/lib/gitlab/import_export/uploads_saver_spec.rb
@@ -9,7 +9,9 @@ describe Gitlab::ImportExport::UploadsSaver do
let(:shared) { project.import_export_shared }
before do
- allow_any_instance_of(Gitlab::ImportExport).to receive(:storage_path).and_return(export_path)
+ allow_next_instance_of(Gitlab::ImportExport) do |instance|
+ allow(instance).to receive(:storage_path).and_return(export_path)
+ end
end
after do
diff --git a/spec/lib/gitlab/import_export/wiki_repo_saver_spec.rb b/spec/lib/gitlab/import_export/wiki_repo_saver_spec.rb
index 9c6bbff48b7..59a59223d8d 100644
--- a/spec/lib/gitlab/import_export/wiki_repo_saver_spec.rb
+++ b/spec/lib/gitlab/import_export/wiki_repo_saver_spec.rb
@@ -13,7 +13,9 @@ describe Gitlab::ImportExport::WikiRepoSaver do
before do
project.add_maintainer(user)
- allow_any_instance_of(Gitlab::ImportExport).to receive(:storage_path).and_return(export_path)
+ allow_next_instance_of(Gitlab::ImportExport) do |instance|
+ allow(instance).to receive(:storage_path).and_return(export_path)
+ end
project_wiki.wiki
project_wiki.create_page("index", "test content")
end
diff --git a/spec/lib/gitlab/mail_room/mail_room_spec.rb b/spec/lib/gitlab/mail_room/mail_room_spec.rb
new file mode 100644
index 00000000000..cb3e214d38b
--- /dev/null
+++ b/spec/lib/gitlab/mail_room/mail_room_spec.rb
@@ -0,0 +1,106 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+describe Gitlab::MailRoom do
+ let(:default_port) { 143 }
+ let(:default_config) do
+ {
+ enabled: false,
+ port: default_port,
+ ssl: false,
+ start_tls: false,
+ mailbox: 'inbox',
+ idle_timeout: 60,
+ log_path: Rails.root.join('log', 'mail_room_json.log').to_s
+ }
+ end
+
+ before do
+ described_class.reset_config!
+ allow(File).to receive(:exist?).and_return true
+ end
+
+ describe '#config' do
+ context 'if the yml file cannot be found' do
+ before do
+ allow(File).to receive(:exist?).and_return false
+ end
+
+ it 'returns an empty hash' do
+ expect(described_class.config).to be_empty
+ end
+ end
+
+ before do
+ allow(described_class).to receive(:load_from_yaml).and_return(default_config)
+ end
+
+ it 'sets up config properly' do
+ expected_result = default_config
+
+ expect(described_class.config).to match expected_result
+ end
+
+ context 'when a config value is missing from the yml file' do
+ it 'overwrites missing values with the default' do
+ stub_config(port: nil)
+
+ expect(described_class.config[:port]).to eq default_port
+ end
+ end
+
+ describe 'setting up redis settings' do
+ let(:fake_redis_queues) { double(url: "localhost", sentinels: "yes, them", sentinels?: true) }
+
+ before do
+ allow(Gitlab::Redis::Queues).to receive(:new).and_return(fake_redis_queues)
+ end
+
+ target_proc = proc { described_class.config[:redis_url] }
+
+ it_behaves_like 'only truthy if both enabled and address are truthy', target_proc
+ end
+
+ describe 'setting up the log path' do
+ context 'if the log path is a relative path' do
+ it 'expands the log path to an absolute value' do
+ stub_config(log_path: 'tiny_log.log')
+
+ new_path = Pathname.new(described_class.config[:log_path])
+ expect(new_path.absolute?).to be_truthy
+ end
+ end
+
+ context 'if the log path is absolute path' do
+ it 'leaves the path as-is' do
+ new_path = '/dev/null'
+ stub_config(log_path: new_path)
+
+ expect(described_class.config[:log_path]).to eq new_path
+ end
+ end
+ end
+ end
+
+ describe '#enabled?' do
+ target_proc = proc { described_class.enabled? }
+
+ it_behaves_like 'only truthy if both enabled and address are truthy', target_proc
+ end
+
+ describe '#reset_config?' do
+ it 'resets config' do
+ described_class.instance_variable_set(:@config, { some_stuff: 'hooray' })
+
+ described_class.reset_config!
+
+ expect(described_class.instance_variable_get(:@config)).to be_nil
+ end
+ end
+
+ def stub_config(override_values)
+ modified_config = default_config.merge(override_values)
+ allow(described_class).to receive(:load_from_yaml).and_return(modified_config)
+ end
+end
diff --git a/spec/lib/gitlab/metrics/instrumentation_spec.rb b/spec/lib/gitlab/metrics/instrumentation_spec.rb
index 0e2f274f157..bf84a476df9 100644
--- a/spec/lib/gitlab/metrics/instrumentation_spec.rb
+++ b/spec/lib/gitlab/metrics/instrumentation_spec.rb
@@ -87,7 +87,9 @@ describe Gitlab::Metrics::Instrumentation do
allow(described_class).to receive(:transaction)
.and_return(transaction)
- expect_any_instance_of(Gitlab::Metrics::MethodCall).to receive(:measure)
+ expect_next_instance_of(Gitlab::Metrics::MethodCall) do |instance|
+ expect(instance).to receive(:measure)
+ end
@dummy.foo
end
@@ -165,7 +167,9 @@ describe Gitlab::Metrics::Instrumentation do
allow(described_class).to receive(:transaction)
.and_return(transaction)
- expect_any_instance_of(Gitlab::Metrics::MethodCall).to receive(:measure)
+ expect_next_instance_of(Gitlab::Metrics::MethodCall) do |instance|
+ expect(instance).to receive(:measure)
+ end
@dummy.new.bar
end
diff --git a/spec/lib/gitlab/query_limiting/middleware_spec.rb b/spec/lib/gitlab/query_limiting/middleware_spec.rb
index fb1c30118c2..f996ea38bb9 100644
--- a/spec/lib/gitlab/query_limiting/middleware_spec.rb
+++ b/spec/lib/gitlab/query_limiting/middleware_spec.rb
@@ -7,8 +7,9 @@ describe Gitlab::QueryLimiting::Middleware do
it 'runs the application with query limiting in place' do
middleware = described_class.new(-> (env) { env })
- expect_any_instance_of(Gitlab::QueryLimiting::Transaction)
- .to receive(:act_upon_results)
+ expect_next_instance_of(Gitlab::QueryLimiting::Transaction) do |instance|
+ expect(instance).to receive(:act_upon_results)
+ end
expect(middleware.call({ number: 10 }))
.to eq({ number: 10 })
diff --git a/spec/lib/gitlab/sanitizers/svg_spec.rb b/spec/lib/gitlab/sanitizers/svg_spec.rb
index a8c7495376d..18fa96a2914 100644
--- a/spec/lib/gitlab/sanitizers/svg_spec.rb
+++ b/spec/lib/gitlab/sanitizers/svg_spec.rb
@@ -14,7 +14,9 @@ describe Gitlab::Sanitizers::SVG do
let(:sanitized) { File.read(sanitized_svg_path) }
it 'delegates sanitization to scrubber' do
- expect_any_instance_of(Gitlab::Sanitizers::SVG::Scrubber).to receive(:scrub).at_least(:once)
+ expect_next_instance_of(Gitlab::Sanitizers::SVG::Scrubber) do |instance|
+ expect(instance).to receive(:scrub).at_least(:once)
+ end
described_class.clean(data)
end
diff --git a/spec/lib/gitlab/sherlock/transaction_spec.rb b/spec/lib/gitlab/sherlock/transaction_spec.rb
index 2245c3ee8e2..728c44df4f3 100644
--- a/spec/lib/gitlab/sherlock/transaction_spec.rb
+++ b/spec/lib/gitlab/sherlock/transaction_spec.rb
@@ -167,8 +167,9 @@ describe Gitlab::Sherlock::Transaction do
allow(Gitlab::Sherlock).to receive(:enable_line_profiler?)
.and_return(true)
- allow_any_instance_of(Gitlab::Sherlock::LineProfiler)
- .to receive(:profile).and_return('cats are amazing', [])
+ allow_next_instance_of(Gitlab::Sherlock::LineProfiler) do |instance|
+ allow(instance).to receive(:profile).and_return('cats are amazing', [])
+ end
retval = transaction.profile_lines { 'cats are amazing' }
diff --git a/spec/lib/gitlab/sidekiq_middleware/correlation_injector_spec.rb b/spec/lib/gitlab/sidekiq_middleware/correlation_injector_spec.rb
index 0ff694d409b..d5ed939485a 100644
--- a/spec/lib/gitlab/sidekiq_middleware/correlation_injector_spec.rb
+++ b/spec/lib/gitlab/sidekiq_middleware/correlation_injector_spec.rb
@@ -28,7 +28,9 @@ describe Gitlab::SidekiqMiddleware::CorrelationInjector do
end
it 'injects into payload the correlation id' do
- expect_any_instance_of(described_class).to receive(:call).and_call_original
+ expect_next_instance_of(described_class) do |instance|
+ expect(instance).to receive(:call).and_call_original
+ end
Labkit::Correlation::CorrelationId.use_id('new-correlation-id') do
TestWorker.perform_async(1234)
diff --git a/spec/lib/gitlab/slash_commands/run_spec.rb b/spec/lib/gitlab/slash_commands/run_spec.rb
index 900fae05719..32a23129e3c 100644
--- a/spec/lib/gitlab/slash_commands/run_spec.rb
+++ b/spec/lib/gitlab/slash_commands/run_spec.rb
@@ -56,13 +56,13 @@ describe Gitlab::SlashCommands::Run do
context 'when a pipeline could not be scheduled' do
it 'returns an error' do
- expect_any_instance_of(Gitlab::Chat::Command)
- .to receive(:try_create_pipeline)
- .and_return(nil)
+ expect_next_instance_of(Gitlab::Chat::Command) do |instance|
+ expect(instance).to receive(:try_create_pipeline).and_return(nil)
+ end
- expect_any_instance_of(Gitlab::SlashCommands::Presenters::Run)
- .to receive(:failed_to_schedule)
- .with('foo')
+ expect_next_instance_of(Gitlab::SlashCommands::Presenters::Run) do |instance|
+ expect(instance).to receive(:failed_to_schedule).with('foo')
+ end
command.execute(command: 'foo', arguments: '')
end
@@ -77,17 +77,18 @@ describe Gitlab::SlashCommands::Run do
persisted?: true
)
- expect_any_instance_of(Gitlab::Chat::Command)
- .to receive(:try_create_pipeline)
- .and_return(pipeline)
+ expect_next_instance_of(Gitlab::Chat::Command) do |instance|
+ expect(instance).to receive(:try_create_pipeline).and_return(pipeline)
+ end
expect(Gitlab::Chat::Responder)
.to receive(:responder_for)
.with(build)
.and_return(nil)
- expect_any_instance_of(Gitlab::SlashCommands::Presenters::Run)
- .to receive(:unsupported_chat_service)
+ expect_next_instance_of(Gitlab::SlashCommands::Presenters::Run) do |instance|
+ expect(instance).to receive(:unsupported_chat_service)
+ end
command.execute(command: 'foo', arguments: '')
end
@@ -103,18 +104,18 @@ describe Gitlab::SlashCommands::Run do
persisted?: true
)
- expect_any_instance_of(Gitlab::Chat::Command)
- .to receive(:try_create_pipeline)
- .and_return(pipeline)
+ expect_next_instance_of(Gitlab::Chat::Command) do |instance|
+ expect(instance).to receive(:try_create_pipeline).and_return(pipeline)
+ end
expect(Gitlab::Chat::Responder)
.to receive(:responder_for)
.with(build)
.and_return(responder)
- expect_any_instance_of(Gitlab::SlashCommands::Presenters::Run)
- .to receive(:in_channel_response)
- .with(responder.scheduled_output)
+ expect_next_instance_of(Gitlab::SlashCommands::Presenters::Run) do |instance|
+ expect(instance).to receive(:in_channel_response).with(responder.scheduled_output)
+ end
command.execute(command: 'foo', arguments: '')
end
diff --git a/spec/migrations/update_minimum_password_length_spec.rb b/spec/migrations/update_minimum_password_length_spec.rb
new file mode 100644
index 00000000000..0a763e5ce0f
--- /dev/null
+++ b/spec/migrations/update_minimum_password_length_spec.rb
@@ -0,0 +1,30 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+require Rails.root.join('db', 'post_migrate', '20191205084057_update_minimum_password_length')
+
+describe UpdateMinimumPasswordLength, :migration do
+ let(:application_settings) { table(:application_settings) }
+ let(:application_setting) do
+ application_settings.create!(
+ minimum_password_length: ApplicationSetting::DEFAULT_MINIMUM_PASSWORD_LENGTH
+ )
+ end
+
+ before do
+ stub_const('ApplicationSetting::DEFAULT_MINIMUM_PASSWORD_LENGTH', 10)
+ allow(Devise.password_length).to receive(:min).and_return(12)
+ end
+
+ it 'correctly migrates minimum_password_length' do
+ reversible_migration do |migration|
+ migration.before -> {
+ expect(application_setting.reload.minimum_password_length).to eq(10)
+ }
+
+ migration.after -> {
+ expect(application_setting.reload.minimum_password_length).to eq(12)
+ }
+ end
+ end
+end
diff --git a/spec/models/application_setting_spec.rb b/spec/models/application_setting_spec.rb
index 9a76be5b6f1..a403aa296d4 100644
--- a/spec/models/application_setting_spec.rb
+++ b/spec/models/application_setting_spec.rb
@@ -68,6 +68,12 @@ describe ApplicationSetting do
it { is_expected.to validate_numericality_of(:snippet_size_limit).only_integer.is_greater_than(0) }
+ it { is_expected.not_to allow_value(7).for(:minimum_password_length) }
+ it { is_expected.not_to allow_value(129).for(:minimum_password_length) }
+ it { is_expected.not_to allow_value(nil).for(:minimum_password_length) }
+ it { is_expected.not_to allow_value('abc').for(:minimum_password_length) }
+ it { is_expected.to allow_value(10).for(:minimum_password_length) }
+
context 'when snowplow is enabled' do
before do
setting.snowplow_enabled = true
diff --git a/spec/models/ci/build_spec.rb b/spec/models/ci/build_spec.rb
index dde37e62e6c..371982df2bb 100644
--- a/spec/models/ci/build_spec.rb
+++ b/spec/models/ci/build_spec.rb
@@ -2366,6 +2366,7 @@ describe Ci::Build do
{ key: 'CI_COMMIT_BEFORE_SHA', value: build.before_sha, public: true, masked: false },
{ key: 'CI_COMMIT_REF_NAME', value: build.ref, public: true, masked: false },
{ key: 'CI_COMMIT_REF_SLUG', value: build.ref_slug, public: true, masked: false },
+ { key: 'CI_COMMIT_BRANCH', value: build.ref, public: true, masked: false },
{ key: 'CI_COMMIT_MESSAGE', value: pipeline.git_commit_message, public: true, masked: false },
{ key: 'CI_COMMIT_TITLE', value: pipeline.git_commit_title, public: true, masked: false },
{ key: 'CI_COMMIT_DESCRIPTION', value: pipeline.git_commit_description, public: true, masked: false },
@@ -2589,6 +2590,19 @@ describe Ci::Build do
it { is_expected.to include(job_variable) }
end
+ context 'when build is for branch' do
+ let(:branch_variable) do
+ { key: 'CI_COMMIT_BRANCH', value: 'master', public: true, masked: false }
+ end
+
+ before do
+ build.update(tag: false)
+ pipeline.update(tag: false)
+ end
+
+ it { is_expected.to include(branch_variable) }
+ end
+
context 'when build is for tag' do
let(:tag_variable) do
{ key: 'CI_COMMIT_TAG', value: 'master', public: true, masked: false }
@@ -3522,7 +3536,7 @@ describe Ci::Build do
end
it 'can drop the build' do
- expect(Gitlab::Sentry).to receive(:track_and_raise_for_dev_exception)
+ expect(Gitlab::ErrorTracking).to receive(:track_and_raise_for_dev_exception)
expect { build.drop! }.not_to raise_error
diff --git a/spec/models/ci/pipeline_spec.rb b/spec/models/ci/pipeline_spec.rb
index b60e240d596..3f9e882ea52 100644
--- a/spec/models/ci/pipeline_spec.rb
+++ b/spec/models/ci/pipeline_spec.rb
@@ -599,6 +599,7 @@ describe Ci::Pipeline, :mailer do
CI_COMMIT_BEFORE_SHA
CI_COMMIT_REF_NAME
CI_COMMIT_REF_SLUG
+ CI_COMMIT_BRANCH
CI_COMMIT_MESSAGE
CI_COMMIT_TITLE
CI_COMMIT_DESCRIPTION
diff --git a/spec/models/clusters/cluster_spec.rb b/spec/models/clusters/cluster_spec.rb
index 036b6c7902f..44ca4a06e2d 100644
--- a/spec/models/clusters/cluster_spec.rb
+++ b/spec/models/clusters/cluster_spec.rb
@@ -1004,7 +1004,7 @@ describe Clusters::Cluster, :use_clean_rails_memory_store_caching do
it { is_expected.to eq(connection_status: :unknown_failure) }
it 'notifies Sentry' do
- expect(Gitlab::Sentry).to receive(:track_exception)
+ expect(Gitlab::ErrorTracking).to receive(:track_exception)
.with(instance_of(StandardError), hash_including(cluster_id: cluster.id))
subject
diff --git a/spec/models/concerns/group_descendant_spec.rb b/spec/models/concerns/group_descendant_spec.rb
index 6af57283a2a..47419770d0f 100644
--- a/spec/models/concerns/group_descendant_spec.rb
+++ b/spec/models/concerns/group_descendant_spec.rb
@@ -82,7 +82,7 @@ describe GroupDescendant do
end
it 'tracks the exception when a parent was not preloaded' do
- expect(Gitlab::Sentry).to receive(:track_and_raise_for_dev_exception).and_call_original
+ expect(Gitlab::ErrorTracking).to receive(:track_and_raise_for_dev_exception).and_call_original
expect { described_class.build_hierarchy([subsub_group]) }.to raise_error(ArgumentError)
end
@@ -91,7 +91,7 @@ describe GroupDescendant do
expected_hierarchy = { parent => { subgroup => subsub_group } }
# this does not raise in production, so stubbing it here.
- allow(Gitlab::Sentry).to receive(:track_and_raise_for_dev_exception)
+ allow(Gitlab::ErrorTracking).to receive(:track_and_raise_for_dev_exception)
expect(described_class.build_hierarchy([subsub_group])).to eq(expected_hierarchy)
end
diff --git a/spec/models/namespace_spec.rb b/spec/models/namespace_spec.rb
index 3089afd8d8a..2ba0d97792b 100644
--- a/spec/models/namespace_spec.rb
+++ b/spec/models/namespace_spec.rb
@@ -281,7 +281,7 @@ describe Namespace do
move_dir_result
end
- expect(Gitlab::Sentry).to receive(:should_raise_for_dev?).and_return(false) # like prod
+ expect(Gitlab::ErrorTracking).to receive(:should_raise_for_dev?).and_return(false) # like prod
namespace.update(path: namespace.full_path + '_new')
end
diff --git a/spec/models/upload_spec.rb b/spec/models/upload_spec.rb
index 6128e7d2a24..7138305d7b1 100644
--- a/spec/models/upload_spec.rb
+++ b/spec/models/upload_spec.rb
@@ -171,7 +171,7 @@ describe Upload do
it 'sends a message to Sentry' do
upload = create(:upload, :issuable_upload)
- expect(Gitlab::Sentry).to receive(:track_exception).with(instance_of(RuntimeError), upload.attributes)
+ expect(Gitlab::ErrorTracking).to receive(:track_exception).with(instance_of(RuntimeError), upload.attributes)
upload.exist?
end
diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb
index 49991dbd2d4..db26b872045 100644
--- a/spec/models/user_spec.rb
+++ b/spec/models/user_spec.rb
@@ -98,6 +98,53 @@ describe User, :do_not_mock_admin_mode do
end
describe 'validations' do
+ describe 'password' do
+ let!(:user) { create(:user) }
+
+ before do
+ allow(Devise).to receive(:password_length).and_return(8..128)
+ allow(described_class).to receive(:password_length).and_return(10..130)
+ end
+
+ context 'length' do
+ it { is_expected.to validate_length_of(:password).is_at_least(10).is_at_most(130) }
+ end
+
+ context 'length validator' do
+ context 'for a short password' do
+ before do
+ user.password = user.password_confirmation = 'abc'
+ end
+
+ it 'does not run the default Devise password length validation' do
+ expect(user).to be_invalid
+ expect(user.errors.full_messages.join).not_to include('is too short (minimum is 8 characters)')
+ end
+
+ it 'runs the custom password length validator' do
+ expect(user).to be_invalid
+ expect(user.errors.full_messages.join).to include('is too short (minimum is 10 characters)')
+ end
+ end
+
+ context 'for a long password' do
+ before do
+ user.password = user.password_confirmation = 'a' * 140
+ end
+
+ it 'does not run the default Devise password length validation' do
+ expect(user).to be_invalid
+ expect(user.errors.full_messages.join).not_to include('is too long (maximum is 128 characters)')
+ end
+
+ it 'runs the custom password length validator' do
+ expect(user).to be_invalid
+ expect(user.errors.full_messages.join).to include('is too long (maximum is 130 characters)')
+ end
+ end
+ end
+ end
+
describe 'name' do
it { is_expected.to validate_presence_of(:name) }
it { is_expected.to validate_length_of(:name).is_at_most(128) }
@@ -461,6 +508,34 @@ describe User, :do_not_mock_admin_mode do
end
end
+ describe '.password_length' do
+ let(:password_length) { described_class.password_length }
+
+ it 'is expected to be a Range' do
+ expect(password_length).to be_a(Range)
+ end
+
+ context 'minimum value' do
+ before do
+ stub_application_setting(minimum_password_length: 101)
+ end
+
+ it 'is determined by the current value of `minimum_password_length` attribute of application_setting' do
+ expect(password_length.min).to eq(101)
+ end
+ end
+
+ context 'maximum value' do
+ before do
+ allow(Devise.password_length).to receive(:max).and_return(201)
+ end
+
+ it 'is determined by the current value of `Devise.password_length.max`' do
+ expect(password_length.max).to eq(201)
+ end
+ end
+ end
+
describe '.limit_to_todo_authors' do
context 'when filtering by todo authors' do
let(:user1) { create(:user) }
diff --git a/spec/requests/api/branches_spec.rb b/spec/requests/api/branches_spec.rb
index eda2f6d854f..99374d28324 100644
--- a/spec/requests/api/branches_spec.rb
+++ b/spec/requests/api/branches_spec.rb
@@ -629,7 +629,9 @@ describe API::Branches do
describe 'DELETE /projects/:id/repository/branches/:branch' do
before do
- allow_any_instance_of(Repository).to receive(:rm_branch).and_return(true)
+ allow_next_instance_of(Repository) do |instance|
+ allow(instance).to receive(:rm_branch).and_return(true)
+ end
end
it 'removes branch' do
@@ -666,7 +668,9 @@ describe API::Branches do
describe 'DELETE /projects/:id/repository/merged_branches' do
before do
- allow_any_instance_of(Repository).to receive(:rm_branch).and_return(true)
+ allow_next_instance_of(Repository) do |instance|
+ allow(instance).to receive(:rm_branch).and_return(true)
+ end
end
it 'returns 202 with json body' do
diff --git a/spec/requests/api/files_spec.rb b/spec/requests/api/files_spec.rb
index f1e1b8df8ee..ab915af8ab0 100644
--- a/spec/requests/api/files_spec.rb
+++ b/spec/requests/api/files_spec.rb
@@ -548,8 +548,9 @@ describe API::Files do
end
it "returns a 400 if editor fails to create file" do
- allow_any_instance_of(Repository).to receive(:create_file)
- .and_raise(Gitlab::Git::CommitError, 'Cannot create file')
+ allow_next_instance_of(Repository) do |instance|
+ allow(instance).to receive(:create_file).and_raise(Gitlab::Git::CommitError, 'Cannot create file')
+ end
post api(route("any%2Etxt"), user), params: params
@@ -698,7 +699,9 @@ describe API::Files do
end
it "returns a 400 if fails to delete file" do
- allow_any_instance_of(Repository).to receive(:delete_file).and_raise(Gitlab::Git::CommitError, 'Cannot delete file')
+ allow_next_instance_of(Repository) do |instance|
+ allow(instance).to receive(:delete_file).and_raise(Gitlab::Git::CommitError, 'Cannot delete file')
+ end
delete api(route(file_path), user), params: params
diff --git a/spec/requests/api/graphql_spec.rb b/spec/requests/api/graphql_spec.rb
index bfdfd034cca..d0378278600 100644
--- a/spec/requests/api/graphql_spec.rb
+++ b/spec/requests/api/graphql_spec.rb
@@ -46,7 +46,7 @@ describe 'GraphQL' do
end
it 'logs the exception in Sentry and continues with the request' do
- expect(Gitlab::Sentry).to receive(:track_and_raise_for_dev_exception).at_least(1).times
+ expect(Gitlab::ErrorTracking).to receive(:track_and_raise_for_dev_exception).at_least(1).times
expect(Gitlab::GraphqlLogger).to receive(:info)
post_graphql(query, variables: {})
@@ -146,7 +146,7 @@ describe 'GraphQL' do
end
it "logs a warning that the 'calls_gitaly' field declaration is missing" do
- expect(Gitlab::Sentry).to receive(:track_and_raise_for_dev_exception).once
+ expect(Gitlab::ErrorTracking).to receive(:track_and_raise_for_dev_exception).once
post_graphql(query, current_user: user)
end
diff --git a/spec/requests/api/groups_spec.rb b/spec/requests/api/groups_spec.rb
index c7b35d6f50d..a4f68df928f 100644
--- a/spec/requests/api/groups_spec.rb
+++ b/spec/requests/api/groups_spec.rb
@@ -1075,8 +1075,9 @@ describe API::Groups do
let(:project_path) { CGI.escape(project.full_path) }
before do
- allow_any_instance_of(Projects::TransferService)
- .to receive(:execute).and_return(true)
+ allow_next_instance_of(Projects::TransferService) do |instance|
+ allow(instance).to receive(:execute).and_return(true)
+ end
end
context "when authenticated as user" do
diff --git a/spec/requests/api/helpers_spec.rb b/spec/requests/api/helpers_spec.rb
index 1bec860bf0e..26174611c58 100644
--- a/spec/requests/api/helpers_spec.rb
+++ b/spec/requests/api/helpers_spec.rb
@@ -229,8 +229,8 @@ describe API::Helpers do
stub_sentry_settings
- expect(Gitlab::Sentry).to receive(:sentry_dsn).and_return(Gitlab.config.sentry.dsn)
- Gitlab::Sentry.configure
+ expect(Gitlab::ErrorTracking).to receive(:sentry_dsn).and_return(Gitlab.config.sentry.dsn)
+ Gitlab::ErrorTracking.configure
Raven.client.configuration.encoding = 'json'
end
diff --git a/spec/requests/api/jobs_spec.rb b/spec/requests/api/jobs_spec.rb
index 020e7659a4c..82bf607b911 100644
--- a/spec/requests/api/jobs_spec.rb
+++ b/spec/requests/api/jobs_spec.rb
@@ -795,9 +795,11 @@ describe API::Jobs do
before do
stub_remote_url_206(url, file_path)
- allow_any_instance_of(JobArtifactUploader).to receive(:file_storage?) { false }
- allow_any_instance_of(JobArtifactUploader).to receive(:url) { url }
- allow_any_instance_of(JobArtifactUploader).to receive(:size) { File.size(file_path) }
+ allow_next_instance_of(JobArtifactUploader) do |instance|
+ allow(instance).to receive(:file_storage?) { false }
+ allow(instance).to receive(:url) { url }
+ allow(instance).to receive(:size) { File.size(file_path) }
+ end
end
it 'returns specific job trace' do
diff --git a/spec/requests/api/project_snippets_spec.rb b/spec/requests/api/project_snippets_spec.rb
index cac3f07d0d0..bfb6f10efa3 100644
--- a/spec/requests/api/project_snippets_spec.rb
+++ b/spec/requests/api/project_snippets_spec.rb
@@ -179,7 +179,9 @@ describe API::ProjectSnippets do
end
before do
- allow_any_instance_of(AkismetService).to receive(:spam?).and_return(true)
+ allow_next_instance_of(AkismetService) do |instance|
+ allow(instance).to receive(:spam?).and_return(true)
+ end
end
context 'when the snippet is private' do
@@ -269,7 +271,9 @@ describe API::ProjectSnippets do
end
before do
- allow_any_instance_of(AkismetService).to receive(:spam?).and_return(true)
+ allow_next_instance_of(AkismetService) do |instance|
+ allow(instance).to receive(:spam?).and_return(true)
+ end
end
context 'when the snippet is private' do
diff --git a/spec/requests/api/snippets_spec.rb b/spec/requests/api/snippets_spec.rb
index 29ef040ee2e..eb9d0d38bcb 100644
--- a/spec/requests/api/snippets_spec.rb
+++ b/spec/requests/api/snippets_spec.rb
@@ -238,7 +238,9 @@ describe API::Snippets do
end
before do
- allow_any_instance_of(AkismetService).to receive(:spam?).and_return(true)
+ allow_next_instance_of(AkismetService) do |instance|
+ allow(instance).to receive(:spam?).and_return(true)
+ end
end
context 'when the snippet is private' do
@@ -325,7 +327,9 @@ describe API::Snippets do
end
before do
- allow_any_instance_of(AkismetService).to receive(:spam?).and_return(true)
+ allow_next_instance_of(AkismetService) do |instance|
+ allow(instance).to receive(:spam?).and_return(true)
+ end
end
context 'when the snippet is private' do
diff --git a/spec/requests/api/tags_spec.rb b/spec/requests/api/tags_spec.rb
index dca87d5e4ce..09e63b86cfc 100644
--- a/spec/requests/api/tags_spec.rb
+++ b/spec/requests/api/tags_spec.rb
@@ -328,7 +328,9 @@ describe API::Tags do
let(:route) { "/projects/#{project_id}/repository/tags/#{tag_name}" }
before do
- allow_any_instance_of(Repository).to receive(:rm_tag).and_return(true)
+ allow_next_instance_of(Repository) do |instance|
+ allow(instance).to receive(:rm_tag).and_return(true)
+ end
end
shared_examples_for 'repository delete tag' do
diff --git a/spec/requests/jwt_controller_spec.rb b/spec/requests/jwt_controller_spec.rb
index c1f99115612..199c2dbe9ca 100644
--- a/spec/requests/jwt_controller_spec.rb
+++ b/spec/requests/jwt_controller_spec.rb
@@ -134,7 +134,9 @@ describe JwtController do
context 'when internal auth is disabled' do
it 'rejects the authorization attempt with personal access token message' do
- allow_any_instance_of(ApplicationSetting).to receive(:password_authentication_enabled_for_git?) { false }
+ allow_next_instance_of(ApplicationSetting) do |instance|
+ allow(instance).to receive(:password_authentication_enabled_for_git?) { false }
+ end
get '/jwt/auth', params: parameters, headers: headers
expect(response).to have_gitlab_http_status(401)
diff --git a/spec/requests/rack_attack_global_spec.rb b/spec/requests/rack_attack_global_spec.rb
index 9e62d84d313..9968b2e4aba 100644
--- a/spec/requests/rack_attack_global_spec.rb
+++ b/spec/requests/rack_attack_global_spec.rb
@@ -84,7 +84,9 @@ describe 'Rack Attack global throttles' do
expect(response).to have_http_status 200
end
- expect_any_instance_of(Rack::Attack::Request).to receive(:ip).at_least(:once).and_return('1.2.3.4')
+ expect_next_instance_of(Rack::Attack::Request) do |instance|
+ expect(instance).to receive(:ip).at_least(:once).and_return('1.2.3.4')
+ end
# would be over limit for the same IP
get url_that_does_not_require_authentication
diff --git a/spec/rubocop/cop/avoid_break_from_strong_memoize_spec.rb b/spec/rubocop/cop/avoid_break_from_strong_memoize_spec.rb
index 62f6c7a3414..feb85c354ef 100644
--- a/spec/rubocop/cop/avoid_break_from_strong_memoize_spec.rb
+++ b/spec/rubocop/cop/avoid_break_from_strong_memoize_spec.rb
@@ -62,7 +62,9 @@ describe RuboCop::Cop::AvoidBreakFromStrongMemoize do
end
end
RUBY
- expect_any_instance_of(described_class).to receive(:add_offense).once
+ expect_next_instance_of(described_class) do |instance|
+ expect(instance).to receive(:add_offense).once
+ end
inspect_source(source)
end
diff --git a/spec/rubocop/cop/avoid_return_from_blocks_spec.rb b/spec/rubocop/cop/avoid_return_from_blocks_spec.rb
index 133d286ccd2..919cd3d98f3 100644
--- a/spec/rubocop/cop/avoid_return_from_blocks_spec.rb
+++ b/spec/rubocop/cop/avoid_return_from_blocks_spec.rb
@@ -29,7 +29,9 @@ describe RuboCop::Cop::AvoidReturnFromBlocks do
end
end
RUBY
- expect_any_instance_of(described_class).to receive(:add_offense).once
+ expect_next_instance_of(described_class) do |instance|
+ expect(instance).to receive(:add_offense).once
+ end
inspect_source(source)
end
diff --git a/spec/serializers/analytics_summary_serializer_spec.rb b/spec/serializers/analytics_summary_serializer_spec.rb
index 33a41706794..06f2c0ca68b 100644
--- a/spec/serializers/analytics_summary_serializer_spec.rb
+++ b/spec/serializers/analytics_summary_serializer_spec.rb
@@ -16,8 +16,9 @@ describe AnalyticsSummarySerializer do
end
before do
- allow_any_instance_of(Gitlab::CycleAnalytics::Summary::Issue)
- .to receive(:value).and_return(1.12)
+ allow_next_instance_of(Gitlab::CycleAnalytics::Summary::Issue) do |instance|
+ allow(instance).to receive(:value).and_return(1.12)
+ end
end
it 'generates payload for single object' do
diff --git a/spec/services/auth/container_registry_authentication_service_spec.rb b/spec/services/auth/container_registry_authentication_service_spec.rb
index 2807b8c8c85..5003dfcc951 100644
--- a/spec/services/auth/container_registry_authentication_service_spec.rb
+++ b/spec/services/auth/container_registry_authentication_service_spec.rb
@@ -20,7 +20,9 @@ describe Auth::ContainerRegistryAuthenticationService do
before do
allow(Gitlab.config.registry).to receive_messages(enabled: true, issuer: 'rspec', key: nil)
- allow_any_instance_of(JSONWebToken::RSAToken).to receive(:key).and_return(rsa_key)
+ allow_next_instance_of(JSONWebToken::RSAToken) do |instance|
+ allow(instance).to receive(:key).and_return(rsa_key)
+ end
end
shared_examples 'an authenticated' do
diff --git a/spec/services/boards/issues/create_service_spec.rb b/spec/services/boards/issues/create_service_spec.rb
index ef7b7fdbaac..3520630dd83 100644
--- a/spec/services/boards/issues/create_service_spec.rb
+++ b/spec/services/boards/issues/create_service_spec.rb
@@ -17,7 +17,9 @@ describe Boards::Issues::CreateService do
end
it 'delegates the create proceedings to Issues::CreateService' do
- expect_any_instance_of(Issues::CreateService).to receive(:execute).once
+ expect_next_instance_of(Issues::CreateService) do |instance|
+ expect(instance).to receive(:execute).once
+ end
service.execute
end
diff --git a/spec/services/ci/archive_trace_service_spec.rb b/spec/services/ci/archive_trace_service_spec.rb
index 64fa74ccce5..ba94013b574 100644
--- a/spec/services/ci/archive_trace_service_spec.rb
+++ b/spec/services/ci/archive_trace_service_spec.rb
@@ -41,7 +41,9 @@ describe Ci::ArchiveTraceService, '#execute' do
context 'when job failed to archive trace but did not raise an exception' do
before do
- allow_any_instance_of(Gitlab::Ci::Trace).to receive(:archive!) {}
+ allow_next_instance_of(Gitlab::Ci::Trace) do |instance|
+ allow(instance).to receive(:archive!) {}
+ end
end
it 'leaves a warning message in sidekiq log' do
@@ -59,7 +61,7 @@ describe Ci::ArchiveTraceService, '#execute' do
let(:job) { create(:ci_build, :running, :trace_live) }
it 'increments Prometheus counter, sends crash report to Sentry and ignore an error for continuing to archive' do
- expect(Gitlab::Sentry)
+ expect(Gitlab::ErrorTracking)
.to receive(:track_and_raise_for_dev_exception)
.with(::Gitlab::Ci::Trace::ArchiveError,
issue_url: 'https://gitlab.com/gitlab-org/gitlab-foss/issues/51502',
diff --git a/spec/services/ci/create_pipeline_service/rules_spec.rb b/spec/services/ci/create_pipeline_service/rules_spec.rb
index 2c93007f8e8..0a2c5724ce4 100644
--- a/spec/services/ci/create_pipeline_service/rules_spec.rb
+++ b/spec/services/ci/create_pipeline_service/rules_spec.rb
@@ -13,7 +13,9 @@ describe Ci::CreatePipelineService do
context 'job:rules' do
before do
stub_ci_pipeline_yaml_file(config)
- allow_any_instance_of(Ci::BuildScheduleWorker).to receive(:perform).and_return(true)
+ allow_next_instance_of(Ci::BuildScheduleWorker) do |instance|
+ allow(instance).to receive(:perform).and_return(true)
+ end
end
context 'exists:' do
@@ -98,6 +100,17 @@ describe Ci::CreatePipelineService do
stub_ci_pipeline_yaml_file(config)
end
+ shared_examples 'workflow:rules feature disabled' do
+ before do
+ stub_feature_flags(workflow_rules: false)
+ end
+
+ it 'presents a message that rules are disabled' do
+ expect(pipeline.errors[:base]).to include('Workflow rules are disabled')
+ expect(pipeline).to be_persisted
+ end
+ end
+
context 'with a single regex-matching if: clause' do
let(:config) do
<<-EOY
@@ -229,16 +242,7 @@ describe Ci::CreatePipelineService do
expect(pipeline).not_to be_persisted
end
- context 'with workflow:rules shut off' do
- before do
- stub_feature_flags(workflow_rules: false)
- end
-
- it 'invalidates the pipeline with an empty jobs error' do
- expect(pipeline.errors[:base]).to include('No stages / jobs for this pipeline.')
- expect(pipeline).not_to be_persisted
- end
- end
+ it_behaves_like 'workflow:rules feature disabled'
end
context 'where workflow passes and the job passes' do
@@ -249,16 +253,7 @@ describe Ci::CreatePipelineService do
expect(pipeline).to be_persisted
end
- context 'with workflow:rules shut off' do
- before do
- stub_feature_flags(workflow_rules: false)
- end
-
- it 'saves a pending pipeline' do
- expect(pipeline).to be_pending
- expect(pipeline).to be_persisted
- end
- end
+ it_behaves_like 'workflow:rules feature disabled'
end
context 'where workflow fails and the job fails' do
@@ -269,16 +264,7 @@ describe Ci::CreatePipelineService do
expect(pipeline).not_to be_persisted
end
- context 'with workflow:rules shut off' do
- before do
- stub_feature_flags(workflow_rules: false)
- end
-
- it 'invalidates the pipeline with an empty jobs error' do
- expect(pipeline.errors[:base]).to include('No stages / jobs for this pipeline.')
- expect(pipeline).not_to be_persisted
- end
- end
+ it_behaves_like 'workflow:rules feature disabled'
end
context 'where workflow fails and the job passes' do
@@ -289,16 +275,7 @@ describe Ci::CreatePipelineService do
expect(pipeline).not_to be_persisted
end
- context 'with workflow:rules shut off' do
- before do
- stub_feature_flags(workflow_rules: false)
- end
-
- it 'saves a pending pipeline' do
- expect(pipeline).to be_pending
- expect(pipeline).to be_persisted
- end
- end
+ it_behaves_like 'workflow:rules feature disabled'
end
end
end
diff --git a/spec/services/ci/create_pipeline_service_spec.rb b/spec/services/ci/create_pipeline_service_spec.rb
index c4274f0bd17..4f624368215 100644
--- a/spec/services/ci/create_pipeline_service_spec.rb
+++ b/spec/services/ci/create_pipeline_service_spec.rb
@@ -528,7 +528,7 @@ describe Ci::CreatePipelineService do
end
it 'logs error' do
- expect(Gitlab::Sentry).to receive(:track_exception).and_call_original
+ expect(Gitlab::ErrorTracking).to receive(:track_exception).and_call_original
execute_service
end
@@ -613,7 +613,7 @@ describe Ci::CreatePipelineService do
end
it 'logs error' do
- expect(Gitlab::Sentry).to receive(:track_exception).and_call_original
+ expect(Gitlab::ErrorTracking).to receive(:track_exception).and_call_original
execute_service
end
diff --git a/spec/services/ci/pipeline_trigger_service_spec.rb b/spec/services/ci/pipeline_trigger_service_spec.rb
index 24d42f402f4..44ce1ff699b 100644
--- a/spec/services/ci/pipeline_trigger_service_spec.rb
+++ b/spec/services/ci/pipeline_trigger_service_spec.rb
@@ -45,7 +45,9 @@ describe Ci::PipelineTriggerService do
context 'when commit message has [ci skip]' do
before do
- allow_any_instance_of(Ci::Pipeline).to receive(:git_commit_message) { '[ci skip]' }
+ allow_next_instance_of(Ci::Pipeline) do |instance|
+ allow(instance).to receive(:git_commit_message) { '[ci skip]' }
+ end
end
it 'ignores [ci skip] and create as general' do
@@ -124,7 +126,9 @@ describe Ci::PipelineTriggerService do
context 'when commit message has [ci skip]' do
before do
- allow_any_instance_of(Ci::Pipeline).to receive(:git_commit_message) { '[ci skip]' }
+ allow_next_instance_of(Ci::Pipeline) do |instance|
+ allow(instance).to receive(:git_commit_message) { '[ci skip]' }
+ end
end
it 'ignores [ci skip] and create as general' do
diff --git a/spec/services/ci/play_manual_stage_service_spec.rb b/spec/services/ci/play_manual_stage_service_spec.rb
index 5d812745c7f..e2946111a13 100644
--- a/spec/services/ci/play_manual_stage_service_spec.rb
+++ b/spec/services/ci/play_manual_stage_service_spec.rb
@@ -51,8 +51,9 @@ describe Ci::PlayManualStageService, '#execute' do
context 'when user does not have permission on a specific build' do
before do
- allow_any_instance_of(Ci::Build).to receive(:play)
- .and_raise(Gitlab::Access::AccessDeniedError)
+ allow_next_instance_of(Ci::Build) do |instance|
+ allow(instance).to receive(:play).and_raise(Gitlab::Access::AccessDeniedError)
+ end
service.execute(stage)
end
diff --git a/spec/services/ci/prepare_build_service_spec.rb b/spec/services/ci/prepare_build_service_spec.rb
index 87061b3b15a..3c3d8b90bb0 100644
--- a/spec/services/ci/prepare_build_service_spec.rb
+++ b/spec/services/ci/prepare_build_service_spec.rb
@@ -51,7 +51,7 @@ describe Ci::PrepareBuildService do
it 'drops the build and notifies Sentry' do
expect(build).to receive(:drop).with(:unmet_prerequisites).once
- expect(Gitlab::Sentry).to receive(:track_exception)
+ expect(Gitlab::ErrorTracking).to receive(:track_exception)
.with(instance_of(Kubeclient::HttpError), hash_including(build_id: build.id))
subject
diff --git a/spec/services/ci/process_pipeline_service_spec.rb b/spec/services/ci/process_pipeline_service_spec.rb
index a15a0afc526..ba5891c8694 100644
--- a/spec/services/ci/process_pipeline_service_spec.rb
+++ b/spec/services/ci/process_pipeline_service_spec.rb
@@ -426,7 +426,9 @@ describe Ci::ProcessPipelineService, '#execute' do
before do
successful_build('test', stage_idx: 0)
- allow_any_instance_of(Ci::PersistentRef).to receive(:delete_refs) { raise ArgumentError }
+ allow_next_instance_of(Ci::PersistentRef) do |instance|
+ allow(instance).to receive(:delete_refs) { raise ArgumentError }
+ end
end
it 'process the pipeline' do
diff --git a/spec/services/ci/register_job_service_spec.rb b/spec/services/ci/register_job_service_spec.rb
index aa31d98c4fb..0339c6cc2d6 100644
--- a/spec/services/ci/register_job_service_spec.rb
+++ b/spec/services/ci/register_job_service_spec.rb
@@ -514,7 +514,7 @@ module Ci
subject { execute(specific_runner, {}) }
it 'does drop the build and logs both failures' do
- expect(Gitlab::Sentry).to receive(:track_exception)
+ expect(Gitlab::ErrorTracking).to receive(:track_exception)
.with(anything, a_hash_including(build_id: pending_job.id))
.twice
.and_call_original
@@ -540,7 +540,7 @@ module Ci
subject { execute(specific_runner, {}) }
it 'does drop the build and logs failure' do
- expect(Gitlab::Sentry).to receive(:track_exception)
+ expect(Gitlab::ErrorTracking).to receive(:track_exception)
.with(anything, a_hash_including(build_id: pending_job.id))
.once
.and_call_original
diff --git a/spec/services/clusters/applications/check_installation_progress_service_spec.rb b/spec/services/clusters/applications/check_installation_progress_service_spec.rb
index 335397ee9f5..7b37eb97800 100644
--- a/spec/services/clusters/applications/check_installation_progress_service_spec.rb
+++ b/spec/services/clusters/applications/check_installation_progress_service_spec.rb
@@ -144,10 +144,9 @@ describe Clusters::Applications::CheckInstallationProgressService, '#execute' do
end
it 'removes the installation POD' do
- expect_any_instance_of(Gitlab::Kubernetes::Helm::Api)
- .to receive(:delete_pod!)
- .with(kind_of(String))
- .once
+ expect_next_instance_of(Gitlab::Kubernetes::Helm::Api) do |instance|
+ expect(instance).to receive(:delete_pod!).with(kind_of(String)).once
+ end
expect(service).to receive(:remove_installation_pod).and_call_original
service.execute
diff --git a/spec/services/clusters/applications/check_uninstall_progress_service_spec.rb b/spec/services/clusters/applications/check_uninstall_progress_service_spec.rb
index a70b94a6fd6..93557c6b229 100644
--- a/spec/services/clusters/applications/check_uninstall_progress_service_spec.rb
+++ b/spec/services/clusters/applications/check_uninstall_progress_service_spec.rb
@@ -48,10 +48,9 @@ describe Clusters::Applications::CheckUninstallProgressService do
let(:phase) { Gitlab::Kubernetes::Pod::SUCCEEDED }
before do
- expect_any_instance_of(Gitlab::Kubernetes::Helm::Api)
- .to receive(:delete_pod!)
- .with(kind_of(String))
- .once
+ expect_next_instance_of(Gitlab::Kubernetes::Helm::Api) do |instance|
+ expect(instance).to receive(:delete_pod!).with(kind_of(String)).once
+ end
expect(service).to receive(:pod_phase).once.and_return(phase)
end
diff --git a/spec/services/clusters/gcp/verify_provision_status_service_spec.rb b/spec/services/clusters/gcp/verify_provision_status_service_spec.rb
index 9611b2080ba..584f9b8367f 100644
--- a/spec/services/clusters/gcp/verify_provision_status_service_spec.rb
+++ b/spec/services/clusters/gcp/verify_provision_status_service_spec.rb
@@ -21,7 +21,9 @@ describe Clusters::Gcp::VerifyProvisionStatusService do
shared_examples 'finalize_creation' do
it 'schedules a worker for status minitoring' do
- expect_any_instance_of(Clusters::Gcp::FinalizeCreationService).to receive(:execute)
+ expect_next_instance_of(Clusters::Gcp::FinalizeCreationService) do |instance|
+ expect(instance).to receive(:execute)
+ end
described_class.new.execute(provider)
end
diff --git a/spec/services/clusters/kubernetes/create_or_update_namespace_service_spec.rb b/spec/services/clusters/kubernetes/create_or_update_namespace_service_spec.rb
index 1f520c4849d..5dc4a1dc0b3 100644
--- a/spec/services/clusters/kubernetes/create_or_update_namespace_service_spec.rb
+++ b/spec/services/clusters/kubernetes/create_or_update_namespace_service_spec.rb
@@ -60,7 +60,9 @@ describe Clusters::Kubernetes::CreateOrUpdateNamespaceService, '#execute' do
end
it 'creates project service account' do
- expect_any_instance_of(Clusters::Kubernetes::CreateOrUpdateServiceAccountService).to receive(:execute).once
+ expect_next_instance_of(Clusters::Kubernetes::CreateOrUpdateServiceAccountService) do |instance|
+ expect(instance).to receive(:execute).once
+ end
subject
end
@@ -127,7 +129,9 @@ describe Clusters::Kubernetes::CreateOrUpdateNamespaceService, '#execute' do
end
it 'creates project service account' do
- expect_any_instance_of(Clusters::Kubernetes::CreateOrUpdateServiceAccountService).to receive(:execute).once
+ expect_next_instance_of(Clusters::Kubernetes::CreateOrUpdateServiceAccountService) do |instance|
+ expect(instance).to receive(:execute).once
+ end
subject
end
diff --git a/spec/services/discussions/resolve_service_spec.rb b/spec/services/discussions/resolve_service_spec.rb
index 5b99430cb75..2e9a7a293d1 100644
--- a/spec/services/discussions/resolve_service_spec.rb
+++ b/spec/services/discussions/resolve_service_spec.rb
@@ -29,7 +29,9 @@ describe Discussions::ResolveService do
end
it 'executes the notification service' do
- expect_any_instance_of(MergeRequests::ResolvedDiscussionNotificationService).to receive(:execute).with(discussion.noteable)
+ expect_next_instance_of(MergeRequests::ResolvedDiscussionNotificationService) do |instance|
+ expect(instance).to receive(:execute).with(discussion.noteable)
+ end
service.execute(discussion)
end
diff --git a/spec/services/event_create_service_spec.rb b/spec/services/event_create_service_spec.rb
index eb738ac80b1..a8ddca0cdf3 100644
--- a/spec/services/event_create_service_spec.rb
+++ b/spec/services/event_create_service_spec.rb
@@ -131,9 +131,9 @@ describe EventCreateService do
end
it 'caches the last push event for the user' do
- expect_any_instance_of(Users::LastPushEventService)
- .to receive(:cache_last_push_event)
- .with(an_instance_of(PushEvent))
+ expect_next_instance_of(Users::LastPushEventService) do |instance|
+ expect(instance).to receive(:cache_last_push_event).with(an_instance_of(PushEvent))
+ end
subject
end
diff --git a/spec/services/groups/destroy_service_spec.rb b/spec/services/groups/destroy_service_spec.rb
index 055d0243d4b..a45c7cdffa6 100644
--- a/spec/services/groups/destroy_service_spec.rb
+++ b/spec/services/groups/destroy_service_spec.rb
@@ -41,7 +41,9 @@ describe Groups::DestroyService do
let!(:chat_team) { create(:chat_team, namespace: group) }
it 'destroys the team too' do
- expect_any_instance_of(Mattermost::Team).to receive(:destroy)
+ expect_next_instance_of(Mattermost::Team) do |instance|
+ expect(instance).to receive(:destroy)
+ end
destroy_group(group, user, async)
end
diff --git a/spec/services/groups/transfer_service_spec.rb b/spec/services/groups/transfer_service_spec.rb
index 9a490dfd779..bbf5bbbf814 100644
--- a/spec/services/groups/transfer_service_spec.rb
+++ b/spec/services/groups/transfer_service_spec.rb
@@ -13,7 +13,9 @@ describe Groups::TransferService do
let(:new_parent_group) { create(:group, :public) }
before do
- allow_any_instance_of(described_class).to receive(:update_group_attributes).and_raise(Gitlab::UpdatePathError, 'namespace directory cannot be moved')
+ allow_next_instance_of(described_class) do |instance|
+ allow(instance).to receive(:update_group_attributes).and_raise(Gitlab::UpdatePathError, 'namespace directory cannot be moved')
+ end
create(:group_member, :owner, group: new_parent_group, user: user)
end
diff --git a/spec/services/issues/import_csv_service_spec.rb b/spec/services/issues/import_csv_service_spec.rb
index 516a1137319..e7370407d4c 100644
--- a/spec/services/issues/import_csv_service_spec.rb
+++ b/spec/services/issues/import_csv_service_spec.rb
@@ -18,7 +18,9 @@ describe Issues::ImportCsvService do
let(:file) { fixture_file_upload('spec/fixtures/banana_sample.gif') }
it 'returns invalid file error' do
- expect_any_instance_of(Notify).to receive(:import_issues_csv_email)
+ expect_next_instance_of(Notify) do |instance|
+ expect(instance).to receive(:import_issues_csv_email)
+ end
expect(subject[:success]).to eq(0)
expect(subject[:parse_error]).to eq(true)
@@ -29,7 +31,9 @@ describe Issues::ImportCsvService do
let(:file) { fixture_file_upload('spec/fixtures/csv_comma.csv') }
it 'imports CSV without errors' do
- expect_any_instance_of(Notify).to receive(:import_issues_csv_email)
+ expect_next_instance_of(Notify) do |instance|
+ expect(instance).to receive(:import_issues_csv_email)
+ end
expect(subject[:success]).to eq(3)
expect(subject[:error_lines]).to eq([])
@@ -41,7 +45,9 @@ describe Issues::ImportCsvService do
let(:file) { fixture_file_upload('spec/fixtures/csv_tab.csv') }
it 'imports CSV with some error rows' do
- expect_any_instance_of(Notify).to receive(:import_issues_csv_email)
+ expect_next_instance_of(Notify) do |instance|
+ expect(instance).to receive(:import_issues_csv_email)
+ end
expect(subject[:success]).to eq(2)
expect(subject[:error_lines]).to eq([3])
@@ -53,7 +59,9 @@ describe Issues::ImportCsvService do
let(:file) { fixture_file_upload('spec/fixtures/csv_semicolon.csv') }
it 'imports CSV with a blank row' do
- expect_any_instance_of(Notify).to receive(:import_issues_csv_email)
+ expect_next_instance_of(Notify) do |instance|
+ expect(instance).to receive(:import_issues_csv_email)
+ end
expect(subject[:success]).to eq(3)
expect(subject[:error_lines]).to eq([4])
diff --git a/spec/services/issues/move_service_spec.rb b/spec/services/issues/move_service_spec.rb
index e39af7bbb72..ee809aabac0 100644
--- a/spec/services/issues/move_service_spec.rb
+++ b/spec/services/issues/move_service_spec.rb
@@ -131,7 +131,9 @@ describe Issues::MoveService do
let!(:hook) { create(:project_hook, project: old_project, issues_events: true) }
it 'executes project issue hooks' do
- allow_any_instance_of(WebHookService).to receive(:execute)
+ allow_next_instance_of(WebHookService) do |instance|
+ allow(instance).to receive(:execute)
+ end
# Ideally, we'd test that `WebHookWorker.jobs.size` increased by 1,
# but since the entire spec run takes place in a transaction, we never
diff --git a/spec/services/lfs/lock_file_service_spec.rb b/spec/services/lfs/lock_file_service_spec.rb
index 15dbc3231a3..2bd62b96083 100644
--- a/spec/services/lfs/lock_file_service_spec.rb
+++ b/spec/services/lfs/lock_file_service_spec.rb
@@ -54,7 +54,9 @@ describe Lfs::LockFileService do
context 'when an error is raised' do
it "doesn't succeed" do
- allow_any_instance_of(described_class).to receive(:create_lock!).and_raise(StandardError)
+ allow_next_instance_of(described_class) do |instance|
+ allow(instance).to receive(:create_lock!).and_raise(StandardError)
+ end
expect(subject.execute[:status]).to eq(:error)
end
diff --git a/spec/services/lfs/locks_finder_service_spec.rb b/spec/services/lfs/locks_finder_service_spec.rb
index 0fc2c593d94..fdc60e2c03f 100644
--- a/spec/services/lfs/locks_finder_service_spec.rb
+++ b/spec/services/lfs/locks_finder_service_spec.rb
@@ -91,7 +91,9 @@ describe Lfs::LocksFinderService do
context 'when an error is raised' do
it "doesn't succeed" do
- allow_any_instance_of(described_class).to receive(:find_locks).and_raise(StandardError)
+ allow_next_instance_of(described_class) do |instance|
+ allow(instance).to receive(:find_locks).and_raise(StandardError)
+ end
result = subject.execute
diff --git a/spec/services/merge_requests/create_pipeline_service_spec.rb b/spec/services/merge_requests/create_pipeline_service_spec.rb
index 576e8498e4d..25f5c54a413 100644
--- a/spec/services/merge_requests/create_pipeline_service_spec.rb
+++ b/spec/services/merge_requests/create_pipeline_service_spec.rb
@@ -62,13 +62,65 @@ describe MergeRequests::CreatePipelineService do
end
end
- context 'when .gitlab-ci.yml does not have only: [merge_requests] keyword' do
- let(:config) do
- { rspec: { script: 'echo' } }
+ context 'when .gitlab-ci.yml does not use workflow:rules' do
+ context 'without only: [merge_requests] keyword' do
+ let(:config) do
+ { rspec: { script: 'echo' } }
+ end
+
+ it 'does not create a pipeline' do
+ expect { subject }.not_to change { Ci::Pipeline.count }
+ end
+ end
+
+ context 'with rules that specify creation on a tag' do
+ let(:config) do
+ {
+ rspec: {
+ script: 'echo',
+ rules: [{ if: '$CI_COMMIT_TAG' }]
+ }
+ }
+ end
+
+ it 'does not create a pipeline' do
+ expect { subject }.not_to change { Ci::Pipeline.count }
+ end
+ end
+ end
+
+ context 'when workflow:rules are specified' do
+ context 'when rules request creation on merge request' do
+ let(:config) do
+ {
+ workflow: {
+ rules: [{ if: '$CI_MERGE_REQUEST_ID' }]
+ },
+ rspec: { script: 'echo' }
+ }
+ end
+
+ it 'creates a detached merge request pipeline' do
+ expect { subject }.to change { Ci::Pipeline.count }.by(1)
+
+ expect(subject).to be_persisted
+ expect(subject).to be_detached_merge_request_pipeline
+ end
end
- it 'does not create a pipeline' do
- expect { subject }.not_to change { Ci::Pipeline.count }
+ context 'with rules do specify creation on a tag' do
+ let(:config) do
+ {
+ workflow: {
+ rules: [{ if: '$CI_COMMIT_TAG' }]
+ },
+ rspec: { script: 'echo' }
+ }
+ end
+
+ it 'does not create a pipeline' do
+ expect { subject }.not_to change { Ci::Pipeline.count }
+ end
end
end
end
diff --git a/spec/services/projects/fork_service_spec.rb b/spec/services/projects/fork_service_spec.rb
index 5a3796fec3d..fc01c93b5cf 100644
--- a/spec/services/projects/fork_service_spec.rb
+++ b/spec/services/projects/fork_service_spec.rb
@@ -6,6 +6,16 @@ describe Projects::ForkService do
include ProjectForksHelper
include Gitlab::ShellAdapter
+ shared_examples 'forks count cache refresh' do
+ it 'flushes the forks count cache of the source project', :clean_gitlab_redis_cache do
+ expect(from_project.forks_count).to be_zero
+
+ fork_project(from_project, to_user)
+
+ expect(from_project.forks_count).to eq(1)
+ end
+ end
+
context 'when forking a new project' do
describe 'fork by user' do
before do
@@ -40,6 +50,11 @@ describe Projects::ForkService do
end
end
+ it_behaves_like 'forks count cache refresh' do
+ let(:from_project) { @from_project }
+ let(:to_user) { @to_user }
+ end
+
describe "successfully creates project in the user namespace" do
let(:to_project) { fork_project(@from_project, @to_user, namespace: @to_user.namespace) }
@@ -62,12 +77,9 @@ describe Projects::ForkService do
expect(@from_project.avatar.file).to be_exists
end
- it 'flushes the forks count cache of the source project' do
- expect(@from_project.forks_count).to be_zero
-
- fork_project(@from_project, @to_user)
-
- expect(@from_project.forks_count).to eq(1)
+ it_behaves_like 'forks count cache refresh' do
+ let(:from_project) { @from_project }
+ let(:to_user) { @to_user }
end
it 'creates a fork network with the new project and the root project set' do
@@ -102,6 +114,11 @@ describe Projects::ForkService do
it 'sets the forked_from_project on the membership' do
expect(to_project.fork_network_member.forked_from_project).to eq(from_forked_project)
end
+
+ it_behaves_like 'forks count cache refresh' do
+ let(:from_project) { from_forked_project }
+ let(:to_user) { @to_user }
+ end
end
end
diff --git a/spec/services/system_note_service_spec.rb b/spec/services/system_note_service_spec.rb
index bb457217b3f..a952e26e338 100644
--- a/spec/services/system_note_service_spec.rb
+++ b/spec/services/system_note_service_spec.rb
@@ -467,7 +467,9 @@ describe SystemNoteService do
before do
allow(JIRA::Resource::Remotelink).to receive(:all).and_return([])
message = "[#{author.name}|http://localhost/#{author.username}] mentioned this issue in [a commit of #{project.full_path}|http://localhost/#{project.full_path}/commit/#{commit.id}]:\n'#{commit.title.chomp}'"
- allow_any_instance_of(JIRA::Resource::Issue).to receive(:comments).and_return([OpenStruct.new(body: message)])
+ allow_next_instance_of(JIRA::Resource::Issue) do |instance|
+ allow(instance).to receive(:comments).and_return([OpenStruct.new(body: message)])
+ end
end
it "does not return success message" do
diff --git a/spec/support/shared_examples/mail_room_shared_examples.rb b/spec/support/shared_examples/mail_room_shared_examples.rb
new file mode 100644
index 00000000000..4cca29250e2
--- /dev/null
+++ b/spec/support/shared_examples/mail_room_shared_examples.rb
@@ -0,0 +1,35 @@
+# frozen_string_literal: true
+
+shared_examples_for 'only truthy if both enabled and address are truthy' do |target_proc|
+ context 'with both enabled and address as truthy values' do
+ it 'is truthy' do
+ stub_config(enabled: true, address: 'localhost')
+
+ expect(target_proc.call).to be_truthy
+ end
+ end
+
+ context 'with address only as truthy' do
+ it 'is falsey' do
+ stub_config(enabled: false, address: 'localhost')
+
+ expect(target_proc.call).to be_falsey
+ end
+ end
+
+ context 'with enabled only as truthy' do
+ it 'is falsey' do
+ stub_config(enabled: true, address: nil)
+
+ expect(target_proc.call).to be_falsey
+ end
+ end
+
+ context 'with neither address nor enabled as truthy' do
+ it 'is falsey' do
+ stub_config(enabled: false, address: nil)
+
+ expect(target_proc.call).to be_falsey
+ end
+ end
+end
diff --git a/spec/support/shared_examples/services/base_helm_service_shared_examples.rb b/spec/support/shared_examples/services/base_helm_service_shared_examples.rb
index f867cb69cfd..19f5334b4b2 100644
--- a/spec/support/shared_examples/services/base_helm_service_shared_examples.rb
+++ b/spec/support/shared_examples/services/base_helm_service_shared_examples.rb
@@ -12,7 +12,7 @@ shared_examples 'logs kubernetes errors' do
end
it 'logs into kubernetes.log and Sentry' do
- expect(Gitlab::Sentry).to receive(:track_exception).with(
+ expect(Gitlab::ErrorTracking).to receive(:track_exception).with(
error,
hash_including(error_hash)
)
diff --git a/spec/workers/ci/archive_traces_cron_worker_spec.rb b/spec/workers/ci/archive_traces_cron_worker_spec.rb
index 291fe54c4e3..fc700c15b10 100644
--- a/spec/workers/ci/archive_traces_cron_worker_spec.rb
+++ b/spec/workers/ci/archive_traces_cron_worker_spec.rb
@@ -63,7 +63,7 @@ describe Ci::ArchiveTracesCronWorker do
let!(:build) { create(:ci_build, :success, :trace_live, finished_at: finished_at) }
before do
- allow(Gitlab::Sentry).to receive(:track_and_raise_for_dev_exception)
+ allow(Gitlab::ErrorTracking).to receive(:track_and_raise_for_dev_exception)
allow_any_instance_of(Gitlab::Ci::Trace).to receive(:archive!).and_raise('Unexpected error')
end
diff --git a/spec/workers/run_pipeline_schedule_worker_spec.rb b/spec/workers/run_pipeline_schedule_worker_spec.rb
index 1d376e1f02a..14364194b44 100644
--- a/spec/workers/run_pipeline_schedule_worker_spec.rb
+++ b/spec/workers/run_pipeline_schedule_worker_spec.rb
@@ -42,7 +42,7 @@ describe RunPipelineScheduleWorker do
before do
allow(Ci::CreatePipelineService).to receive(:new) { raise ActiveRecord::StatementInvalid }
- expect(Gitlab::Sentry)
+ expect(Gitlab::ErrorTracking)
.to receive(:track_and_raise_for_dev_exception)
.with(ActiveRecord::StatementInvalid,
issue_url: 'https://gitlab.com/gitlab-org/gitlab-foss/issues/41231',
diff --git a/spec/workers/stuck_ci_jobs_worker_spec.rb b/spec/workers/stuck_ci_jobs_worker_spec.rb
index 48a20f498b7..c994a5dcb78 100644
--- a/spec/workers/stuck_ci_jobs_worker_spec.rb
+++ b/spec/workers/stuck_ci_jobs_worker_spec.rb
@@ -30,7 +30,7 @@ describe StuckCiJobsWorker do
it "does drop the job and logs the reason" do
job.update_columns(yaml_variables: '[{"key" => "value"}]')
- expect(Gitlab::Sentry).to receive(:track_exception)
+ expect(Gitlab::ErrorTracking).to receive(:track_exception)
.with(anything, a_hash_including(build_id: job.id))
.once
.and_call_original