diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-02-06 18:08:52 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-02-06 18:08:52 +0300 |
commit | 7b69a22d499787378aa30561822ef797a99c22e5 (patch) | |
tree | 630c757f4b55abd7ee445def6577587ec57e860d /spec | |
parent | d75e21489f113731bfe02b6c88e58879b5859103 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
25 files changed, 152 insertions, 196 deletions
diff --git a/spec/db/schema_spec.rb b/spec/db/schema_spec.rb index 0875bb4e92a..5a02d712117 100644 --- a/spec/db/schema_spec.rb +++ b/spec/db/schema_spec.rb @@ -46,7 +46,7 @@ RSpec.describe 'Database schema', feature_category: :database do ci_pending_builds: %w[partition_id], ci_pipeline_variables: %w[partition_id], ci_pipelines: %w[partition_id], - ci_resources: %w[partition_id], + ci_resources: %w[partition_id build_id], ci_runner_projects: %w[runner_id], ci_running_builds: %w[partition_id], ci_sources_pipelines: %w[partition_id source_partition_id], @@ -187,7 +187,6 @@ RSpec.describe 'Database schema', feature_category: :database do # These pre-existing enums have limits > 2 bytes IGNORED_LIMIT_ENUMS = { 'Analytics::CycleAnalytics::Stage' => %w[start_event_identifier end_event_identifier], - 'Analytics::CycleAnalytics::ProjectStage' => %w[start_event_identifier end_event_identifier], 'Ci::Bridge' => %w[failure_reason], 'Ci::Build' => %w[failure_reason], 'Ci::BuildMetadata' => %w[timeout_source], diff --git a/spec/factories/analytics/cycle_analytics/project_stages.rb b/spec/factories/analytics/cycle_analytics/project_stages.rb deleted file mode 100644 index e673c4957b0..00000000000 --- a/spec/factories/analytics/cycle_analytics/project_stages.rb +++ /dev/null @@ -1,16 +0,0 @@ -# frozen_string_literal: true - -FactoryBot.define do - factory :cycle_analytics_project_stage, class: 'Analytics::CycleAnalytics::ProjectStage' do - project - sequence(:name) { |n| "Stage ##{n}" } - hidden { false } - issue_stage - value_stream { association(:cycle_analytics_project_value_stream, project: project) } - - trait :issue_stage do - start_event_identifier { Gitlab::Analytics::CycleAnalytics::StageEvents::IssueCreated.identifier } - end_event_identifier { Gitlab::Analytics::CycleAnalytics::StageEvents::IssueStageEnd.identifier } - end - end -end diff --git a/spec/factories/analytics/cycle_analytics/project_value_streams.rb b/spec/factories/analytics/cycle_analytics/project_value_streams.rb deleted file mode 100644 index 45a6470b0aa..00000000000 --- a/spec/factories/analytics/cycle_analytics/project_value_streams.rb +++ /dev/null @@ -1,9 +0,0 @@ -# frozen_string_literal: true - -FactoryBot.define do - factory :cycle_analytics_project_value_stream, class: 'Analytics::CycleAnalytics::ProjectValueStream' do - sequence(:name) { |n| "Value Stream ##{n}" } - - project - end -end diff --git a/spec/factories/analytics/cycle_analytics/stages.rb b/spec/factories/analytics/cycle_analytics/stages.rb index abf051f9a69..4f6f38f6f33 100644 --- a/spec/factories/analytics/cycle_analytics/stages.rb +++ b/spec/factories/analytics/cycle_analytics/stages.rb @@ -2,11 +2,19 @@ FactoryBot.define do factory :cycle_analytics_stage, class: 'Analytics::CycleAnalytics::Stage' do + transient do + project { nil } + end + sequence(:name) { |n| "Stage ##{n}" } start_event_identifier { Gitlab::Analytics::CycleAnalytics::StageEvents::MergeRequestCreated.identifier } end_event_identifier { Gitlab::Analytics::CycleAnalytics::StageEvents::MergeRequestMerged.identifier } namespace { association(:group) } value_stream { association(:cycle_analytics_value_stream, namespace: namespace) } + + after(:build) do |stage, evaluator| + stage.namespace = evaluator.project.reload.project_namespace if evaluator.project + end end end diff --git a/spec/finders/analytics/cycle_analytics/stage_finder_spec.rb b/spec/finders/analytics/cycle_analytics/stage_finder_spec.rb index 0275205028a..3e10ed78ab9 100644 --- a/spec/finders/analytics/cycle_analytics/stage_finder_spec.rb +++ b/spec/finders/analytics/cycle_analytics/stage_finder_spec.rb @@ -7,7 +7,7 @@ RSpec.describe Analytics::CycleAnalytics::StageFinder do let(:stage_id) { { id: Gitlab::Analytics::CycleAnalytics::DefaultStages.names.first } } - subject { described_class.new(parent: project, stage_id: stage_id[:id]).execute } + subject { described_class.new(parent: project.project_namespace, stage_id: stage_id[:id]).execute } context 'when looking up in-memory default stage by name exists' do it { expect(subject).not_to be_persisted } diff --git a/spec/finders/protected_branches_finder_spec.rb b/spec/finders/protected_branches_finder_spec.rb index 487d1be697a..5926891ac9d 100644 --- a/spec/finders/protected_branches_finder_spec.rb +++ b/spec/finders/protected_branches_finder_spec.rb @@ -3,35 +3,57 @@ require 'spec_helper' RSpec.describe ProtectedBranchesFinder do - let(:project) { create(:project) } - let!(:protected_branch) { create(:protected_branch, project: project) } - let!(:another_protected_branch) { create(:protected_branch, project: project) } + let_it_be(:group) { create(:group) } + let_it_be(:project) { create(:project, namespace: group) } + + let!(:project_protected_branch) { create(:protected_branch, project: project) } + let!(:another_project_protected_branch) { create(:protected_branch, project: project) } + let!(:group_protected_branch) { create(:protected_branch, project: nil, group: group) } + let!(:another_group_protected_branch) { create(:protected_branch, project: nil, group: group) } let!(:other_protected_branch) { create(:protected_branch) } + let(:params) { {} } + subject { described_class.new(entity, params).execute } + describe '#execute' do - subject { described_class.new(project, params).execute } + shared_examples 'execute by entity' do + it 'returns all protected branches of project by default' do + expect(subject).to match_array(expected_branches) + end - it 'returns all protected branches of project by default' do - expect(subject).to match_array([protected_branch, another_protected_branch]) - end + context 'when search param is present' do + let(:params) { { search: group_protected_branch.name } } - context 'when search param is present' do - let(:params) { { search: protected_branch.name } } + it 'filters by search param' do + expect(subject).to eq([group_protected_branch]) + end + end + + context 'when there are more protected branches than the limit' do + before do + stub_const("#{described_class}::LIMIT", 1) + end - it 'filters by search param' do - expect(subject).to eq([protected_branch]) + it 'returns limited protected branches of project' do + expect(subject.count).to eq(1) + end end end - context 'when there are more protected branches than the limit' do - before do - stub_const("#{described_class}::LIMIT", 1) + it_behaves_like 'execute by entity' do + let(:entity) { project } + let(:expected_branches) do + [ + project_protected_branch, another_project_protected_branch, + group_protected_branch, another_group_protected_branch + ] end + end - it 'returns limited protected branches of project' do - expect(subject.count).to eq(1) - end + it_behaves_like 'execute by entity' do + let(:entity) { group } + let(:expected_branches) { [group_protected_branch, another_group_protected_branch] } end end end diff --git a/spec/frontend/notes/deprecated_notes_spec.js b/spec/frontend/notes/deprecated_notes_spec.js index 4756a107a15..6d3bc19bd45 100644 --- a/spec/frontend/notes/deprecated_notes_spec.js +++ b/spec/frontend/notes/deprecated_notes_spec.js @@ -28,6 +28,10 @@ window.gl = window.gl || {}; gl.utils = gl.utils || {}; gl.utils.disableButtonIfEmptyField = () => {}; +function wrappedDiscussionNote(note) { + return `<table><tbody>${note}</tbody></table>`; +} + // the following test is unreliable and failing in main 2-3 times a day // see https://gitlab.com/gitlab-org/gitlab/issues/206906#note_290602581 // eslint-disable-next-line jest/no-disabled-tests @@ -436,22 +440,40 @@ describe.skip('Old Notes (~/deprecated_notes.js)', () => { ); }); - it('should append to row selected with line_code', () => { - $form.length = 0; - note.discussion_line_code = 'line_code'; - note.diff_discussion_html = '<tr></tr>'; + describe('HTML output', () => { + let line; - const line = document.createElement('div'); - line.id = note.discussion_line_code; - document.body.appendChild(line); + beforeEach(() => { + $form.length = 0; + note.discussion_line_code = 'line_code'; + note.diff_discussion_html = '<tr></tr>'; - // Override mocks for this single test - $form.closest.mockReset(); - $form.closest.mockReturnValue($form); + line = document.createElement('div'); + line.id = note.discussion_line_code; + document.body.appendChild(line); - Notes.prototype.renderDiscussionNote.call(notes, note, $form); + // Override mocks for these tests + $form.closest.mockReset(); + $form.closest.mockReturnValue($form); + }); - expect(line.nextSibling.outerHTML).toEqual(note.diff_discussion_html); + it('should append to row selected with line_code', () => { + Notes.prototype.renderDiscussionNote.call(notes, note, $form); + + expect(line.nextSibling.outerHTML).toEqual( + wrappedDiscussionNote(note.diff_discussion_html), + ); + }); + + it('sanitizes the output html without stripping leading <tr> or <td> elements', () => { + const sanitizedDiscussion = '<tr><td><a>I am a dolphin!</a></td></tr>'; + note.diff_discussion_html = + '<tr><td><a href="javascript:alert(1)">I am a dolphin!</a></td></tr>'; + + Notes.prototype.renderDiscussionNote.call(notes, note, $form); + + expect(line.nextSibling.outerHTML).toEqual(wrappedDiscussionNote(sanitizedDiscussion)); + }); }); }); diff --git a/spec/lib/banzai/filter/references/issue_reference_filter_spec.rb b/spec/lib/banzai/filter/references/issue_reference_filter_spec.rb index 37fdd3ec806..d8a97c6c3dc 100644 --- a/spec/lib/banzai/filter/references/issue_reference_filter_spec.rb +++ b/spec/lib/banzai/filter/references/issue_reference_filter_spec.rb @@ -47,57 +47,55 @@ RSpec.describe Banzai::Filter::References::IssueReferenceFilter, feature_categor end end - context 'internal reference' do - let(:reference) { "##{issue.iid}" } - + shared_examples 'an internal reference' do it_behaves_like 'a reference containing an element node' it_behaves_like 'a reference with issue type information' it 'links to a valid reference' do - doc = reference_filter("Fixed #{reference}") + doc = reference_filter("Fixed #{written_reference}") expect(doc.css('a').first.attr('href')) .to eq issue_url end it 'links with adjacent text' do - doc = reference_filter("Fixed (#{reference}.)") + doc = reference_filter("Fixed (#{written_reference}.)") expect(doc.text).to eql("Fixed (#{reference}.)") end it 'ignores invalid issue IDs' do - invalid = invalidate_reference(reference) + invalid = invalidate_reference(written_reference) exp = act = "Fixed #{invalid}" expect(reference_filter(act).to_html).to eq exp end it 'includes a title attribute' do - doc = reference_filter("Issue #{reference}") + doc = reference_filter("Issue #{written_reference}") expect(doc.css('a').first.attr('title')).to eq issue.title end it 'escapes the title attribute' do issue.update_attribute(:title, %{"></a>whatever<a title="}) - doc = reference_filter("Issue #{reference}") + doc = reference_filter("Issue #{written_reference}") expect(doc.text).to eq "Issue #{reference}" end it 'renders non-HTML tooltips' do - doc = reference_filter("Issue #{reference}") + doc = reference_filter("Issue #{written_reference}") expect(doc.at_css('a')).not_to have_attribute('data-html') end it 'includes default classes' do - doc = reference_filter("Issue #{reference}") + doc = reference_filter("Issue #{written_reference}") expect(doc.css('a').first.attr('class')).to eq 'gfm gfm-issue' end it 'includes a data-project attribute' do - doc = reference_filter("Issue #{reference}") + doc = reference_filter("Issue #{written_reference}") link = doc.css('a').first expect(link).to have_attribute('data-project') @@ -105,7 +103,7 @@ RSpec.describe Banzai::Filter::References::IssueReferenceFilter, feature_categor end it 'includes a data-issue attribute' do - doc = reference_filter("See #{reference}") + doc = reference_filter("See #{written_reference}") link = doc.css('a').first expect(link).to have_attribute('data-issue') @@ -113,7 +111,7 @@ RSpec.describe Banzai::Filter::References::IssueReferenceFilter, feature_categor end it 'includes data attributes for issuable popover' do - doc = reference_filter("See #{reference}") + doc = reference_filter("See #{written_reference}") link = doc.css('a').first expect(link.attr('data-project-path')).to eq project.full_path @@ -121,21 +119,21 @@ RSpec.describe Banzai::Filter::References::IssueReferenceFilter, feature_categor end it 'includes a data-original attribute' do - doc = reference_filter("See #{reference}") + doc = reference_filter("See #{written_reference}") link = doc.css('a').first expect(link).to have_attribute('data-original') - expect(link.attr('data-original')).to eq reference + expect(link.attr('data-original')).to eq written_reference end it 'does not escape the data-original attribute' do inner_html = 'element <code>node</code> inside' - doc = reference_filter(%{<a href="#{reference}">#{inner_html}</a>}) + doc = reference_filter(%{<a href="#{written_reference}">#{inner_html}</a>}) expect(doc.children.first.attr('data-original')).to eq inner_html end it 'includes a data-reference-format attribute' do - doc = reference_filter("Issue #{reference}+") + doc = reference_filter("Issue #{written_reference}+") link = doc.css('a').first expect(link).to have_attribute('data-reference-format') @@ -153,7 +151,7 @@ RSpec.describe Banzai::Filter::References::IssueReferenceFilter, feature_categor end it 'supports an :only_path context' do - doc = reference_filter("Issue #{reference}", only_path: true) + doc = reference_filter("Issue #{written_reference}", only_path: true) link = doc.css('a').first.attr('href') expect(link).not_to match %r(https?://) @@ -161,7 +159,7 @@ RSpec.describe Banzai::Filter::References::IssueReferenceFilter, feature_categor end it 'does not process links containing issue numbers followed by text' do - href = "#{reference}st" + href = "#{written_reference}st" doc = reference_filter("<a href='#{href}'></a>") link = doc.css('a').first.attr('href') @@ -169,6 +167,20 @@ RSpec.describe Banzai::Filter::References::IssueReferenceFilter, feature_categor end end + context 'standard internal reference' do + let(:written_reference) { "##{issue.iid}" } + let(:reference) { "##{issue.iid}" } + + it_behaves_like 'an internal reference' + end + + context 'alternative internal_reference' do + let(:written_reference) { "GL-#{issue.iid}" } + let(:reference) { "##{issue.iid}" } + + it_behaves_like 'an internal reference' + end + context 'cross-project / cross-namespace complete reference' do let(:reference) { "#{project2.full_path}##{issue.iid}" } let(:issue) { create(:issue, project: project2) } diff --git a/spec/lib/gitlab/analytics/cycle_analytics/aggregated/base_query_builder_spec.rb b/spec/lib/gitlab/analytics/cycle_analytics/aggregated/base_query_builder_spec.rb index bf2f8d8159b..bd6af4269b4 100644 --- a/spec/lib/gitlab/analytics/cycle_analytics/aggregated/base_query_builder_spec.rb +++ b/spec/lib/gitlab/analytics/cycle_analytics/aggregated/base_query_builder_spec.rb @@ -17,7 +17,7 @@ RSpec.describe Gitlab::Analytics::CycleAnalytics::Aggregated::BaseQueryBuilder d let_it_be(:issue_outside_project) { create(:issue) } let_it_be(:stage) do - create(:cycle_analytics_project_stage, + create(:cycle_analytics_stage, project: project, start_event_identifier: :issue_created, end_event_identifier: :issue_deployed_to_production diff --git a/spec/lib/gitlab/analytics/cycle_analytics/aggregated/records_fetcher_spec.rb b/spec/lib/gitlab/analytics/cycle_analytics/aggregated/records_fetcher_spec.rb index 7e36d89a2a1..aa0a1b66eef 100644 --- a/spec/lib/gitlab/analytics/cycle_analytics/aggregated/records_fetcher_spec.rb +++ b/spec/lib/gitlab/analytics/cycle_analytics/aggregated/records_fetcher_spec.rb @@ -8,7 +8,7 @@ RSpec.describe Gitlab::Analytics::CycleAnalytics::Aggregated::RecordsFetcher do let_it_be(:issue_2) { create(:issue, project: project) } let_it_be(:issue_3) { create(:issue, project: project) } - let_it_be(:stage) { create(:cycle_analytics_project_stage, start_event_identifier: :issue_created, end_event_identifier: :issue_deployed_to_production, project: project) } + let_it_be(:stage) { create(:cycle_analytics_stage, start_event_identifier: :issue_created, end_event_identifier: :issue_deployed_to_production, namespace: project.reload.project_namespace) } let_it_be(:stage_event_1) { create(:cycle_analytics_issue_stage_event, stage_event_hash_id: stage.stage_event_hash_id, project_id: project.id, issue_id: issue_1.id, start_event_timestamp: 2.years.ago, end_event_timestamp: 1.year.ago) } # duration: 1 year let_it_be(:stage_event_2) { create(:cycle_analytics_issue_stage_event, stage_event_hash_id: stage.stage_event_hash_id, project_id: project.id, issue_id: issue_2.id, start_event_timestamp: 5.years.ago, end_event_timestamp: 2.years.ago) } # duration: 3 years diff --git a/spec/lib/gitlab/analytics/cycle_analytics/average_spec.rb b/spec/lib/gitlab/analytics/cycle_analytics/average_spec.rb index e2fdd4918d5..de325454b34 100644 --- a/spec/lib/gitlab/analytics/cycle_analytics/average_spec.rb +++ b/spec/lib/gitlab/analytics/cycle_analytics/average_spec.rb @@ -21,7 +21,7 @@ RSpec.describe Gitlab::Analytics::CycleAnalytics::Average do let(:stage) do build( - :cycle_analytics_project_stage, + :cycle_analytics_stage, start_event_identifier: Gitlab::Analytics::CycleAnalytics::StageEvents::IssueCreated.identifier, end_event_identifier: Gitlab::Analytics::CycleAnalytics::StageEvents::IssueFirstMentionedInCommit.identifier, project: project diff --git a/spec/lib/gitlab/analytics/cycle_analytics/base_query_builder_spec.rb b/spec/lib/gitlab/analytics/cycle_analytics/base_query_builder_spec.rb index e83ee0c6b75..59b2bacea50 100644 --- a/spec/lib/gitlab/analytics/cycle_analytics/base_query_builder_spec.rb +++ b/spec/lib/gitlab/analytics/cycle_analytics/base_query_builder_spec.rb @@ -10,10 +10,10 @@ RSpec.describe Gitlab::Analytics::CycleAnalytics::BaseQueryBuilder do let(:params) { { current_user: user } } let(:records) do - stage = build(:cycle_analytics_project_stage, { + stage = build(:cycle_analytics_stage, { start_event_identifier: :merge_request_created, end_event_identifier: :merge_request_merged, - project: project + namespace: project.reload.project_namespace }) described_class.new(stage: stage, params: params).build.to_a end diff --git a/spec/lib/gitlab/analytics/cycle_analytics/median_spec.rb b/spec/lib/gitlab/analytics/cycle_analytics/median_spec.rb index 4db5d64164e..39cfab49f54 100644 --- a/spec/lib/gitlab/analytics/cycle_analytics/median_spec.rb +++ b/spec/lib/gitlab/analytics/cycle_analytics/median_spec.rb @@ -9,10 +9,10 @@ RSpec.describe Gitlab::Analytics::CycleAnalytics::Median do let(:stage) do build( - :cycle_analytics_project_stage, + :cycle_analytics_stage, start_event_identifier: Gitlab::Analytics::CycleAnalytics::StageEvents::MergeRequestCreated.identifier, end_event_identifier: Gitlab::Analytics::CycleAnalytics::StageEvents::MergeRequestMerged.identifier, - project: project + namespace: project.reload.project_namespace ) end diff --git a/spec/lib/gitlab/analytics/cycle_analytics/records_fetcher_spec.rb b/spec/lib/gitlab/analytics/cycle_analytics/records_fetcher_spec.rb index 7f70a4cfc4e..e9a9dfeca82 100644 --- a/spec/lib/gitlab/analytics/cycle_analytics/records_fetcher_spec.rb +++ b/spec/lib/gitlab/analytics/cycle_analytics/records_fetcher_spec.rb @@ -58,7 +58,7 @@ RSpec.describe Gitlab::Analytics::CycleAnalytics::RecordsFetcher do let_it_be(:issue2) { create(:issue, project: project, confidential: true) } let(:stage) do - build(:cycle_analytics_project_stage, { + build(:cycle_analytics_stage, { start_event_identifier: :plan_stage_start, end_event_identifier: :issue_first_mentioned_in_commit, project: project @@ -88,7 +88,7 @@ RSpec.describe Gitlab::Analytics::CycleAnalytics::RecordsFetcher do let(:mr1) { create(:merge_request, created_at: 5.days.ago, source_project: project, allow_broken: true) } let(:mr2) { create(:merge_request, created_at: 4.days.ago, source_project: project, allow_broken: true) } let(:stage) do - build(:cycle_analytics_project_stage, { + build(:cycle_analytics_stage, { start_event_identifier: :merge_request_created, end_event_identifier: :merge_request_merged, project: project @@ -110,10 +110,10 @@ RSpec.describe Gitlab::Analytics::CycleAnalytics::RecordsFetcher do let_it_be(:issue3) { create(:issue, project: project) } let(:stage) do - build(:cycle_analytics_project_stage, { + build(:cycle_analytics_stage, { start_event_identifier: :plan_stage_start, end_event_identifier: :issue_first_mentioned_in_commit, - project: project + namespace: project.project_namespace }) end diff --git a/spec/lib/gitlab/analytics/cycle_analytics/sorting_spec.rb b/spec/lib/gitlab/analytics/cycle_analytics/sorting_spec.rb index daf85ea379a..d0ada3d195b 100644 --- a/spec/lib/gitlab/analytics/cycle_analytics/sorting_spec.rb +++ b/spec/lib/gitlab/analytics/cycle_analytics/sorting_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' RSpec.describe Gitlab::Analytics::CycleAnalytics::Sorting do - let(:stage) { build(:cycle_analytics_project_stage, start_event_identifier: :merge_request_created, end_event_identifier: :merge_request_merged) } + let(:stage) { build(:cycle_analytics_stage, start_event_identifier: :merge_request_created, end_event_identifier: :merge_request_merged) } subject(:order_values) { described_class.new(query: MergeRequest.joins(:metrics), stage: stage).apply(sort, direction).order_values } diff --git a/spec/migrations/20230112141236_schedule_vulnerabilities_feedback_migration2_spec.rb b/spec/migrations/20230203122602_schedule_vulnerabilities_feedback_migration3_spec.rb index 0e0f08fea0e..91604b1f57c 100644 --- a/spec/migrations/20230112141236_schedule_vulnerabilities_feedback_migration2_spec.rb +++ b/spec/migrations/20230203122602_schedule_vulnerabilities_feedback_migration3_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' require_migration! -RSpec.describe ScheduleVulnerabilitiesFeedbackMigration2, feature_category: :vulnerability_management do +RSpec.describe ScheduleVulnerabilitiesFeedbackMigration3, feature_category: :vulnerability_management do let(:migration) { described_class::MIGRATION } describe '#up' do diff --git a/spec/models/analytics/cycle_analytics/project_stage_spec.rb b/spec/models/analytics/cycle_analytics/project_stage_spec.rb deleted file mode 100644 index 1e7335987a4..00000000000 --- a/spec/models/analytics/cycle_analytics/project_stage_spec.rb +++ /dev/null @@ -1,50 +0,0 @@ -# frozen_string_literal: true - -require 'spec_helper' - -RSpec.describe Analytics::CycleAnalytics::ProjectStage do - describe 'associations' do - it { is_expected.to belong_to(:project).required } - end - - it 'default stages must be valid' do - project = build(:project) - - Gitlab::Analytics::CycleAnalytics::DefaultStages.all.each do |params| - stage = described_class.new(params.merge(project: project)) - expect(stage).to be_valid - end - end - - it_behaves_like 'value stream analytics stage' do - let(:factory) { :cycle_analytics_project_stage } - let(:parent) { build(:project) } - let(:parent_name) { :project } - end - - describe '.distinct_stages_within_hierarchy' do - let_it_be(:top_level_group) { create(:group) } - let_it_be(:sub_group_1) { create(:group, parent: top_level_group) } - let_it_be(:sub_group_2) { create(:group, parent: sub_group_1) } - - let_it_be(:project_1) { create(:project, group: sub_group_1) } - let_it_be(:project_2) { create(:project, group: sub_group_2) } - let_it_be(:project_3) { create(:project, group: top_level_group) } - - let_it_be(:stage1) { create(:cycle_analytics_project_stage, project: project_1, start_event_identifier: :issue_created, end_event_identifier: :issue_deployed_to_production) } - let_it_be(:stage2) { create(:cycle_analytics_project_stage, project: project_3, start_event_identifier: :issue_created, end_event_identifier: :issue_deployed_to_production) } - - let_it_be(:stage3) { create(:cycle_analytics_project_stage, project: project_1, start_event_identifier: :merge_request_created, end_event_identifier: :merge_request_merged) } - let_it_be(:stage4) { create(:cycle_analytics_project_stage, project: project_3, start_event_identifier: :merge_request_created, end_event_identifier: :merge_request_merged) } - - subject(:distinct_start_and_end_event_identifiers) { described_class.distinct_stages_within_hierarchy(top_level_group).to_a.pluck(:start_event_identifier, :end_event_identifier) } - - it 'returns distinct stages by start and end events (using stage_event_hash_id)' do - expect(distinct_start_and_end_event_identifiers).to match_array( - [ - %w[issue_created issue_deployed_to_production], - %w[merge_request_created merge_request_merged] - ]) - end - end -end diff --git a/spec/models/analytics/cycle_analytics/project_value_stream_spec.rb b/spec/models/analytics/cycle_analytics/project_value_stream_spec.rb deleted file mode 100644 index d84ecedc634..00000000000 --- a/spec/models/analytics/cycle_analytics/project_value_stream_spec.rb +++ /dev/null @@ -1,39 +0,0 @@ -# frozen_string_literal: true - -require 'spec_helper' - -RSpec.describe Analytics::CycleAnalytics::ProjectValueStream, type: :model do - describe 'associations' do - it { is_expected.to belong_to(:project) } - it { is_expected.to have_many(:stages) } - end - - describe 'validations' do - it { is_expected.to validate_presence_of(:project) } - it { is_expected.to validate_presence_of(:name) } - it { is_expected.to validate_length_of(:name).is_at_most(100) } - - it 'validates uniqueness of name' do - project = create(:project) - create(:cycle_analytics_project_value_stream, name: 'test', project: project) - - value_stream = build(:cycle_analytics_project_value_stream, name: 'test', project: project) - - expect(value_stream).to be_invalid - expect(value_stream.errors.messages).to eq(name: [I18n.t('errors.messages.taken')]) - end - end - - it 'is not custom' do - expect(described_class.new).not_to be_custom - end - - describe '.build_default_value_stream' do - it 'builds the default value stream' do - project = build(:project) - - value_stream = described_class.build_default_value_stream(project) - expect(value_stream.name).to eq('default') - end - end -end diff --git a/spec/models/analytics/cycle_analytics/stage_event_hash_spec.rb b/spec/models/analytics/cycle_analytics/stage_event_hash_spec.rb index a24f237fa9d..43db610af5c 100644 --- a/spec/models/analytics/cycle_analytics/stage_event_hash_spec.rb +++ b/spec/models/analytics/cycle_analytics/stage_event_hash_spec.rb @@ -7,7 +7,6 @@ RSpec.describe Analytics::CycleAnalytics::StageEventHash, type: :model do let(:hash_sha256) { 'does_not_matter' } describe 'associations' do - it { is_expected.to have_many(:cycle_analytics_project_stages) } it { is_expected.to have_many(:cycle_analytics_stages) } end @@ -31,7 +30,7 @@ RSpec.describe Analytics::CycleAnalytics::StageEventHash, type: :model do end describe '.cleanup_if_unused' do - it 'removes the record if there is no project or group stages with given stage events hash' do + it 'removes the record if there is no stages with given stage events hash' do described_class.cleanup_if_unused(stage_event_hash.id) expect(described_class.find_by_id(stage_event_hash.id)).to be_nil diff --git a/spec/models/cycle_analytics/project_level_stage_adapter_spec.rb b/spec/models/cycle_analytics/project_level_stage_adapter_spec.rb index ee13aae50dc..1516de8defd 100644 --- a/spec/models/cycle_analytics/project_level_stage_adapter_spec.rb +++ b/spec/models/cycle_analytics/project_level_stage_adapter_spec.rb @@ -10,11 +10,14 @@ RSpec.describe CycleAnalytics::ProjectLevelStageAdapter, type: :model do end end - let_it_be(:project) { merge_request.target_project } + let_it_be(:project) { merge_request.target_project.reload } let(:stage) do - params = Gitlab::Analytics::CycleAnalytics::DefaultStages.find_by_name!(stage_name).merge(project: project) - Analytics::CycleAnalytics::ProjectStage.new(params) + params = Gitlab::Analytics::CycleAnalytics::DefaultStages + .find_by_name!(stage_name) + .merge(namespace: project.project_namespace) + + Analytics::CycleAnalytics::Stage.new(params) end around do |example| diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb index 9d6ab7d6137..cd7b46d40ae 100644 --- a/spec/models/project_spec.rb +++ b/spec/models/project_spec.rb @@ -121,8 +121,6 @@ RSpec.describe Project, factory_default: :keep, feature_category: :projects do it { is_expected.to have_many(:lfs_file_locks) } it { is_expected.to have_many(:project_deploy_tokens) } it { is_expected.to have_many(:deploy_tokens).through(:project_deploy_tokens) } - it { is_expected.to have_many(:cycle_analytics_stages).inverse_of(:project) } - it { is_expected.to have_many(:value_streams).inverse_of(:project) } it { is_expected.to have_many(:external_pull_requests) } it { is_expected.to have_many(:sourced_pipelines) } it { is_expected.to have_many(:source_pipelines) } diff --git a/spec/serializers/analytics/cycle_analytics/stage_entity_spec.rb b/spec/serializers/analytics/cycle_analytics/stage_entity_spec.rb index 8b45e8a64fc..7c53acbf168 100644 --- a/spec/serializers/analytics/cycle_analytics/stage_entity_spec.rb +++ b/spec/serializers/analytics/cycle_analytics/stage_entity_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' RSpec.describe Analytics::CycleAnalytics::StageEntity do - let(:stage) { build(:cycle_analytics_project_stage, start_event_identifier: :merge_request_created, end_event_identifier: :merge_request_merged) } + let(:stage) { build(:cycle_analytics_stage, start_event_identifier: :merge_request_created, end_event_identifier: :merge_request_merged) } subject(:entity_json) { described_class.new(Analytics::CycleAnalytics::StagePresenter.new(stage)).as_json } diff --git a/spec/support/helpers/ci/template_helpers.rb b/spec/support/helpers/ci/template_helpers.rb index 2cdd242ac22..cd3ab4bd82d 100644 --- a/spec/support/helpers/ci/template_helpers.rb +++ b/spec/support/helpers/ci/template_helpers.rb @@ -13,14 +13,21 @@ module Ci def public_image_manifest(registry, repository, reference) token = public_image_repository_token(registry, repository) + headers = { + 'Authorization' => "Bearer #{token}", + 'Accept' => 'application/vnd.docker.distribution.manifest.list.v2+json, application/vnd.oci.image.index.v1+json' + } response = with_net_connect_allowed do - Gitlab::HTTP.get(image_manifest_url(registry, repository, reference), - headers: { 'Authorization' => "Bearer #{token}" }) + Gitlab::HTTP.get(image_manifest_url(registry, repository, reference), headers: headers) end - return unless response.success? - - Gitlab::Json.parse(response.body) + if response.success? + Gitlab::Json.parse(response.body) + elsif response.not_found? + nil + else + raise "Could not retrieve manifest: #{response.body}" + end end def public_image_repository_token(registry, repository) @@ -31,17 +38,17 @@ module Ci Gitlab::HTTP.get(image_manifest_url(registry, repository, 'latest')) end - return unless response.unauthorized? + raise 'Unauthorized' unless response.unauthorized? www_authenticate = response.headers['www-authenticate'] - return unless www_authenticate + raise 'Missing www-authenticate' unless www_authenticate realm, service, scope = www_authenticate.split(',').map { |s| s[/\w+="(.*)"/, 1] } token_response = with_net_connect_allowed do Gitlab::HTTP.get(realm, query: { service: service, scope: scope }) end - return unless token_response.success? + raise "Could not get token: #{token_response.body}" unless token_response.success? token_response['token'] end diff --git a/spec/support/rspec_order_todo.yml b/spec/support/rspec_order_todo.yml index 58411fc3c4f..2259a20cd74 100644 --- a/spec/support/rspec_order_todo.yml +++ b/spec/support/rspec_order_todo.yml @@ -1636,7 +1636,6 @@ - './ee/spec/models/allowed_email_domain_spec.rb' - './ee/spec/models/analytics/cycle_analytics/aggregation_context_spec.rb' - './ee/spec/models/analytics/cycle_analytics/group_level_spec.rb' -- './ee/spec/models/analytics/cycle_analytics/project_stage_spec.rb' - './ee/spec/models/analytics/cycle_analytics/runtime_limiter_spec.rb' - './ee/spec/models/analytics/devops_adoption/enabled_namespace_spec.rb' - './ee/spec/models/analytics/devops_adoption/snapshot_spec.rb' @@ -7729,7 +7728,6 @@ - './spec/models/analytics/cycle_analytics/aggregation_spec.rb' - './spec/models/analytics/cycle_analytics/issue_stage_event_spec.rb' - './spec/models/analytics/cycle_analytics/merge_request_stage_event_spec.rb' -- './spec/models/analytics/cycle_analytics/project_stage_spec.rb' - './spec/models/analytics/cycle_analytics/project_value_stream_spec.rb' - './spec/models/analytics/cycle_analytics/stage_event_hash_spec.rb' - './spec/models/analytics/usage_trends/measurement_spec.rb' diff --git a/spec/workers/projects/refresh_build_artifacts_size_statistics_worker_spec.rb b/spec/workers/projects/refresh_build_artifacts_size_statistics_worker_spec.rb index 00c45255316..99627ff1ad2 100644 --- a/spec/workers/projects/refresh_build_artifacts_size_statistics_worker_spec.rb +++ b/spec/workers/projects/refresh_build_artifacts_size_statistics_worker_spec.rb @@ -17,12 +17,14 @@ RSpec.describe Projects::RefreshBuildArtifactsSizeStatisticsWorker do build( :project_build_artifacts_size_refresh, :running, + id: 99, project_id: 77, last_job_artifact_id: 123 ) end it 'logs refresh information' do + expect(worker).to receive(:log_extra_metadata_on_done).with(:refresh_id, refresh.id) expect(worker).to receive(:log_extra_metadata_on_done).with(:project_id, refresh.project_id) expect(worker).to receive(:log_extra_metadata_on_done).with(:last_job_artifact_id, refresh.last_job_artifact_id) expect(worker).to receive(:log_extra_metadata_on_done).with(:last_batch, refresh.destroyed?) |