Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2021-05-19 18:44:42 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2021-05-19 18:44:42 +0300
commit4555e1b21c365ed8303ffb7a3325d773c9b8bf31 (patch)
tree5423a1c7516cffe36384133ade12572cf709398d /spec/serializers
parente570267f2f6b326480d284e0164a6464ba4081bc (diff)
Add latest changes from gitlab-org/gitlab@13-12-stable-eev13.12.0-rc42
Diffstat (limited to 'spec/serializers')
-rw-r--r--spec/serializers/analytics/cycle_analytics/stage_entity_spec.rb14
-rw-r--r--spec/serializers/ci/codequality_mr_diff_entity_spec.rb10
-rw-r--r--spec/serializers/ci/codequality_mr_diff_report_serializer_spec.rb10
-rw-r--r--spec/serializers/ci/downloadable_artifact_entity_spec.rb28
-rw-r--r--spec/serializers/ci/downloadable_artifact_serializer_spec.rb17
-rw-r--r--spec/serializers/ci/pipeline_entity_spec.rb12
-rw-r--r--spec/serializers/context_commits_diff_entity_spec.rb25
-rw-r--r--spec/serializers/diffs_metadata_entity_spec.rb2
-rw-r--r--spec/serializers/group_issuable_autocomplete_entity_spec.rb17
-rw-r--r--spec/serializers/issue_entity_spec.rb4
-rw-r--r--spec/serializers/job_entity_spec.rb4
-rw-r--r--spec/serializers/member_serializer_spec.rb33
-rw-r--r--spec/serializers/merge_requests/pipeline_entity_spec.rb2
-rw-r--r--spec/serializers/pipeline_details_entity_spec.rb18
-rw-r--r--spec/serializers/pipeline_serializer_spec.rb9
-rw-r--r--spec/serializers/test_case_entity_spec.rb44
16 files changed, 151 insertions, 98 deletions
diff --git a/spec/serializers/analytics/cycle_analytics/stage_entity_spec.rb b/spec/serializers/analytics/cycle_analytics/stage_entity_spec.rb
new file mode 100644
index 00000000000..90cc7f7827b
--- /dev/null
+++ b/spec/serializers/analytics/cycle_analytics/stage_entity_spec.rb
@@ -0,0 +1,14 @@
+# frozen_string_literal: true
+
+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) }
+
+ subject(:entity_json) { described_class.new(Analytics::CycleAnalytics::StagePresenter.new(stage)).as_json }
+
+ it 'exposes start and end event descriptions' do
+ expect(entity_json).to have_key(:start_event_html_description)
+ expect(entity_json).to have_key(:end_event_html_description)
+ end
+end
diff --git a/spec/serializers/ci/codequality_mr_diff_entity_spec.rb b/spec/serializers/ci/codequality_mr_diff_entity_spec.rb
index 82708908d95..4f161c36b06 100644
--- a/spec/serializers/ci/codequality_mr_diff_entity_spec.rb
+++ b/spec/serializers/ci/codequality_mr_diff_entity_spec.rb
@@ -4,18 +4,18 @@ require 'spec_helper'
RSpec.describe Ci::CodequalityMrDiffEntity do
let(:entity) { described_class.new(mr_diff_report) }
- let(:mr_diff_report) { Gitlab::Ci::Reports::CodequalityMrDiff.new(codequality_report) }
+ let(:mr_diff_report) { Gitlab::Ci::Reports::CodequalityMrDiff.new(codequality_report.all_degradations) }
let(:codequality_report) { Gitlab::Ci::Reports::CodequalityReports.new }
- let(:degradation_1) { build(:codequality_degradation_1) }
- let(:degradation_2) { build(:codequality_degradation_2) }
+ let(:major) { build(:codequality_degradation, :major) }
+ let(:minor) { build(:codequality_degradation, :minor) }
describe '#as_json' do
subject(:report) { entity.as_json }
context 'when quality report has degradations' do
before do
- codequality_report.add_degradation(degradation_1)
- codequality_report.add_degradation(degradation_2)
+ codequality_report.add_degradation(major)
+ codequality_report.add_degradation(minor)
end
it 'contains correct codequality mr diff report', :aggregate_failures do
diff --git a/spec/serializers/ci/codequality_mr_diff_report_serializer_spec.rb b/spec/serializers/ci/codequality_mr_diff_report_serializer_spec.rb
index 906ca36041f..6afbc3b8353 100644
--- a/spec/serializers/ci/codequality_mr_diff_report_serializer_spec.rb
+++ b/spec/serializers/ci/codequality_mr_diff_report_serializer_spec.rb
@@ -4,18 +4,18 @@ require 'spec_helper'
RSpec.describe Ci::CodequalityMrDiffReportSerializer do
let(:serializer) { described_class.new.represent(mr_diff_report) }
- let(:mr_diff_report) { Gitlab::Ci::Reports::CodequalityMrDiff.new(codequality_report) }
+ let(:mr_diff_report) { Gitlab::Ci::Reports::CodequalityMrDiff.new(codequality_report.all_degradations) }
let(:codequality_report) { Gitlab::Ci::Reports::CodequalityReports.new }
- let(:degradation_1) { build(:codequality_degradation_1) }
- let(:degradation_2) { build(:codequality_degradation_2) }
+ let(:major) { build(:codequality_degradation, :major) }
+ let(:minor) { build(:codequality_degradation, :minor) }
describe '#to_json' do
subject { serializer.as_json }
context 'when quality report has degradations' do
before do
- codequality_report.add_degradation(degradation_1)
- codequality_report.add_degradation(degradation_2)
+ codequality_report.add_degradation(major)
+ codequality_report.add_degradation(minor)
end
it 'matches the schema' do
diff --git a/spec/serializers/ci/downloadable_artifact_entity_spec.rb b/spec/serializers/ci/downloadable_artifact_entity_spec.rb
new file mode 100644
index 00000000000..34a271e7422
--- /dev/null
+++ b/spec/serializers/ci/downloadable_artifact_entity_spec.rb
@@ -0,0 +1,28 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe Ci::DownloadableArtifactEntity do
+ let(:pipeline) { create(:ci_pipeline, :with_codequality_reports) }
+ let(:user) { create(:user) }
+ let(:request) { EntityRequest.new({ current_user: user }) }
+ let(:entity) { described_class.new(pipeline, request: request) }
+
+ describe '#as_json' do
+ subject { entity.as_json }
+
+ it 'contains required fields', :aggregate_failures do
+ expect(subject).to include(:artifacts)
+ expect(subject[:artifacts].size).to eq(1)
+ end
+
+ context 'when user cannot read job artifact' do
+ let!(:build) { create(:ci_build, :success, :artifacts, :non_public_artifacts, pipeline: pipeline) }
+
+ it 'returns only artifacts readable by user', :aggregate_failures do
+ expect(subject[:artifacts].size).to eq(1)
+ expect(subject[:artifacts].first[:name]).to eq("test:codequality")
+ end
+ end
+ end
+end
diff --git a/spec/serializers/ci/downloadable_artifact_serializer_spec.rb b/spec/serializers/ci/downloadable_artifact_serializer_spec.rb
new file mode 100644
index 00000000000..90f159a06f9
--- /dev/null
+++ b/spec/serializers/ci/downloadable_artifact_serializer_spec.rb
@@ -0,0 +1,17 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe Ci::DownloadableArtifactSerializer do
+ let(:pipeline) { create(:ci_pipeline, :with_codequality_reports) }
+ let(:user) { create(:user) }
+ let(:serializer) { described_class.new(current_user: user).represent(pipeline) }
+
+ describe '#as_json' do
+ subject { serializer.as_json }
+
+ it 'matches schema' do
+ expect(subject).to match_schema('entities/downloadable_artifact')
+ end
+ end
+end
diff --git a/spec/serializers/ci/pipeline_entity_spec.rb b/spec/serializers/ci/pipeline_entity_spec.rb
index 83ea0d649e8..054406e4e65 100644
--- a/spec/serializers/ci/pipeline_entity_spec.rb
+++ b/spec/serializers/ci/pipeline_entity_spec.rb
@@ -155,7 +155,7 @@ RSpec.describe Ci::PipelineEntity do
it 'has a correct failure reason' do
expect(subject[:failure_reason])
- .to eq 'CI/CD YAML configuration error!'
+ .to eq 'The pipeline failed due to an error on the CI/CD configuration file.'
end
end
@@ -239,23 +239,23 @@ RSpec.describe Ci::PipelineEntity do
end
context 'when pipeline has failed builds' do
- let_it_be(:pipeline) { create(:ci_pipeline, user: user) }
+ let_it_be(:pipeline) { create(:ci_pipeline, project: project, user: user) }
let_it_be(:build) { create(:ci_build, :success, pipeline: pipeline) }
let_it_be(:failed_1) { create(:ci_build, :failed, pipeline: pipeline) }
let_it_be(:failed_2) { create(:ci_build, :failed, pipeline: pipeline) }
context 'when the user can retry the pipeline' do
- it 'exposes these failed builds' do
- allow(entity).to receive(:can_retry?).and_return(true)
+ before do
+ project.add_maintainer(user)
+ end
+ it 'exposes these failed builds' do
expect(subject[:failed_builds].map { |b| b[:id] }).to contain_exactly(failed_1.id, failed_2.id)
end
end
context 'when the user cannot retry the pipeline' do
it 'is nil' do
- allow(entity).to receive(:can_retry?).and_return(false)
-
expect(subject[:failed_builds]).to be_nil
end
end
diff --git a/spec/serializers/context_commits_diff_entity_spec.rb b/spec/serializers/context_commits_diff_entity_spec.rb
new file mode 100644
index 00000000000..e8f38527f5b
--- /dev/null
+++ b/spec/serializers/context_commits_diff_entity_spec.rb
@@ -0,0 +1,25 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe ContextCommitsDiffEntity do
+ let_it_be(:merge_request) { create(:merge_request) }
+ let_it_be(:mrcc1) { create(:merge_request_context_commit, merge_request: merge_request, sha: "cfe32cf61b73a0d5e9f13e774abde7ff789b1660") }
+ let_it_be(:mrcc2) { create(:merge_request_context_commit, merge_request: merge_request, sha: "ae73cb07c9eeaf35924a10f713b364d32b2dd34f") }
+
+ context 'as json' do
+ subject { ContextCommitsDiffEntity.represent(merge_request.context_commits_diff).as_json }
+
+ it 'exposes commits_count' do
+ expect(subject[:commits_count]).to eq(2)
+ end
+
+ it 'exposes showing_context_commits_diff' do
+ expect(subject).to have_key(:showing_context_commits_diff)
+ end
+
+ it 'exposes diffs_path' do
+ expect(subject[:diffs_path]).to eq(Gitlab::Routing.url_helpers.diffs_project_merge_request_path(merge_request.project, merge_request, only_context_commits: true))
+ end
+ end
+end
diff --git a/spec/serializers/diffs_metadata_entity_spec.rb b/spec/serializers/diffs_metadata_entity_spec.rb
index f6993d4652e..b1cbe7e216e 100644
--- a/spec/serializers/diffs_metadata_entity_spec.rb
+++ b/spec/serializers/diffs_metadata_entity_spec.rb
@@ -28,7 +28,7 @@ RSpec.describe DiffsMetadataEntity do
:start_version, :latest_diff, :latest_version_path,
:added_lines, :removed_lines, :render_overflow_warning,
:email_patch_path, :plain_diff_path,
- :merge_request_diffs, :context_commits,
+ :merge_request_diffs, :context_commits, :context_commits_diff,
:definition_path_prefix, :source_branch_exists,
:can_merge, :conflict_resolution_path, :has_conflicts,
:project_name, :project_path, :user_full_name, :username,
diff --git a/spec/serializers/group_issuable_autocomplete_entity_spec.rb b/spec/serializers/group_issuable_autocomplete_entity_spec.rb
new file mode 100644
index 00000000000..86ef9dea23b
--- /dev/null
+++ b/spec/serializers/group_issuable_autocomplete_entity_spec.rb
@@ -0,0 +1,17 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe GroupIssuableAutocompleteEntity do
+ let(:group) { build_stubbed(:group) }
+ let(:project) { build_stubbed(:project, group: group) }
+ let(:issue) { build_stubbed(:issue, project: project) }
+
+ describe '#represent' do
+ subject { described_class.new(issue, parent_group: group).as_json }
+
+ it 'includes the iid, title, and reference' do
+ expect(subject).to include(:iid, :title, :reference)
+ end
+ end
+end
diff --git a/spec/serializers/issue_entity_spec.rb b/spec/serializers/issue_entity_spec.rb
index 82ea26fae40..76f8cf644c6 100644
--- a/spec/serializers/issue_entity_spec.rb
+++ b/spec/serializers/issue_entity_spec.rb
@@ -29,7 +29,7 @@ RSpec.describe IssueEntity do
before do
project.add_developer(member)
public_project.add_developer(member)
- Issues::MoveService.new(public_project, member).execute(issue, project)
+ Issues::MoveService.new(project: public_project, current_user: member).execute(issue, project)
end
context 'when user cannot read target project' do
@@ -61,7 +61,7 @@ RSpec.describe IssueEntity do
before do
Issues::DuplicateService
- .new(project, member)
+ .new(project: project, current_user: member)
.execute(issue, new_issue)
end
diff --git a/spec/serializers/job_entity_spec.rb b/spec/serializers/job_entity_spec.rb
index 1cbf1914c0c..f31cfcb8499 100644
--- a/spec/serializers/job_entity_spec.rb
+++ b/spec/serializers/job_entity_spec.rb
@@ -21,6 +21,10 @@ RSpec.describe JobEntity do
subject { entity.as_json }
+ it 'contains complete to indicate if a pipeline is completed' do
+ expect(subject).to include(:complete)
+ end
+
it 'contains paths to job page action' do
expect(subject).to include(:build_path)
end
diff --git a/spec/serializers/member_serializer_spec.rb b/spec/serializers/member_serializer_spec.rb
index f7415214e95..687d69f86ea 100644
--- a/spec/serializers/member_serializer_spec.rb
+++ b/spec/serializers/member_serializer_spec.rb
@@ -30,39 +30,6 @@ RSpec.describe MemberSerializer do
.from(nil).to(true)
.and change(group_member, :last_blocked_owner).from(nil).to(false)
end
-
- context "with LastGroupOwnerAssigner query improvements" do
- it "avoids N+1 database queries for last group owner assignment in MembersPresenter" do
- group_member = create(:group_member, group: group)
- control_count = ActiveRecord::QueryRecorder.new { member_last_owner_with_preload([group_member]) }.count
- group_members = create_list(:group_member, 3, group: group)
-
- expect { member_last_owner_with_preload(group_members) }.not_to exceed_query_limit(control_count)
- end
-
- it "avoids N+1 database queries for last blocked owner assignment in MembersPresenter" do
- group_member = create(:group_member, group: group)
- control_count = ActiveRecord::QueryRecorder.new { member_last_blocked_owner_with_preload([group_member]) }.count
- group_members = create_list(:group_member, 3, group: group)
-
- expect { member_last_blocked_owner_with_preload(group_members) }.not_to exceed_query_limit(control_count)
- end
-
- def member_last_owner_with_preload(members)
- assigner_with_preload(members)
- members.map { |m| group.member_last_owner?(m) }
- end
-
- def member_last_blocked_owner_with_preload(members)
- assigner_with_preload(members)
- members.map { |m| group.member_last_blocked_owner?(m) }
- end
-
- def assigner_with_preload(members)
- MembersPreloader.new(members).preload_all
- Members::LastGroupOwnerAssigner.new(group, members).execute
- end
- end
end
context 'project member' do
diff --git a/spec/serializers/merge_requests/pipeline_entity_spec.rb b/spec/serializers/merge_requests/pipeline_entity_spec.rb
index 03a049401c1..6970b547f12 100644
--- a/spec/serializers/merge_requests/pipeline_entity_spec.rb
+++ b/spec/serializers/merge_requests/pipeline_entity_spec.rb
@@ -42,6 +42,4 @@ RSpec.describe MergeRequests::PipelineEntity do
expect(entity.as_json).not_to include(:coverage)
end
end
-
- it_behaves_like 'public artifacts'
end
diff --git a/spec/serializers/pipeline_details_entity_spec.rb b/spec/serializers/pipeline_details_entity_spec.rb
index 5756656d146..128f1922887 100644
--- a/spec/serializers/pipeline_details_entity_spec.rb
+++ b/spec/serializers/pipeline_details_entity_spec.rb
@@ -32,7 +32,7 @@ RSpec.describe PipelineDetailsEntity do
expect(subject[:details])
.to include :duration, :finished_at
expect(subject[:details])
- .to include :stages, :artifacts, :manual_actions, :scheduled_actions
+ .to include :stages, :manual_actions, :scheduled_actions
expect(subject[:details][:status]).to include :icon, :favicon, :text, :label
end
@@ -70,6 +70,20 @@ RSpec.describe PipelineDetailsEntity do
expect(subject[:flags][:retryable]).to eq false
end
end
+
+ it 'does not contain code_quality_build_path in details' do
+ expect(subject[:details]).not_to include :code_quality_build_path
+ end
+
+ context 'when option code_quality_walkthrough is set and pipeline is a success' do
+ let(:entity) do
+ described_class.represent(pipeline, request: request, code_quality_walkthrough: true)
+ end
+
+ it 'contains details.code_quality_build_path' do
+ expect(subject[:details]).to include :code_quality_build_path
+ end
+ end
end
context 'when pipeline is cancelable' do
@@ -184,7 +198,5 @@ RSpec.describe PipelineDetailsEntity do
expect(source_jobs[child_pipeline.id][:name]).to eq('child')
end
end
-
- it_behaves_like 'public artifacts'
end
end
diff --git a/spec/serializers/pipeline_serializer_spec.rb b/spec/serializers/pipeline_serializer_spec.rb
index 6028da301f3..1111290cade 100644
--- a/spec/serializers/pipeline_serializer_spec.rb
+++ b/spec/serializers/pipeline_serializer_spec.rb
@@ -155,7 +155,7 @@ RSpec.describe PipelineSerializer do
it 'verifies number of queries', :request_store do
recorded = ActiveRecord::QueryRecorder.new { subject }
- expected_queries = Gitlab.ee? ? 39 : 36
+ expected_queries = Gitlab.ee? ? 33 : 30
expect(recorded.count).to be_within(2).of(expected_queries)
expect(recorded.cached_count).to eq(0)
@@ -176,7 +176,7 @@ RSpec.describe PipelineSerializer do
# pipeline. With the same ref this check is cached but if refs are
# different then there is an extra query per ref
# https://gitlab.com/gitlab-org/gitlab-foss/issues/46368
- expected_queries = Gitlab.ee? ? 42 : 39
+ expected_queries = Gitlab.ee? ? 36 : 33
expect(recorded.count).to be_within(2).of(expected_queries)
expect(recorded.cached_count).to eq(0)
@@ -202,7 +202,7 @@ RSpec.describe PipelineSerializer do
# Existing numbers are high and require performance optimization
# Ongoing issue:
# https://gitlab.com/gitlab-org/gitlab/-/issues/225156
- expected_queries = Gitlab.ee? ? 82 : 76
+ expected_queries = Gitlab.ee? ? 77 : 70
expect(recorded.count).to be_within(2).of(expected_queries)
expect(recorded.cached_count).to eq(0)
@@ -221,8 +221,7 @@ RSpec.describe PipelineSerializer do
create(:ci_build, :scheduled, project: project, environment: env.name)
recorded = ActiveRecord::QueryRecorder.new { subject }
- expected_queries = Gitlab.ee? ? 61 : 57
-
+ expected_queries = Gitlab.ee? ? 56 : 52
expect(recorded.count).to be_within(1).of(expected_queries)
expect(recorded.cached_count).to eq(0)
end
diff --git a/spec/serializers/test_case_entity_spec.rb b/spec/serializers/test_case_entity_spec.rb
index e2b0f722f41..cdeefd2fec5 100644
--- a/spec/serializers/test_case_entity_spec.rb
+++ b/spec/serializers/test_case_entity_spec.rb
@@ -41,47 +41,19 @@ RSpec.describe TestCaseEntity do
end
end
- context 'when feature is enabled' do
- before do
- stub_feature_flags(junit_pipeline_screenshots_view: true)
- end
-
- context 'when attachment is present' do
- let(:test_case) { build(:report_test_case, :failed_with_attachment, job: job) }
-
- it 'returns the attachment_url' do
- expect(subject).to include(:attachment_url)
- end
- end
-
- context 'when attachment is not present' do
- let(:test_case) { build(:report_test_case, job: job) }
+ context 'when attachment is present' do
+ let(:test_case) { build(:report_test_case, :failed_with_attachment, job: job) }
- it 'returns a nil attachment_url' do
- expect(subject[:attachment_url]).to be_nil
- end
+ it 'returns the attachment_url' do
+ expect(subject).to include(:attachment_url)
end
end
- context 'when feature is disabled' do
- before do
- stub_feature_flags(junit_pipeline_screenshots_view: false)
- end
-
- context 'when attachment is present' do
- let(:test_case) { build(:report_test_case, :failed_with_attachment, job: job) }
-
- it 'returns no attachment_url' do
- expect(subject).not_to include(:attachment_url)
- end
- end
-
- context 'when attachment is not present' do
- let(:test_case) { build(:report_test_case, job: job) }
+ context 'when attachment is not present' do
+ let(:test_case) { build(:report_test_case, job: job) }
- it 'returns no attachment_url' do
- expect(subject).not_to include(:attachment_url)
- end
+ it 'returns a nil attachment_url' do
+ expect(subject[:attachment_url]).to be_nil
end
end
end