diff options
Diffstat (limited to 'spec')
6 files changed, 63 insertions, 54 deletions
diff --git a/spec/factories/protected_branches.rb b/spec/factories/protected_branches.rb index 2d3abc77350..bac1cf21596 100644 --- a/spec/factories/protected_branches.rb +++ b/spec/factories/protected_branches.rb @@ -2,7 +2,7 @@ FactoryBot.define do factory :protected_branch do - name + sequence(:name) { |n| "protected_branch_#{n}" } project transient do @@ -11,6 +11,20 @@ FactoryBot.define do default_access_level { true } end + trait :create_branch_on_repository do + association :project, factory: [:project, :repository] + + transient do + repository_branch_name { name } + end + + after(:create) do |protected_branch, evaluator| + project = protected_branch.project + + project.repository.create_branch(evaluator.repository_branch_name, project.default_branch_or_main) + end + end + trait :developers_can_push do transient do default_push_level { false } diff --git a/spec/lib/gitlab/database/partitioning/sliding_list_strategy_spec.rb b/spec/lib/gitlab/database/partitioning/sliding_list_strategy_spec.rb index 73474e8b38a..636a09e5710 100644 --- a/spec/lib/gitlab/database/partitioning/sliding_list_strategy_spec.rb +++ b/spec/lib/gitlab/database/partitioning/sliding_list_strategy_spec.rb @@ -37,8 +37,8 @@ RSpec.describe Gitlab::Database::Partitioning::SlidingListStrategy do describe '#current_partitions' do it 'detects both partitions' do expect(strategy.current_partitions).to eq([ - Gitlab::Database::Partitioning::SingleNumericListPartition.new(table_name, 1, partition_name: '_test_partitioned_test_1'), - Gitlab::Database::Partitioning::SingleNumericListPartition.new(table_name, 2, partition_name: '_test_partitioned_test_2') + Gitlab::Database::Partitioning::SingleNumericListPartition.new(table_name, 1, partition_name: '_test_partitioned_test_1'), + Gitlab::Database::Partitioning::SingleNumericListPartition.new(table_name, 2, partition_name: '_test_partitioned_test_2') ]) end end diff --git a/spec/lib/gitlab/import/import_failure_service_spec.rb b/spec/lib/gitlab/import/import_failure_service_spec.rb index c16d4a7c804..e3fec63adde 100644 --- a/spec/lib/gitlab/import/import_failure_service_spec.rb +++ b/spec/lib/gitlab/import/import_failure_service_spec.rb @@ -7,58 +7,48 @@ RSpec.describe Gitlab::Import::ImportFailureService, :aggregate_failures do let_it_be(:project) { create(:project, :import_started, import_type: import_type) } let(:exception) { StandardError.new('some error') } - let(:arguments) { { project_id: project.id } } - let(:base_arguments) { { error_source: 'SomeImporter', exception: exception }.merge(arguments) } - let(:exe_arguments) { { fail_import: false, metrics: false } } + let(:import_state) { nil } + let(:fail_import) { false } + let(:metrics) { false } + + let(:arguments) do + { + project_id: project.id, + error_source: 'SomeImporter', + exception: exception, + fail_import: fail_import, + metrics: metrics, + import_state: import_state + } + end describe '.track' do + let(:instance) { double(:failure_service) } + context 'with all arguments provided' do - let(:instance) { double(:failure_service) } - let(:instance_arguments) do + let(:arguments) do { exception: exception, import_state: '_import_state_', project_id: '_project_id_', - error_source: '_error_source_' - } - end - - let(:exe_arguments) do - { + error_source: '_error_source_', fail_import: '_fail_import_', metrics: '_metrics_' } end it 'invokes a new instance and executes' do - expect(described_class).to receive(:new).with(**instance_arguments).and_return(instance) - expect(instance).to receive(:execute).with(**exe_arguments) + expect(described_class).to receive(:new).with(**arguments).and_return(instance) + expect(instance).to receive(:execute) - described_class.track(**instance_arguments.merge(exe_arguments)) + described_class.track(**arguments) end end context 'with only necessary arguments utilizing defaults' do - let(:instance) { double(:failure_service) } - let(:instance_arguments) do - { - exception: exception, - import_state: nil, - project_id: nil, - error_source: nil - } - end - - let(:exe_arguments) do - { - fail_import: false, - metrics: false - } - end - it 'invokes a new instance and executes' do - expect(described_class).to receive(:new).with(**instance_arguments).and_return(instance) - expect(instance).to receive(:execute).with(**exe_arguments) + expect(described_class).to receive(:new).with(a_hash_including(exception: exception)).and_return(instance) + expect(instance).to receive(:execute) described_class.track(exception: exception) end @@ -66,7 +56,7 @@ RSpec.describe Gitlab::Import::ImportFailureService, :aggregate_failures do end describe '#execute' do - subject(:service) { described_class.new(**base_arguments) } + subject(:service) { described_class.new(**arguments) } shared_examples 'logs the exception and fails the import' do it 'when the failure does not abort the import' do @@ -89,13 +79,14 @@ RSpec.describe Gitlab::Import::ImportFailureService, :aggregate_failures do source: 'SomeImporter' ) - service.execute(**exe_arguments) + service.execute expect(project.import_state.reload.status).to eq('failed') expect(project.import_failures).not_to be_empty expect(project.import_failures.last.exception_class).to eq('StandardError') expect(project.import_failures.last.exception_message).to eq('some error') + expect(project.import_failures.last.retry_count).to eq(0) end end @@ -120,32 +111,36 @@ RSpec.describe Gitlab::Import::ImportFailureService, :aggregate_failures do source: 'SomeImporter' ) - service.execute(**exe_arguments) + service.execute expect(project.import_state.reload.status).to eq('started') expect(project.import_failures).not_to be_empty expect(project.import_failures.last.exception_class).to eq('StandardError') expect(project.import_failures.last.exception_message).to eq('some error') + expect(project.import_failures.last.retry_count).to eq(nil) end end context 'when tracking metrics' do - let(:exe_arguments) { { fail_import: false, metrics: true } } + let(:metrics) { true } it 'tracks the failed import' do - metrics = double(:metrics) + metrics_double = double(:metrics) - expect(Gitlab::Import::Metrics).to receive(:new).with("#{project.import_type}_importer", project).and_return(metrics) - expect(metrics).to receive(:track_failed_import) + expect(Gitlab::Import::Metrics) + .to receive(:new) + .with("#{project.import_type}_importer", project) + .and_return(metrics_double) + expect(metrics_double).to receive(:track_failed_import) - service.execute(**exe_arguments) + service.execute end end context 'when using the project as reference' do context 'when it fails the import' do - let(:exe_arguments) { { fail_import: true, metrics: false } } + let(:fail_import) { true } it_behaves_like 'logs the exception and fails the import' end @@ -156,10 +151,10 @@ RSpec.describe Gitlab::Import::ImportFailureService, :aggregate_failures do end context 'when using the import_state as reference' do - let(:arguments) { { import_state: project.import_state } } + let(:import_state) { project.import_state } context 'when it fails the import' do - let(:exe_arguments) { { fail_import: true, metrics: false } } + let(:fail_import) { true } it_behaves_like 'logs the exception and fails the import' end diff --git a/spec/models/integrations/microsoft_teams_spec.rb b/spec/models/integrations/microsoft_teams_spec.rb index 21b9a005746..033432f31a0 100644 --- a/spec/models/integrations/microsoft_teams_spec.rb +++ b/spec/models/integrations/microsoft_teams_spec.rb @@ -304,7 +304,7 @@ RSpec.describe Integrations::MicrosoftTeams do context 'with protected branch' do before do - create(:protected_branch, project: project, name: 'a-protected-branch') + create(:protected_branch, :create_branch_on_repository, project: project, name: 'a-protected-branch') end let(:pipeline) do diff --git a/spec/support/shared_examples/models/chat_integration_shared_examples.rb b/spec/support/shared_examples/models/chat_integration_shared_examples.rb index 72659dd5f3b..9ae727a87de 100644 --- a/spec/support/shared_examples/models/chat_integration_shared_examples.rb +++ b/spec/support/shared_examples/models/chat_integration_shared_examples.rb @@ -113,7 +113,7 @@ RSpec.shared_examples "chat integration" do |integration_name| context "with protected branch" do before do - create(:protected_branch, project: project, name: "a-protected-branch") + create(:protected_branch, :create_branch_on_repository, project: project, name: "a-protected-branch") end let(:sample_data) do @@ -309,7 +309,7 @@ RSpec.shared_examples "chat integration" do |integration_name| context "with protected branch" do before do - create(:protected_branch, project: project, name: "a-protected-branch") + create(:protected_branch, :create_branch_on_repository, project: project, name: "a-protected-branch") end let(:sample_data) do diff --git a/spec/support/shared_examples/models/concerns/integrations/slack_mattermost_notifier_shared_examples.rb b/spec/support/shared_examples/models/concerns/integrations/slack_mattermost_notifier_shared_examples.rb index 2d4c0b60f2b..ad15f82be5e 100644 --- a/spec/support/shared_examples/models/concerns/integrations/slack_mattermost_notifier_shared_examples.rb +++ b/spec/support/shared_examples/models/concerns/integrations/slack_mattermost_notifier_shared_examples.rb @@ -305,7 +305,7 @@ RSpec.shared_examples Integrations::SlackMattermostNotifier do |service_name| context 'on a protected branch' do before do - create(:protected_branch, project: project, name: 'a-protected-branch') + create(:protected_branch, :create_branch_on_repository, project: project, name: 'a-protected-branch') end let(:data) do @@ -347,7 +347,7 @@ RSpec.shared_examples Integrations::SlackMattermostNotifier do |service_name| context 'on a protected branch with protected branches defined using wildcards' do before do - create(:protected_branch, project: project, name: '*-stable') + create(:protected_branch, :create_branch_on_repository, repository_branch_name: '1-stable', project: project, name: '*-stable') end let(:data) do @@ -560,7 +560,7 @@ RSpec.shared_examples Integrations::SlackMattermostNotifier do |service_name| context 'on a protected branch' do before do - create(:protected_branch, project: project, name: 'a-protected-branch') + create(:protected_branch, :create_branch_on_repository, project: project, name: 'a-protected-branch') end let(:pipeline) do @@ -590,7 +590,7 @@ RSpec.shared_examples Integrations::SlackMattermostNotifier do |service_name| context 'on a protected branch with protected branches defined usin wildcards' do before do - create(:protected_branch, project: project, name: '*-stable') + create(:protected_branch, :create_branch_on_repository, repository_branch_name: '1-stable', project: project, name: '*-stable') end let(:pipeline) do |