diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-08-22 18:10:52 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-08-22 18:10:52 +0300 |
commit | b52aefb5996cdd22dc969161d414244a59046e6e (patch) | |
tree | 9b1e3fe92ababfcc3110dca0380727a593220bd4 /spec | |
parent | 4fc46d75644b28789e83c95ec4d1309498bb4ba3 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
17 files changed, 553 insertions, 10 deletions
diff --git a/spec/fixtures/api/schemas/entities/codequality_degradation.json b/spec/fixtures/api/schemas/entities/codequality_degradation.json index ac772873daf..ac1a556e33c 100644 --- a/spec/fixtures/api/schemas/entities/codequality_degradation.json +++ b/spec/fixtures/api/schemas/entities/codequality_degradation.json @@ -10,6 +10,9 @@ "description": { "type": "string" }, + "fingerprint": { + "type": "string" + }, "severity": { "type": "string" }, diff --git a/spec/graphql/types/merge_request_type_spec.rb b/spec/graphql/types/merge_request_type_spec.rb index bd271da55a9..c8545d811fa 100644 --- a/spec/graphql/types/merge_request_type_spec.rb +++ b/spec/graphql/types/merge_request_type_spec.rb @@ -36,7 +36,7 @@ RSpec.describe GitlabSchema.types['MergeRequest'], feature_category: :code_revie commit_count current_user_todos conflicts auto_merge_enabled approved_by source_branch_protected squash_on_merge available_auto_merge_strategies has_ci mergeable commits committers commits_without_merge_commits squash security_auto_fix default_squash_commit_message - auto_merge_strategy merge_user award_emoji prepared_at + auto_merge_strategy merge_user award_emoji prepared_at codequality_reports_comparer ] expect(described_class).to have_graphql_fields(*expected_fields).at_least diff --git a/spec/graphql/types/security/codequality_reports_comparer/degradation_type_spec.rb b/spec/graphql/types/security/codequality_reports_comparer/degradation_type_spec.rb new file mode 100644 index 00000000000..9ae1b3fcf94 --- /dev/null +++ b/spec/graphql/types/security/codequality_reports_comparer/degradation_type_spec.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe GitlabSchema.types['CodequalityReportsComparerReportDegradation'], feature_category: :code_quality do + specify { expect(described_class.graphql_name).to eq('CodequalityReportsComparerReportDegradation') } + + it 'has expected fields' do + expected_fields = %i[description fingerprint severity file_path line web_url engine_name] + + expect(described_class).to have_graphql_fields(*expected_fields) + end +end diff --git a/spec/graphql/types/security/codequality_reports_comparer/report_type_spec.rb b/spec/graphql/types/security/codequality_reports_comparer/report_type_spec.rb new file mode 100644 index 00000000000..a1788126f1b --- /dev/null +++ b/spec/graphql/types/security/codequality_reports_comparer/report_type_spec.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe GitlabSchema.types['CodequalityReportsComparerReport'], feature_category: :code_quality do + specify { expect(described_class.graphql_name).to eq('CodequalityReportsComparerReport') } + + it 'has expected fields' do + expected_fields = %i[status new_errors resolved_errors existing_errors summary] + + expect(described_class).to have_graphql_fields(*expected_fields) + end +end diff --git a/spec/graphql/types/security/codequality_reports_comparer/status_enum_spec.rb b/spec/graphql/types/security/codequality_reports_comparer/status_enum_spec.rb new file mode 100644 index 00000000000..6e5bdd1e91d --- /dev/null +++ b/spec/graphql/types/security/codequality_reports_comparer/status_enum_spec.rb @@ -0,0 +1,11 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe GitlabSchema.types['CodequalityReportsComparerReportStatus'], feature_category: :code_quality do + specify { expect(described_class.graphql_name).to eq('CodequalityReportsComparerReportStatus') } + + it 'exposes all codequality report status values' do + expect(described_class.values.keys).to contain_exactly('SUCCESS', 'FAILED', 'NOT_FOUND') + end +end diff --git a/spec/graphql/types/security/codequality_reports_comparer/summary_type_spec.rb b/spec/graphql/types/security/codequality_reports_comparer/summary_type_spec.rb new file mode 100644 index 00000000000..41de93b27ad --- /dev/null +++ b/spec/graphql/types/security/codequality_reports_comparer/summary_type_spec.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe GitlabSchema.types['CodequalityReportsComparerReportSummary'], feature_category: :code_quality do + specify { expect(described_class.graphql_name).to eq('CodequalityReportsComparerReportSummary') } + + it 'has expected fields' do + expected_fields = %i[total resolved errored] + + expect(described_class).to have_graphql_fields(*expected_fields) + end +end diff --git a/spec/graphql/types/security/codequality_reports_comparer_type_spec.rb b/spec/graphql/types/security/codequality_reports_comparer_type_spec.rb new file mode 100644 index 00000000000..02f7a9d6925 --- /dev/null +++ b/spec/graphql/types/security/codequality_reports_comparer_type_spec.rb @@ -0,0 +1,11 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe GitlabSchema.types['CodequalityReportsComparer'], feature_category: :code_quality do + specify { expect(described_class.graphql_name).to eq('CodequalityReportsComparer') } + + it 'has expected fields' do + expect(described_class).to have_graphql_fields(:report) + end +end diff --git a/spec/lib/gitlab/background_migration/backfill_users_with_defaults_spec.rb b/spec/lib/gitlab/background_migration/backfill_users_with_defaults_spec.rb new file mode 100644 index 00000000000..78f36933435 --- /dev/null +++ b/spec/lib/gitlab/background_migration/backfill_users_with_defaults_spec.rb @@ -0,0 +1,68 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Gitlab::BackgroundMigration::BackfillUsersWithDefaults, + schema: 20230818083610, + feature_category: :user_profile do + let(:users) { table(:users) } + let(:columns) { [:project_view, :hide_no_ssh_key, :hide_no_password, :notified_of_own_activity] } + let(:initial_column_values) do + [ + [nil, nil, nil, nil], + [0, nil, nil, nil], + [nil, true, nil, nil], + [nil, nil, true, nil], + [nil, nil, nil, true] + ] + .map { |row| columns.zip(row).to_h } + end + + let(:final_column_values) do + [ + [2, false, false, false], + [0, false, false, false], + [2, true, false, false], + [2, false, true, false], + [2, false, false, true] + ] + .map { |row| columns.zip(row).to_h } + end + + subject(:perform_migration) do + described_class + .new( + start_id: users.minimum(:id), + end_id: users.maximum(:id), + batch_table: :users, + batch_column: :id, + sub_batch_size: 2, + pause_ms: 0, + connection: ActiveRecord::Base.connection + ) + .perform + end + + before do + initial_column_values.each_with_index do |attributes, index| + user = users.create!(**attributes.merge(projects_limit: 1, email: "user#{index}@gitlab.com")) + final_column_values[index].merge!(id: user.id) + end + end + + it 'backfills the null values with the default values' do + perform_migration + + final_column_values.each { |attributes| match_attributes(attributes) } + end + + private + + def match_attributes(attributes) + migrated_user = users.find(attributes[:id]) + expect(migrated_user.project_view).to eq(attributes[:project_view]) + expect(migrated_user.hide_no_ssh_key).to eq(attributes[:hide_no_ssh_key]) + expect(migrated_user.hide_no_password).to eq(attributes[:hide_no_password]) + expect(migrated_user.notified_of_own_activity).to eq(attributes[:notified_of_own_activity]) + end +end diff --git a/spec/migrations/20230818083610_queue_backfill_users_with_defaults_spec.rb b/spec/migrations/20230818083610_queue_backfill_users_with_defaults_spec.rb new file mode 100644 index 00000000000..4cd72b4fa7a --- /dev/null +++ b/spec/migrations/20230818083610_queue_backfill_users_with_defaults_spec.rb @@ -0,0 +1,27 @@ +# frozen_string_literal: true + +require 'spec_helper' +require_migration! + +RSpec.describe QueueBackfillUsersWithDefaults, feature_category: :user_profile do + let!(:batched_migration) { described_class::MIGRATION } + + it 'schedules a new batched migration' do + reversible_migration do |migration| + migration.before -> { + expect(batched_migration).not_to have_scheduled_batched_migration + } + + migration.after -> { + expect(batched_migration).to have_scheduled_batched_migration( + table_name: :users, + column_name: :id, + interval: described_class::DELAY_INTERVAL, + batch_size: described_class::BATCH_SIZE, + sub_batch_size: described_class::SUB_BATCH_SIZE, + max_batch_size: described_class::MAX_BATCH_SIZE + ) + } + end + end +end diff --git a/spec/migrations/ensure_mr_user_mentions_note_id_bigint_backfill_is_finished_for_self_managed_spec.rb b/spec/migrations/ensure_mr_user_mentions_note_id_bigint_backfill_is_finished_for_self_managed_spec.rb new file mode 100644 index 00000000000..482cca67e46 --- /dev/null +++ b/spec/migrations/ensure_mr_user_mentions_note_id_bigint_backfill_is_finished_for_self_managed_spec.rb @@ -0,0 +1,35 @@ +# frozen_string_literal: true + +require 'spec_helper' +require_migration! + +RSpec.describe EnsureMrUserMentionsNoteIdBigintBackfillIsFinishedForSelfManaged, feature_category: :database do + describe '#up' do + let(:migration_arguments) do + { + job_class_name: 'CopyColumnUsingBackgroundMigrationJob', + table_name: 'merge_request_user_mentions', + column_name: 'id', + job_arguments: [['note_id'], ['note_id_convert_to_bigint']] + } + end + + it 'ensures the migration is completed for self-managed instances' do + expect_next_instance_of(described_class) do |instance| + expect(instance).to receive(:com_or_dev_or_test_but_not_jh?).and_return(false) + expect(instance).to receive(:ensure_batched_background_migration_is_finished).with(migration_arguments) + end + + migrate! + end + + it 'skips the check for GitLab.com, dev, or test' do + expect_next_instance_of(described_class) do |instance| + expect(instance).to receive(:com_or_dev_or_test_but_not_jh?).and_return(true) + expect(instance).not_to receive(:ensure_batched_background_migration_is_finished) + end + + migrate! + end + end +end diff --git a/spec/migrations/swap_merge_request_user_mentions_note_id_to_bigint_for_self_managed_spec.rb b/spec/migrations/swap_merge_request_user_mentions_note_id_to_bigint_for_self_managed_spec.rb new file mode 100644 index 00000000000..5cba691e20e --- /dev/null +++ b/spec/migrations/swap_merge_request_user_mentions_note_id_to_bigint_for_self_managed_spec.rb @@ -0,0 +1,135 @@ +# frozen_string_literal: true + +require 'spec_helper' +require_migration! + +RSpec.describe SwapMergeRequestUserMentionsNoteIdToBigintForSelfManaged, feature_category: :database do + let(:connection) { described_class.new.connection } + let(:merge_request_user_mentions) { table(:merge_request_user_mentions) } + + shared_examples 'column `note_id_convert_to_bigint` is already dropped' do + before do + connection.execute('ALTER TABLE merge_request_user_mentions ALTER COLUMN note_id TYPE bigint') + connection.execute('ALTER TABLE merge_request_user_mentions DROP COLUMN IF EXISTS note_id_convert_to_bigint') + end + + after do + connection.execute('ALTER TABLE merge_request_user_mentions DROP COLUMN IF EXISTS note_id_convert_to_bigint') + end + + it 'does not swaps the columns' do + disable_migrations_output do + reversible_migration do |migration| + migration.before -> { + merge_request_user_mentions.reset_column_information + + expect(merge_request_user_mentions.columns.find { |c| c.name == 'note_id' }.sql_type).to eq('bigint') + expect(merge_request_user_mentions.columns.find { |c| c.name == 'note_id_convert_to_bigint' }).to be_nil + } + + migration.after -> { + merge_request_user_mentions.reset_column_information + + expect(merge_request_user_mentions.columns.find { |c| c.name == 'note_id' }.sql_type).to eq('bigint') + expect(merge_request_user_mentions.columns.find { |c| c.name == 'note_id_convert_to_bigint' }).to be_nil + } + end + end + end + end + + describe '#up' do + before do + # rubocop:disable RSpec/AnyInstanceOf + allow_any_instance_of(described_class).to( + receive(:com_or_dev_or_test_but_not_jh?).and_return(com_or_dev_or_test_but_not_jh?) + ) + # rubocop:enable RSpec/AnyInstanceOf + end + + context 'when GitLab.com, dev, or test' do + let(:com_or_dev_or_test_but_not_jh?) { true } + + it_behaves_like 'column `note_id_convert_to_bigint` is already dropped' + end + + context 'when self-managed instance with the `note_id_convert_to_bigint` column already dropped' do + let(:com_or_dev_or_test_but_not_jh?) { false } + + it_behaves_like 'column `note_id_convert_to_bigint` is already dropped' + end + + context 'when self-managed instance columns already swapped' do + let(:com_or_dev_or_test_but_not_jh?) { false } + + before do + connection.execute('ALTER TABLE merge_request_user_mentions ALTER COLUMN note_id TYPE bigint') + connection.execute( + 'ALTER TABLE merge_request_user_mentions ADD COLUMN IF NOT EXISTS note_id_convert_to_bigint integer' + ) + + disable_migrations_output { migrate! } + end + + after do + connection.execute('ALTER TABLE merge_request_user_mentions DROP COLUMN IF EXISTS note_id_convert_to_bigint') + end + + it 'does not swaps the columns' do + expect(merge_request_user_mentions.columns.find { |c| c.name == 'note_id' }.sql_type).to eq('bigint') + expect(merge_request_user_mentions.columns.find { |c| c.name == 'note_id_convert_to_bigint' }.sql_type).to( + eq('integer') + ) + end + end + + context 'when self-managed instance' do + let(:com_or_dev_or_test_but_not_jh?) { false } + + before do + connection.execute('ALTER TABLE merge_request_user_mentions ALTER COLUMN note_id TYPE integer') + connection.execute( + 'ALTER TABLE merge_request_user_mentions ADD COLUMN IF NOT EXISTS note_id_convert_to_bigint bigint' + ) + connection.execute('ALTER TABLE merge_request_user_mentions ALTER COLUMN note_id_convert_to_bigint TYPE bigint') + connection.execute( + 'DROP INDEX IF EXISTS index_merge_request_user_mentions_on_note_id_convert_to_bigint CASCADE' + ) + connection.execute('CREATE OR REPLACE FUNCTION trigger_bfcbace4260d() RETURNS trigger LANGUAGE plpgsql AS $$ + BEGIN NEW."note_id_convert_to_bigint" := NEW."note_id"; RETURN NEW; END; $$;') + end + + after do + connection.execute('ALTER TABLE merge_request_user_mentions DROP COLUMN IF EXISTS note_id_convert_to_bigint') + end + + it 'swaps the columns' do + disable_migrations_output do + reversible_migration do |migration| + migration.before -> { + merge_request_user_mentions.reset_column_information + + expect(merge_request_user_mentions.columns.find { |c| c.name == 'note_id' }.sql_type).to eq('integer') + expect(merge_request_user_mentions.columns.find do |c| + c.name == 'note_id_convert_to_bigint' + end.sql_type).to( + eq('bigint') + ) + } + + migration.after -> { + merge_request_user_mentions.reset_column_information + + expect(merge_request_user_mentions.columns.find { |c| c.name == 'note_id' }.sql_type).to eq('bigint') + expect(merge_request_user_mentions.columns.find do |c| + c.name == 'note_id_convert_to_bigint' + end.sql_type).to( + eq('integer') + ) + } + end + end + end + end + end +end diff --git a/spec/requests/api/graphql/merge_requests/codequality_reports_comparer_spec.rb b/spec/requests/api/graphql/merge_requests/codequality_reports_comparer_spec.rb new file mode 100644 index 00000000000..2939e9307e9 --- /dev/null +++ b/spec/requests/api/graphql/merge_requests/codequality_reports_comparer_spec.rb @@ -0,0 +1,185 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe 'Query.project.mergeRequest.codequalityReportsComparer', feature_category: :code_quality do + include GraphqlHelpers + + let_it_be(:user) { create(:user) } + let_it_be(:project) { create(:project, :repository) } + let_it_be(:merge_request) { create(:merge_request, :with_codequality_reports, source_project: project) } + + let(:mock_report) do + { + status: :parsed, + data: { + status: 'failed', + new_errors: [ + { + description: "Method `new_array` has 12 arguments (exceeds 4 allowed). Consider refactoring.", + fingerprint: "15cdb5c53afd42bc22f8ca366a08d547", + severity: "major", + file_path: "foo.rb", + line: 10, + engine_name: "structure" + }, + { + description: "Method `backwards_array` has 12 arguments (exceeds 4 allowed). Consider refactoring.", + fingerprint: "f3bdc1e8c102ba5fbd9e7f6cda51c95e", + severity: "major", + file_path: "foo.rb", + line: 14, + engine_name: "structure" + }, + { + description: "Avoid parameter lists longer than 5 parameters. [12/5]", + fingerprint: "ab5f8b935886b942d621399f5a2ca16e", + severity: "minor", + file_path: "foo.rb", + line: 14, + engine_name: "rubocop" + } + ], + resolved_errors: [], + existing_errors: [], + summary: { + total: 3, + resolved: 0, + errored: 3 + } + }.deep_stringify_keys + } + end + + let(:codequality_reports_comparer_fields) do + <<~QUERY + codequalityReportsComparer { + report { + status + newErrors { + description + fingerprint + severity + filePath + line + webUrl + engineName + } + resolvedErrors { + description + fingerprint + severity + filePath + line + webUrl + engineName + } + existingErrors { + description + fingerprint + severity + filePath + line + webUrl + engineName + } + summary { + errored + resolved + total + } + } + } + QUERY + end + + let(:merge_request_fields) do + query_graphql_field(:merge_request, { iid: merge_request.iid.to_s }, codequality_reports_comparer_fields) + end + + let(:query) { graphql_query_for(:project, { full_path: project.full_path }, merge_request_fields) } + + subject(:result) { graphql_data_at(:project, :merge_request, :codequality_reports_comparer) } + + before do + allow_next_found_instance_of(MergeRequest) do |merge_request| + allow(merge_request).to receive(:compare_codequality_reports).and_return(mock_report) + end + end + + context 'when the user is not authorized to read the field' do + before do + post_graphql(query, current_user: user) + end + + it { is_expected.to be_nil } + end + + context 'when the user is authorized to read the field' do + before_all do + project.add_reporter(user) + end + + before do + post_graphql(query, current_user: user) + end + + context 'when when sast_reports_in_inline_diff FF is disabled' do + before_all do + stub_feature_flags(sast_reports_in_inline_diff: false) + end + + it 'returns null for codequality_reports_comparer field' do + expect(result).to be_nil + end + end + + it 'returns expected data' do + expect(result).to match( + a_hash_including( + { + report: { + status: 'FAILED', + newErrors: [ + { + description: 'Method `new_array` has 12 arguments (exceeds 4 allowed). Consider refactoring.', + fingerprint: '15cdb5c53afd42bc22f8ca366a08d547', + severity: 'MAJOR', + filePath: 'foo.rb', + line: 10, + webUrl: nil, + engineName: 'structure' + }, + { + description: 'Method `backwards_array` has 12 arguments (exceeds 4 allowed). Consider refactoring.', + fingerprint: 'f3bdc1e8c102ba5fbd9e7f6cda51c95e', + severity: 'MAJOR', + filePath: 'foo.rb', + line: 14, + webUrl: nil, + engineName: 'structure' + }, + { + description: 'Avoid parameter lists longer than 5 parameters. [12/5]', + fingerprint: 'ab5f8b935886b942d621399f5a2ca16e', + severity: 'MINOR', + filePath: 'foo.rb', + line: 14, + webUrl: nil, + engineName: 'rubocop' + } + ], + resolvedErrors: [], + existingErrors: [], + summary: { + errored: 3, + resolved: 0, + total: 3 + } + } + }.deep_stringify_keys + ) + ) + end + end +end diff --git a/spec/requests/api/graphql/project/merge_request_spec.rb b/spec/requests/api/graphql/project/merge_request_spec.rb index 80c7258c05d..28aadf850f0 100644 --- a/spec/requests/api/graphql/project/merge_request_spec.rb +++ b/spec/requests/api/graphql/project/merge_request_spec.rb @@ -22,7 +22,8 @@ RSpec.describe 'getting merge request information nested in a project', feature_ it_behaves_like 'a working graphql query' do # we exclude Project.pipeline because it needs arguments - let(:mr_fields) { all_graphql_fields_for('MergeRequest', excluded: %w[jobs pipeline]) } + # and codequalityReportsComparer because no pipeline exist yet + let(:mr_fields) { all_graphql_fields_for('MergeRequest', excluded: %w[jobs pipeline codequalityReportsComparer]) } before do post_graphql(query, current_user: current_user) diff --git a/spec/serializers/codequality_degradation_entity_spec.rb b/spec/serializers/codequality_degradation_entity_spec.rb index 32269e5475b..3d07564c5dc 100644 --- a/spec/serializers/codequality_degradation_entity_spec.rb +++ b/spec/serializers/codequality_degradation_entity_spec.rb @@ -2,18 +2,31 @@ require 'spec_helper' -RSpec.describe CodequalityDegradationEntity do +RSpec.describe CodequalityDegradationEntity, feature_category: :code_quality do let(:entity) { described_class.new(codequality_degradation) } describe '#as_json' do subject { entity.as_json } + context 'when sast_reports_in_inline_diff is disabled' do + before do + stub_feature_flags(sast_reports_in_inline_diff: false) + end + + let(:codequality_degradation) { build(:codequality_degradation_1) } + + it 'does not contain fingerprint' do + expect(subject[:fingerprint]).to be_nil + end + end + context 'when codequality contains an error' do context 'when line is included in location' do let(:codequality_degradation) { build(:codequality_degradation_2) } it 'contains correct codequality degradation details', :aggregate_failures do expect(subject[:description]).to eq("Method `new_array` has 12 arguments (exceeds 4 allowed). Consider refactoring.") + expect(subject[:fingerprint]).to eq("f3bdc1e8c102ba5fbd9e7f6cda51c95e") expect(subject[:severity]).to eq("major") expect(subject[:file_path]).to eq("file_a.rb") expect(subject[:line]).to eq(10) @@ -27,6 +40,7 @@ RSpec.describe CodequalityDegradationEntity do it 'contains correct codequality degradation details', :aggregate_failures do expect(subject[:description]).to eq("Avoid parameter lists longer than 5 parameters. [12/5]") + expect(subject[:fingerprint]).to eq("ab5f8b935886b942d621399f5a2ca16e") expect(subject[:severity]).to eq("minor") expect(subject[:file_path]).to eq("file_b.rb") expect(subject[:line]).to eq(10) @@ -44,6 +58,7 @@ RSpec.describe CodequalityDegradationEntity do it 'lowercases severity', :aggregate_failures do expect(subject[:description]).to eq("Avoid parameter lists longer than 5 parameters. [12/5]") + expect(subject[:fingerprint]).to eq("ab5f8b935886b942d621399f5a2ca16e") expect(subject[:severity]).to eq("minor") expect(subject[:file_path]).to eq("file_b.rb") expect(subject[:line]).to eq(10) diff --git a/spec/serializers/codequality_reports_comparer_serializer_spec.rb b/spec/serializers/codequality_reports_comparer_serializer_spec.rb index 50c8a69737c..7d6f49bf41d 100644 --- a/spec/serializers/codequality_reports_comparer_serializer_spec.rb +++ b/spec/serializers/codequality_reports_comparer_serializer_spec.rb @@ -2,8 +2,8 @@ require 'spec_helper' -RSpec.describe CodequalityReportsComparerSerializer do - let(:project) { double(:project) } +RSpec.describe CodequalityReportsComparerSerializer, feature_category: :code_quality do + let(:project) { build_stubbed(:project) } let(:serializer) { described_class.new(project: project).represent(comparer) } let(:comparer) { Gitlab::Ci::Reports::CodequalityReportsComparer.new(base_report, head_report) } let(:base_report) { Gitlab::Ci::Reports::CodequalityReports.new } diff --git a/spec/services/system_notes/issuables_service_spec.rb b/spec/services/system_notes/issuables_service_spec.rb index af660a9b72e..c6d5f3fa385 100644 --- a/spec/services/system_notes/issuables_service_spec.rb +++ b/spec/services/system_notes/issuables_service_spec.rb @@ -28,6 +28,14 @@ RSpec.describe ::SystemNotes::IssuablesService, feature_category: :team_planning expect(subject.note).to eq "marked this issue as related to #{noteable_ref.to_reference(project)}" end end + + context 'with work items' do + let_it_be(:noteable) { create(:work_item, :task, project: project) } + + it 'sets the note text with the correct work item type' do + expect(subject.note).to eq "marked this task as related to #{noteable_ref.to_reference(project)}" + end + end end describe '#unrelate_issuable' do diff --git a/spec/support/database/auto_explain.rb b/spec/support/database/auto_explain.rb index 108d88e37b9..799457034a1 100644 --- a/spec/support/database/auto_explain.rb +++ b/spec/support/database/auto_explain.rb @@ -115,11 +115,16 @@ module AutoExplain private def record_auto_explain?(connection) - ENV['CI'] \ - && ENV['CI_MERGE_REQUEST_LABELS']&.include?('pipeline:record-queries') \ - && ENV['CI_JOB_NAME_SLUG'] != 'db-migrate-non-superuser' \ - && connection.database_version.to_s[0..1].to_i >= 14 \ - && connection.select_one('SHOW is_superuser')['is_superuser'] == 'on' + return false unless ENV['CI'] + return false if ENV['CI_JOB_NAME_SLUG'] == 'db-migrate-non-superuser' + return false if connection.database_version.to_s[0..1].to_i < 14 + return false if connection.select_one('SHOW is_superuser')['is_superuser'] != 'on' + + # This condition matches the pipeline rules for if-merge-request-labels-record-queries + return true if ENV['CI_MERGE_REQUEST_LABELS']&.include?('pipeline:record-queries') + + # This condition matches the pipeline rules for if-default-branch-refs + ENV['CI_COMMIT_REF_NAME'] == ENV['CI_DEFAULT_BRANCH'] && !ENV['CI_MERGE_REQUEST_IID'] end end end |