diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-08-24 00:10:34 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-08-24 00:10:34 +0300 |
commit | de5fc582771ba7e2dc6e1c783ce8ee417fbe6788 (patch) | |
tree | 3376365943e60af4b8d670f2f9d8dbfd8ae572e2 /spec | |
parent | 0eb05ee0ea5d4e88a1cae604f7ff92507f16d4b0 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
-rw-r--r-- | spec/controllers/admin/application_settings_controller_spec.rb | 11 | ||||
-rw-r--r-- | spec/helpers/projects/pipeline_helper_spec.rb | 2 | ||||
-rw-r--r-- | spec/lib/gitlab/auth/o_auth/provider_spec.rb | 18 | ||||
-rw-r--r-- | spec/lib/gitlab/background_migration/rename_task_system_note_to_checklist_item_spec.rb | 91 | ||||
-rw-r--r-- | spec/migrations/change_task_system_note_wording_to_checklist_item_spec.rb | 32 | ||||
-rw-r--r-- | spec/models/ci/build_spec.rb | 14 | ||||
-rw-r--r-- | spec/models/ci/job_artifact_spec.rb | 108 | ||||
-rw-r--r-- | spec/models/ci/pipeline_spec.rb | 18 | ||||
-rw-r--r-- | spec/models/issue_spec.rb | 16 | ||||
-rw-r--r-- | spec/services/ci/pipelines/hook_service_spec.rb | 2 | ||||
-rw-r--r-- | spec/workers/every_sidekiq_worker_spec.rb | 1 |
11 files changed, 226 insertions, 87 deletions
diff --git a/spec/controllers/admin/application_settings_controller_spec.rb b/spec/controllers/admin/application_settings_controller_spec.rb index e02589ddc83..cb25011fd96 100644 --- a/spec/controllers/admin/application_settings_controller_spec.rb +++ b/spec/controllers/admin/application_settings_controller_spec.rb @@ -362,6 +362,17 @@ RSpec.describe Admin::ApplicationSettingsController, :do_not_mock_admin_mode_set expect(application_settings.reload.pipeline_limit_per_project_user_sha).to eq(25) end end + + context 'invitation flow enforcement setting' do + let(:application_settings) { ApplicationSetting.current } + + it 'updates invitation_flow_enforcement setting' do + put :update, params: { application_setting: { invitation_flow_enforcement: true } } + + expect(response).to redirect_to(general_admin_application_settings_path) + expect(application_settings.reload.invitation_flow_enforcement).to eq(true) + end + end end describe 'PUT #reset_registration_token' do diff --git a/spec/helpers/projects/pipeline_helper_spec.rb b/spec/helpers/projects/pipeline_helper_spec.rb index 8ce4e9f5293..1231dcef693 100644 --- a/spec/helpers/projects/pipeline_helper_spec.rb +++ b/spec/helpers/projects/pipeline_helper_spec.rb @@ -31,7 +31,7 @@ RSpec.describe Projects::PipelineHelper do summary_endpoint: summary_project_pipeline_tests_path(project, pipeline, format: :json), suite_endpoint: project_pipeline_test_path(project, pipeline, suite_name: 'suite', format: :json), blob_path: project_blob_path(project, pipeline.sha), - has_test_report: pipeline.has_reports?(Ci::JobArtifact.test_reports), + has_test_report: pipeline.has_reports?(Ci::JobArtifact.of_report_type(:test)), empty_state_image_path: match_asset_path('illustrations/empty-state/empty-test-cases-lg.svg'), artifacts_expired_image_path: match_asset_path('illustrations/pipeline.svg') }) diff --git a/spec/lib/gitlab/auth/o_auth/provider_spec.rb b/spec/lib/gitlab/auth/o_auth/provider_spec.rb index c1b96819176..96a31c50989 100644 --- a/spec/lib/gitlab/auth/o_auth/provider_spec.rb +++ b/spec/lib/gitlab/auth/o_auth/provider_spec.rb @@ -90,6 +90,24 @@ RSpec.describe Gitlab::Auth::OAuth::Provider do end end end + + context 'for an OpenID Connect provider' do + before do + provider = ActiveSupport::InheritableOptions.new( + name: 'openid_connect', + args: ActiveSupport::InheritableOptions.new(name: 'custom_oidc') + ) + allow(Gitlab.config.omniauth).to receive(:providers).and_return([provider]) + end + + context 'when the provider exists' do + subject { described_class.config_for('custom_oidc') } + + it 'returns the config' do + expect(subject).to be_a(ActiveSupport::InheritableOptions) + end + end + end end describe '.label_for' do diff --git a/spec/lib/gitlab/background_migration/rename_task_system_note_to_checklist_item_spec.rb b/spec/lib/gitlab/background_migration/rename_task_system_note_to_checklist_item_spec.rb new file mode 100644 index 00000000000..6996249cb40 --- /dev/null +++ b/spec/lib/gitlab/background_migration/rename_task_system_note_to_checklist_item_spec.rb @@ -0,0 +1,91 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Gitlab::BackgroundMigration::RenameTaskSystemNoteToChecklistItem do + let(:notes) { table(:notes) } + let(:projects) { table(:projects) } + + let(:namespace) { table(:namespaces).create!(name: 'batchtest1', type: 'Group', path: 'space1') } + let(:project) { table(:projects).create!(name: 'proj1', path: 'proj1', namespace_id: namespace.id) } + let(:issue) { table(:issues).create!(title: 'Test issue') } + + let!(:note1) do + notes.create!( + note: 'marked the task **Task 1** as complete', noteable_type: 'Issue', noteable_id: issue.id, system: true + ) + end + + let!(:note2) do + notes.create!( + note: 'NO_MATCH marked the task **Task 2** as complete', + noteable_type: 'Issue', + noteable_id: issue.id, + system: true + ) + end + + let!(:note3) do + notes.create!( + note: 'marked the task **Task 3** as incomplete', + noteable_type: 'Issue', + noteable_id: issue.id, + system: true + ) + end + + let!(:note4) do + notes.create!( + note: 'marked the task **Task 4** as incomplete', + noteable_type: 'Issue', + noteable_id: issue.id, + system: true + ) + end + + let!(:metadata1) { table(:system_note_metadata).create!(note_id: note1.id, action: :task) } + let!(:metadata2) { table(:system_note_metadata).create!(note_id: note2.id, action: :task) } + let!(:metadata3) { table(:system_note_metadata).create!(note_id: note3.id, action: :task) } + let!(:metadata4) { table(:system_note_metadata).create!(note_id: note4.id, action: :not_task) } + + let(:migration) do + described_class.new( + start_id: note1.id, + end_id: note4.id, + batch_table: :system_note_metadata, + batch_column: :id, + sub_batch_size: 2, + pause_ms: 2, + connection: ApplicationRecord.connection + ) + end + + subject(:perform_migration) { migration.perform } + + it 'renames task to checklist item in task system notes that match', :aggregate_failures do + expect do + perform_migration + + note1.reload + note2.reload + note3.reload + note4.reload + end.to change(note1, :note).to('marked the checklist item **Task 1** as complete').and( + not_change(note2, :note).from('NO_MATCH marked the task **Task 2** as complete') + ).and( + change(note3, :note).to('marked the checklist item **Task 3** as incomplete') + ).and( + not_change(note4, :note).from('marked the task **Task 4** as incomplete') + ) + end + + it 'updates in batches' do + expect { perform_migration }.to make_queries_matching(/UPDATE notes/, 2) + end + + it 'tracks timings of queries' do + expect(migration.batch_metrics.timings).to be_empty + + expect { perform_migration }.to change { migration.batch_metrics.timings } + end +end diff --git a/spec/migrations/change_task_system_note_wording_to_checklist_item_spec.rb b/spec/migrations/change_task_system_note_wording_to_checklist_item_spec.rb new file mode 100644 index 00000000000..039ee92f8bd --- /dev/null +++ b/spec/migrations/change_task_system_note_wording_to_checklist_item_spec.rb @@ -0,0 +1,32 @@ +# frozen_string_literal: true + +require 'spec_helper' +require_migration! + +RSpec.describe ChangeTaskSystemNoteWordingToChecklistItem, :migration do + let(:migration) { described_class::MIGRATION } + + describe '#up' do + it 'schedules a batched background migration' do + migrate! + + expect(migration).to have_scheduled_batched_migration( + table_name: :system_note_metadata, + column_name: :id, + interval: described_class::DELAY_INTERVAL, + batch_size: described_class::BATCH_SIZE, + max_batch_size: described_class::MAX_BATCH_SIZE, + sub_batch_size: described_class::SUB_BATCH_SIZE + ) + end + end + + describe '#down' do + it 'deletes all batched migration records' do + migrate! + schema_migrate_down! + + expect(migration).not_to have_scheduled_batched_migration + end + end +end diff --git a/spec/models/ci/build_spec.rb b/spec/models/ci/build_spec.rb index 948e16a9b3c..960bde3ec93 100644 --- a/spec/models/ci/build_spec.rb +++ b/spec/models/ci/build_spec.rb @@ -1345,13 +1345,12 @@ RSpec.describe Ci::Build do subject { build.send(event) } - where(:ff_enabled, :state, :report_count, :trait) do - true | :success! | 1 | :sast - true | :cancel! | 1 | :sast - true | :drop! | 2 | :multiple_report_artifacts - true | :success! | 0 | :allowed_to_fail - true | :skip! | 0 | :pending - false | :success! | 0 | :sast + where(:state, :report_count, :trait) do + :success! | 1 | :sast + :cancel! | 1 | :sast + :drop! | 2 | :multiple_report_artifacts + :success! | 0 | :allowed_to_fail + :skip! | 0 | :pending end with_them do @@ -1361,7 +1360,6 @@ RSpec.describe Ci::Build do context "when transitioning to #{params[:state]}" do before do allow(Gitlab).to receive(:com?).and_return(true) - stub_feature_flags(report_artifact_build_completed_metrics_on_build_completion: ff_enabled) end it 'increments build_completed_report_type metric' do diff --git a/spec/models/ci/job_artifact_spec.rb b/spec/models/ci/job_artifact_spec.rb index b996bf84529..f31edb747bd 100644 --- a/spec/models/ci/job_artifact_spec.rb +++ b/spec/models/ci/job_artifact_spec.rb @@ -48,82 +48,86 @@ RSpec.describe Ci::JobArtifact do end end - describe '.test_reports' do - subject { described_class.test_reports } + describe '.of_report_type' do + subject { described_class.of_report_type(report_type) } - context 'when there is a test report' do - let!(:artifact) { create(:ci_job_artifact, :junit) } + describe 'test_reports' do + let(:report_type) { :test } - it { is_expected.to eq([artifact]) } - end + context 'when there is a test report' do + let!(:artifact) { create(:ci_job_artifact, :junit) } + + it { is_expected.to eq([artifact]) } + end - context 'when there are no test reports' do - let!(:artifact) { create(:ci_job_artifact, :archive) } + context 'when there are no test reports' do + let!(:artifact) { create(:ci_job_artifact, :archive) } - it { is_expected.to be_empty } + it { is_expected.to be_empty } + end end - end - describe '.accessibility_reports' do - subject { described_class.accessibility_reports } + describe 'accessibility_reports' do + let(:report_type) { :accessibility } - context 'when there is an accessibility report' do - let(:artifact) { create(:ci_job_artifact, :accessibility) } + context 'when there is an accessibility report' do + let(:artifact) { create(:ci_job_artifact, :accessibility) } - it { is_expected.to eq([artifact]) } - end + it { is_expected.to eq([artifact]) } + end - context 'when there are no accessibility report' do - let(:artifact) { create(:ci_job_artifact, :archive) } + context 'when there are no accessibility report' do + let(:artifact) { create(:ci_job_artifact, :archive) } - it { is_expected.to be_empty } + it { is_expected.to be_empty } + end end - end - describe '.coverage_reports' do - subject { described_class.coverage_reports } + describe 'coverage_reports' do + let(:report_type) { :coverage } - context 'when there is a coverage report' do - let!(:artifact) { create(:ci_job_artifact, :cobertura) } + context 'when there is a coverage report' do + let!(:artifact) { create(:ci_job_artifact, :cobertura) } - it { is_expected.to eq([artifact]) } - end + it { is_expected.to eq([artifact]) } + end - context 'when there are no coverage reports' do - let!(:artifact) { create(:ci_job_artifact, :archive) } + context 'when there are no coverage reports' do + let!(:artifact) { create(:ci_job_artifact, :archive) } - it { is_expected.to be_empty } + it { is_expected.to be_empty } + end end - end - describe '.codequality_reports' do - subject { described_class.codequality_reports } + describe 'codequality_reports' do + let(:report_type) { :codequality } - context 'when there is a codequality report' do - let!(:artifact) { create(:ci_job_artifact, :codequality) } + context 'when there is a codequality report' do + let!(:artifact) { create(:ci_job_artifact, :codequality) } - it { is_expected.to eq([artifact]) } - end + it { is_expected.to eq([artifact]) } + end - context 'when there are no codequality reports' do - let!(:artifact) { create(:ci_job_artifact, :archive) } + context 'when there are no codequality reports' do + let!(:artifact) { create(:ci_job_artifact, :archive) } - it { is_expected.to be_empty } + it { is_expected.to be_empty } + end end - end - describe '.terraform_reports' do - context 'when there is a terraform report' do - it 'return the job artifact' do - artifact = create(:ci_job_artifact, :terraform) + describe 'terraform_reports' do + let(:report_type) { :terraform } - expect(described_class.terraform_reports).to eq([artifact]) + context 'when there is a terraform report' do + let!(:artifact) { create(:ci_job_artifact, :terraform) } + + it { is_expected.to eq([artifact]) } end - end - context 'when there are no terraform reports' do - it 'return the an empty array' do - expect(described_class.terraform_reports).to eq([]) + context 'when there are no terraform reports' do + let!(:artifact) { create(:ci_job_artifact, :archive) } + + it { is_expected.to be_empty } end end end @@ -135,7 +139,7 @@ RSpec.describe Ci::JobArtifact do context 'when given an unrecognized report type' do it 'raises error' do - expect { described_class.file_types_for_report(:blah) }.to raise_error(KeyError, /blah/) + expect { described_class.file_types_for_report(:blah) }.to raise_error(ArgumentError, "Unrecognized report type: blah") end end end @@ -146,8 +150,8 @@ RSpec.describe Ci::JobArtifact do subject { Ci::JobArtifact.associated_file_types_for(file_type) } where(:file_type, :result) do - 'codequality' | %w(codequality) - 'quality' | nil + 'codequality' | %w(codequality) + 'quality' | nil end with_them do diff --git a/spec/models/ci/pipeline_spec.rb b/spec/models/ci/pipeline_spec.rb index 0c28c99c113..e713d0dc068 100644 --- a/spec/models/ci/pipeline_spec.rb +++ b/spec/models/ci/pipeline_spec.rb @@ -686,7 +686,7 @@ RSpec.describe Ci::Pipeline, :mailer, factory_default: :keep do describe '.with_reports' do context 'when pipeline has a test report' do - subject { described_class.with_reports(Ci::JobArtifact.test_reports) } + subject { described_class.with_reports(Ci::JobArtifact.of_report_type(:test)) } let!(:pipeline_with_report) { create(:ci_pipeline, :with_test_reports) } @@ -696,7 +696,7 @@ RSpec.describe Ci::Pipeline, :mailer, factory_default: :keep do end context 'when pipeline has a coverage report' do - subject { described_class.with_reports(Ci::JobArtifact.coverage_reports) } + subject { described_class.with_reports(Ci::JobArtifact.of_report_type(:coverage)) } let!(:pipeline_with_report) { create(:ci_pipeline, :with_coverage_reports) } @@ -706,7 +706,7 @@ RSpec.describe Ci::Pipeline, :mailer, factory_default: :keep do end context 'when pipeline has an accessibility report' do - subject { described_class.with_reports(Ci::JobArtifact.accessibility_reports) } + subject { described_class.with_reports(Ci::JobArtifact.of_report_type(:accessibility)) } let(:pipeline_with_report) { create(:ci_pipeline, :with_accessibility_reports) } @@ -716,7 +716,7 @@ RSpec.describe Ci::Pipeline, :mailer, factory_default: :keep do end context 'when pipeline has a codequality report' do - subject { described_class.with_reports(Ci::JobArtifact.codequality_reports) } + subject { described_class.with_reports(Ci::JobArtifact.of_report_type(:codequality)) } let(:pipeline_with_report) { create(:ci_pipeline, :with_codequality_reports) } @@ -729,14 +729,14 @@ RSpec.describe Ci::Pipeline, :mailer, factory_default: :keep do it 'selects the pipeline' do pipeline_with_report = create(:ci_pipeline, :with_terraform_reports) - expect(described_class.with_reports(Ci::JobArtifact.terraform_reports)).to eq( + expect(described_class.with_reports(Ci::JobArtifact.of_report_type(:terraform))).to eq( [pipeline_with_report] ) end end context 'when pipeline does not have metrics reports' do - subject { described_class.with_reports(Ci::JobArtifact.test_reports) } + subject { described_class.with_reports(Ci::JobArtifact.of_report_type(:test)) } let!(:pipeline_without_report) { create(:ci_empty_pipeline) } @@ -4158,7 +4158,7 @@ RSpec.describe Ci::Pipeline, :mailer, factory_default: :keep do test_build = create(:ci_build, :test_reports, pipeline: pipeline) create(:ci_build, :coverage_reports, pipeline: pipeline) - expect(pipeline.latest_report_builds(Ci::JobArtifact.test_reports)).to contain_exactly(test_build) + expect(pipeline.latest_report_builds(Ci::JobArtifact.of_report_type(:test))).to contain_exactly(test_build) end it 'only returns not retried builds' do @@ -4186,7 +4186,7 @@ RSpec.describe Ci::Pipeline, :mailer, factory_default: :keep do create(:ci_build, :test_reports, pipeline: pipeline) grandchild_build = create(:ci_build, :codequality_reports, pipeline: grandchild_pipeline) - expect(pipeline.latest_report_builds_in_self_and_descendants(Ci::JobArtifact.codequality_reports)).to contain_exactly(grandchild_build) + expect(pipeline.latest_report_builds_in_self_and_descendants(Ci::JobArtifact.of_report_type(:codequality))).to contain_exactly(grandchild_build) end it 'only returns builds that are not retried' do @@ -4198,7 +4198,7 @@ RSpec.describe Ci::Pipeline, :mailer, factory_default: :keep do end describe '#has_reports?' do - subject { pipeline.has_reports?(Ci::JobArtifact.test_reports) } + subject { pipeline.has_reports?(Ci::JobArtifact.of_report_type(:test)) } context 'when pipeline has builds with test reports' do before do diff --git a/spec/models/issue_spec.rb b/spec/models/issue_spec.rb index 5b35fdd1eb9..4ca76ae7dd2 100644 --- a/spec/models/issue_spec.rb +++ b/spec/models/issue_spec.rb @@ -1782,20 +1782,4 @@ RSpec.describe Issue do end end end - - describe '#full_search' do - context 'when searching non-english terms' do - [ - 'abc 中文語', - '中文語cn', - '中文語' - ].each do |term| - it 'adds extra where clause to match partial index' do - expect(described_class.full_search(term).to_sql).to include( - "AND (issues.title NOT SIMILAR TO '[\\u0000-\\u218F]*' OR issues.description NOT SIMILAR TO '[\\u0000-\\u218F]*')" - ) - end - end - end - end end diff --git a/spec/services/ci/pipelines/hook_service_spec.rb b/spec/services/ci/pipelines/hook_service_spec.rb index 0e1ef6afd0d..8d138a3d957 100644 --- a/spec/services/ci/pipelines/hook_service_spec.rb +++ b/spec/services/ci/pipelines/hook_service_spec.rb @@ -6,7 +6,7 @@ RSpec.describe Ci::Pipelines::HookService do describe '#execute_hooks' do let_it_be(:namespace) { create(:namespace) } let_it_be(:project) { create(:project, :repository, namespace: namespace) } - let_it_be(:pipeline) { create(:ci_empty_pipeline, :created, project: project) } + let_it_be(:pipeline, reload: true) { create(:ci_empty_pipeline, :created, project: project) } let(:hook_enabled) { true } let!(:hook) { create(:project_hook, project: project, pipeline_events: hook_enabled) } diff --git a/spec/workers/every_sidekiq_worker_spec.rb b/spec/workers/every_sidekiq_worker_spec.rb index 4a1bf7dbbf9..b9d7998225b 100644 --- a/spec/workers/every_sidekiq_worker_spec.rb +++ b/spec/workers/every_sidekiq_worker_spec.rb @@ -356,6 +356,7 @@ RSpec.describe 'Every Sidekiq worker' do 'ObjectPool::ScheduleJoinWorker' => 3, 'ObjectStorage::BackgroundMoveWorker' => 5, 'ObjectStorage::MigrateUploadsWorker' => 3, + 'Onboarding::CreateLearnGitlabWorker' => 3, 'Packages::CleanupPackageFileWorker' => 0, 'Packages::Cleanup::ExecutePolicyWorker' => 0, 'Packages::Composer::CacheUpdateWorker' => false, |