diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-08-20 18:42:06 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-08-20 18:42:06 +0000 |
commit | 6e4e1050d9dba2b7b2523fdd1768823ab85feef4 (patch) | |
tree | 78be5963ec075d80116a932011d695dd33910b4e /spec/serializers | |
parent | 1ce776de4ae122aba3f349c02c17cebeaa8ecf07 (diff) | |
download | gitlab-ce-6e4e1050d9dba2b7b2523fdd1768823ab85feef4.tar.gz |
Add latest changes from gitlab-org/gitlab@13-3-stable-ee
Diffstat (limited to 'spec/serializers')
28 files changed, 398 insertions, 152 deletions
diff --git a/spec/serializers/accessibility_reports_comparer_entity_spec.rb b/spec/serializers/accessibility_reports_comparer_entity_spec.rb index 3024974710e..c576dfa4dd1 100644 --- a/spec/serializers/accessibility_reports_comparer_entity_spec.rb +++ b/spec/serializers/accessibility_reports_comparer_entity_spec.rb @@ -22,6 +22,7 @@ RSpec.describe AccessibilityReportsComparerEntity do } ] end + let(:different_error) do [ { diff --git a/spec/serializers/accessibility_reports_comparer_serializer_spec.rb b/spec/serializers/accessibility_reports_comparer_serializer_spec.rb index ef56f5b6b6b..94d2a2a4065 100644 --- a/spec/serializers/accessibility_reports_comparer_serializer_spec.rb +++ b/spec/serializers/accessibility_reports_comparer_serializer_spec.rb @@ -23,6 +23,7 @@ RSpec.describe AccessibilityReportsComparerSerializer do } ] end + let(:different_error) do [ { diff --git a/spec/serializers/analytics_issue_entity_spec.rb b/spec/serializers/analytics_issue_entity_spec.rb index 2518eec8c23..447c5e7d02a 100644 --- a/spec/serializers/analytics_issue_entity_spec.rb +++ b/spec/serializers/analytics_issue_entity_spec.rb @@ -17,16 +17,13 @@ RSpec.describe AnalyticsIssueEntity do } end - let(:project) { create(:project, name: 'my project') } let(:request) { EntityRequest.new(entity: :merge_request) } let(:entity) do described_class.new(entity_hash, request: request, project: project) end - context 'generic entity' do - subject { entity.as_json } - + shared_examples 'generic entity' do it 'contains the entity URL' do expect(subject).to include(:url) end @@ -40,4 +37,24 @@ RSpec.describe AnalyticsIssueEntity do expect(subject).not_to include(/variables/) end end + + context 'without subgroup' do + let_it_be(:project) { create(:project, name: 'my project') } + + subject { entity.as_json } + + it_behaves_like 'generic entity' + end + + context 'with subgroup' do + let_it_be(:project) { create(:project, :in_subgroup, name: 'my project') } + + subject { entity.as_json } + + it_behaves_like 'generic entity' + + it 'has URL containing subgroup' do + expect(subject[:url]).to include("#{project.group.parent.name}/#{project.group.name}/my_project/") + end + end end diff --git a/spec/serializers/build_details_entity_spec.rb b/spec/serializers/build_details_entity_spec.rb index ef6472e07a0..3166c08ff4e 100644 --- a/spec/serializers/build_details_entity_spec.rb +++ b/spec/serializers/build_details_entity_spec.rb @@ -185,12 +185,38 @@ RSpec.describe BuildDetailsEntity do end end + context 'when the build has expired artifacts' do + let!(:build) { create(:ci_build, :artifacts, artifacts_expire_at: 7.days.ago) } + + it 'does not expose any artifact actions path' do + expect(subject[:artifact].keys).not_to include(:download_path, :browse_path, :keep_path) + end + + it 'artifact locked is false' do + expect(subject.dig(:artifact, :locked)).to eq(false) + end + + context 'when the pipeline is artifacts_locked' do + before do + build.pipeline.update!(locked: :artifacts_locked) + end + + it 'artifact locked is true' do + expect(subject.dig(:artifact, :locked)).to eq(true) + end + + it 'exposes download and browse artifact actions path' do + expect(subject[:artifact].keys).to include(:download_path, :browse_path) + end + end + end + context 'when the build has archive type artifacts' do let!(:build) { create(:ci_build, :artifacts, artifacts_expire_at: 7.days.from_now) } let!(:report) { create(:ci_job_artifact, :codequality, job: build) } it 'exposes artifact details' do - expect(subject[:artifact].keys).to include(:download_path, :browse_path, :keep_path, :expire_at, :expired) + expect(subject[:artifact].keys).to include(:download_path, :browse_path, :keep_path, :expire_at, :expired, :locked) end end end diff --git a/spec/serializers/ci/daily_build_group_report_result_serializer_spec.rb b/spec/serializers/ci/daily_build_group_report_result_serializer_spec.rb index 69bf599c0dd..ddeeb367afe 100644 --- a/spec/serializers/ci/daily_build_group_report_result_serializer_spec.rb +++ b/spec/serializers/ci/daily_build_group_report_result_serializer_spec.rb @@ -11,6 +11,7 @@ RSpec.describe Ci::DailyBuildGroupReportResultSerializer do double(date: '2020-05-19', group_name: 'karma', data: { 'coverage' => 89.1 }) ] end + let(:serializer) { described_class.new.represent(report_result, param_type: 'coverage') } describe '#to_json' do diff --git a/spec/serializers/cluster_error_entity_spec.rb b/spec/serializers/cluster_error_entity_spec.rb new file mode 100644 index 00000000000..43ec41adf14 --- /dev/null +++ b/spec/serializers/cluster_error_entity_spec.rb @@ -0,0 +1,35 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe ClusterErrorEntity do + describe '#as_json' do + let(:cluster) { create(:cluster, :provided_by_user, :group) } + + subject { described_class.new(cluster).as_json } + + context 'when connection_error is present' do + before do + allow(cluster).to receive(:connection_error).and_return(:connection_error) + end + + it { is_expected.to eq({ connection_error: :connection_error, metrics_connection_error: nil, node_connection_error: nil }) } + end + + context 'when metrics_connection_error is present' do + before do + allow(cluster).to receive(:metrics_connection_error).and_return(:http_error) + end + + it { is_expected.to eq({ connection_error: nil, metrics_connection_error: :http_error, node_connection_error: nil }) } + end + + context 'when node_connection_error is present' do + before do + allow(cluster).to receive(:node_connection_error).and_return(:unknown_error) + end + + it { is_expected.to eq({ connection_error: nil, metrics_connection_error: nil, node_connection_error: :unknown_error }) } + end + end +end diff --git a/spec/serializers/cluster_serializer_spec.rb b/spec/serializers/cluster_serializer_spec.rb index ea1cf6ff59a..f34409c3cfb 100644 --- a/spec/serializers/cluster_serializer_spec.rb +++ b/spec/serializers/cluster_serializer_spec.rb @@ -14,6 +14,7 @@ RSpec.describe ClusterSerializer do :enabled, :environment_scope, :gitlab_managed_apps_logs_path, + :kubernetes_errors, :name, :nodes, :path, diff --git a/spec/serializers/commit_entity_spec.rb b/spec/serializers/commit_entity_spec.rb index e2ea63893a4..6b4346faf5b 100644 --- a/spec/serializers/commit_entity_spec.rb +++ b/spec/serializers/commit_entity_spec.rb @@ -8,6 +8,7 @@ RSpec.describe CommitEntity do let(:entity) do described_class.new(commit, request: request) end + let(:request) { double('request') } let(:project) { create(:project, :repository) } let(:commit) { project.commit } diff --git a/spec/serializers/diff_file_base_entity_spec.rb b/spec/serializers/diff_file_base_entity_spec.rb index 153f854aa58..bf69a50a072 100644 --- a/spec/serializers/diff_file_base_entity_spec.rb +++ b/spec/serializers/diff_file_base_entity_spec.rb @@ -11,6 +11,7 @@ RSpec.describe DiffFileBaseEntity do let(:commit_sha_with_changed_submodule) do "cfe32cf61b73a0d5e9f13e774abde7ff789b1660" end + let(:commit) { project.commit(commit_sha_with_changed_submodule) } let(:options) { { request: {}, submodule_links: Gitlab::SubmoduleLinks.new(repository) } } let(:diff_file) { commit.diffs.diff_files.to_a.last } diff --git a/spec/serializers/diffs_metadata_entity_spec.rb b/spec/serializers/diffs_metadata_entity_spec.rb index 8ed47569b75..e8cbc2076d7 100644 --- a/spec/serializers/diffs_metadata_entity_spec.rb +++ b/spec/serializers/diffs_metadata_entity_spec.rb @@ -30,6 +30,7 @@ RSpec.describe DiffsMetadataEntity do :email_patch_path, :plain_diff_path, :merge_request_diffs, :context_commits, :definition_path_prefix, :source_branch_exists, + :can_merge, :conflict_resolution_path, :has_conflicts, # Attributes :diff_files ) diff --git a/spec/serializers/environment_entity_spec.rb b/spec/serializers/environment_entity_spec.rb index 6232a0d2973..c969638614e 100644 --- a/spec/serializers/environment_entity_spec.rb +++ b/spec/serializers/environment_entity_spec.rb @@ -82,10 +82,30 @@ RSpec.describe EnvironmentEntity do end end + context 'with alert' do + let!(:environment) { create(:environment, project: project) } + let!(:prometheus_alert) { create(:prometheus_alert, project: project, environment: environment) } + let!(:alert) { create(:alert_management_alert, :triggered, :prometheus, project: project, environment: environment, prometheus_alert: prometheus_alert) } + + it 'exposes active alert flag' do + project.add_maintainer(user) + + expect(subject[:has_opened_alert]).to eq(true) + end + + context 'when user does not have permission to read alert' do + it 'does not expose active alert flag' do + project.add_reporter(user) + + expect(subject[:has_opened_alert]).to be_nil + end + end + end + context 'pod_logs' do - context 'with developer access' do + context 'with reporter access' do before do - project.add_developer(user) + project.add_reporter(user) end it 'does not expose logs keys' do @@ -95,9 +115,9 @@ RSpec.describe EnvironmentEntity do end end - context 'with maintainer access' do + context 'with developer access' do before do - project.add_maintainer(user) + project.add_developer(user) end it 'exposes logs keys' do diff --git a/spec/serializers/environment_serializer_spec.rb b/spec/serializers/environment_serializer_spec.rb index 1e3980b7720..1eba9ae4e5e 100644 --- a/spec/serializers/environment_serializer_spec.rb +++ b/spec/serializers/environment_serializer_spec.rb @@ -26,6 +26,7 @@ RSpec.describe EnvironmentSerializer do project: project, sha: project.commit.id) end + let(:resource) { deployment.environment } before do diff --git a/spec/serializers/group_deploy_key_entity_spec.rb b/spec/serializers/group_deploy_key_entity_spec.rb new file mode 100644 index 00000000000..e6cef2f10b3 --- /dev/null +++ b/spec/serializers/group_deploy_key_entity_spec.rb @@ -0,0 +1,47 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe GroupDeployKeyEntity do + include RequestAwareEntity + + let(:user) { create(:user) } + let(:group) { create(:group) } + let(:group_deploy_key) { create(:group_deploy_key) } + let(:options) { { user: user } } + + let(:entity) { described_class.new(group_deploy_key, options) } + + before do + group.group_deploy_keys << group_deploy_key + end + + describe 'returns group deploy keys with a group a user can read' do + let(:expected_result) do + { + id: group_deploy_key.id, + user_id: group_deploy_key.user_id, + title: group_deploy_key.title, + fingerprint: group_deploy_key.fingerprint, + fingerprint_sha256: group_deploy_key.fingerprint_sha256, + created_at: group_deploy_key.created_at, + updated_at: group_deploy_key.updated_at, + can_edit: false, + group_deploy_keys_groups: [ + { + can_push: false, + group: + { + id: group.id, + name: group.name, + full_path: group.full_path, + full_name: group.full_name + } + } + ] + } + end + + it { expect(entity.as_json).to eq(expected_result) } + end +end diff --git a/spec/serializers/import/bitbucket_provider_repo_entity_spec.rb b/spec/serializers/import/bitbucket_provider_repo_entity_spec.rb index 2a0386b779f..d59a476961e 100644 --- a/spec/serializers/import/bitbucket_provider_repo_entity_spec.rb +++ b/spec/serializers/import/bitbucket_provider_repo_entity_spec.rb @@ -17,6 +17,7 @@ RSpec.describe Import::BitbucketProviderRepoEntity do } } end + let(:repo) { Bitbucket::Representation::Repo.new(repo_data) } subject { described_class.new(repo).as_json } diff --git a/spec/serializers/import/bitbucket_server_provider_repo_entity_spec.rb b/spec/serializers/import/bitbucket_server_provider_repo_entity_spec.rb index 6e00d608d9a..894bf6ac770 100644 --- a/spec/serializers/import/bitbucket_server_provider_repo_entity_spec.rb +++ b/spec/serializers/import/bitbucket_server_provider_repo_entity_spec.rb @@ -6,8 +6,10 @@ RSpec.describe Import::BitbucketServerProviderRepoEntity do let(:repo_data) do { 'name' => 'test', + 'slug' => 'TEST', 'project' => { - 'name' => 'demo' + 'name' => 'demo', + 'key' => 'DEM' }, 'links' => { 'self' => [ @@ -19,6 +21,7 @@ RSpec.describe Import::BitbucketServerProviderRepoEntity do } } end + let(:repo) { BitbucketServer::Representation::Repo.new(repo_data) } subject { described_class.new(repo).as_json } @@ -26,7 +29,7 @@ RSpec.describe Import::BitbucketServerProviderRepoEntity do it_behaves_like 'exposes required fields for import entity' do let(:expected_values) do { - id: 'demo/test', + id: 'DEM/TEST', full_name: 'demo/test', sanitized_name: 'test', provider_link: 'http://local.bitbucket.server/demo/test.git' diff --git a/spec/serializers/import/fogbugz_provider_repo_entity_spec.rb b/spec/serializers/import/fogbugz_provider_repo_entity_spec.rb index 748ddd2a108..62bb0addb87 100644 --- a/spec/serializers/import/fogbugz_provider_repo_entity_spec.rb +++ b/spec/serializers/import/fogbugz_provider_repo_entity_spec.rb @@ -10,6 +10,7 @@ RSpec.describe Import::FogbugzProviderRepoEntity do 'sProject' => 'demo' } end + let(:repo) { Gitlab::FogbugzImport::Repository.new(repo_data) } subject { described_class.represent(repo, { provider_url: provider_url }).as_json } diff --git a/spec/serializers/import/manifest_provider_repo_entity_spec.rb b/spec/serializers/import/manifest_provider_repo_entity_spec.rb new file mode 100644 index 00000000000..c11f8c42559 --- /dev/null +++ b/spec/serializers/import/manifest_provider_repo_entity_spec.rb @@ -0,0 +1,28 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Import::ManifestProviderRepoEntity do + let(:current_user) { create(:user) } + let(:request) { double(:request, current_user: current_user) } + let(:repo_data) do + { + id: 1, + url: 'http://demo.repo/url', + path: '/demo/path' + } + end + + subject { described_class.represent(repo_data, { group_full_path: 'group', request: request }).as_json } + + it_behaves_like 'exposes required fields for import entity' do + let(:expected_values) do + { + id: repo_data[:id], + full_name: repo_data[:url], + sanitized_name: nil, + provider_link: repo_data[:url] + } + end + end +end diff --git a/spec/serializers/merge_request_poll_widget_entity_spec.rb b/spec/serializers/merge_request_poll_widget_entity_spec.rb index f0493699209..e5f88e31025 100644 --- a/spec/serializers/merge_request_poll_widget_entity_spec.rb +++ b/spec/serializers/merge_request_poll_widget_entity_spec.rb @@ -36,13 +36,28 @@ RSpec.describe MergeRequestPollWidgetEntity do it 'returns merge_pipeline' do pipeline.reload - pipeline_payload = PipelineDetailsEntity - .represent(pipeline, request: request) - .as_json + pipeline_payload = + MergeRequests::PipelineEntity + .represent(pipeline, request: request) + .as_json expect(subject[:merge_pipeline]).to eq(pipeline_payload) end + context 'when merge_request_short_pipeline_serializer is disabled' do + it 'returns detailed info about pipeline' do + stub_feature_flags(merge_request_short_pipeline_serializer: false) + + pipeline.reload + pipeline_payload = + PipelineDetailsEntity + .represent(pipeline, request: request) + .as_json + + expect(subject[:merge_pipeline]).to eq(pipeline_payload) + end + end + context 'when user cannot read pipelines on target project' do before do project.add_guest(user) @@ -222,13 +237,27 @@ RSpec.describe MergeRequestPollWidgetEntity do let(:req) { double('request', current_user: user, project: project) } it 'returns pipeline' do - pipeline_payload = PipelineDetailsEntity - .represent(pipeline, request: req) - .as_json + pipeline_payload = + MergeRequests::PipelineEntity + .represent(pipeline, request: req) + .as_json expect(subject[:pipeline]).to eq(pipeline_payload) end + context 'when merge_request_short_pipeline_serializer is disabled' do + it 'returns detailed info about pipeline' do + stub_feature_flags(merge_request_short_pipeline_serializer: false) + + pipeline_payload = + PipelineDetailsEntity + .represent(pipeline, request: req) + .as_json + + expect(subject[:pipeline]).to eq(pipeline_payload) + end + end + it 'returns ci_status' do expect(subject[:ci_status]).to eq('pending') end diff --git a/spec/serializers/merge_request_widget_entity_spec.rb b/spec/serializers/merge_request_widget_entity_spec.rb index aaee47fb981..1704208d8b9 100644 --- a/spec/serializers/merge_request_widget_entity_spec.rb +++ b/spec/serializers/merge_request_widget_entity_spec.rb @@ -31,6 +31,28 @@ RSpec.describe MergeRequestWidgetEntity do end end + describe 'can_create_pipeline_in_target_project' do + context 'when user has permission' do + before do + project.add_developer(user) + end + + it 'includes the correct permission info' do + expect(subject[:can_create_pipeline_in_target_project]).to eq(true) + end + end + + context 'when user does not have permission' do + before do + project.add_guest(user) + end + + it 'includes the correct permission info' do + expect(subject[:can_create_pipeline_in_target_project]).to eq(false) + end + end + end + describe 'issues links' do it 'includes issues links when requested' do data = described_class.new(resource, request: request, issues_links: true).as_json @@ -234,6 +256,62 @@ RSpec.describe MergeRequestWidgetEntity do end end + describe 'user callouts' do + context 'when suggest pipeline feature is enabled' do + before do + stub_feature_flags(suggest_pipeline: true) + end + + it 'provides a valid path value for user callout path' do + expect(subject[:user_callouts_path]).to eq '/-/user_callouts' + end + + it 'provides a valid value for suggest pipeline feature id' do + expect(subject[:suggest_pipeline_feature_id]).to eq described_class::SUGGEST_PIPELINE + end + + it 'provides a valid value for if it is dismissed' do + expect(subject[:is_dismissed_suggest_pipeline]).to be(false) + end + + context 'when the suggest pipeline has been dismissed' do + before do + create(:user_callout, user: user, feature_name: described_class::SUGGEST_PIPELINE) + end + + it 'indicates suggest pipeline has been dismissed' do + expect(subject[:is_dismissed_suggest_pipeline]).to be(true) + end + end + + context 'when user is not logged in' do + let(:request) { double('request', current_user: nil, project: project) } + + it 'returns a blank is dismissed value' do + expect(subject[:is_dismissed_suggest_pipeline]).to be_nil + end + end + end + + context 'when suggest pipeline feature is not enabled' do + before do + stub_feature_flags(suggest_pipeline: false) + end + + it 'provides no valid value for user callout path' do + expect(subject[:user_callouts_path]).to be_nil + end + + it 'provides no valid value for suggest pipeline feature id' do + expect(subject[:suggest_pipeline_feature_id]).to be_nil + end + + it 'provides no valid value for if it is dismissed' do + expect(subject[:is_dismissed_suggest_pipeline]).to be_nil + end + end + end + it 'has human access' do project.add_maintainer(user) diff --git a/spec/serializers/merge_requests/pipeline_entity_spec.rb b/spec/serializers/merge_requests/pipeline_entity_spec.rb new file mode 100644 index 00000000000..8685d4bb846 --- /dev/null +++ b/spec/serializers/merge_requests/pipeline_entity_spec.rb @@ -0,0 +1,45 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe MergeRequests::PipelineEntity do + let_it_be(:project) { create(:project, :repository) } + let_it_be(:user) { create(:user) } + let_it_be(:pipeline) { create(:ci_pipeline, project: project) } + + let(:request) { double('request') } + + before do + stub_not_protect_default_branch + + allow(request).to receive(:current_user).and_return(user) + allow(request).to receive(:project).and_return(project) + end + + let(:entity) do + described_class.represent(pipeline, request: request) + end + + subject { entity.as_json } + + describe '#as_json' do + it 'contains required fields' do + is_expected.to include( + :id, :path, :active, :coverage, :ref, :commit, :details, + :flags, :triggered, :triggered_by + ) + expect(subject[:commit]).to include(:short_id, :commit_path) + expect(subject[:ref]).to include(:branch) + expect(subject[:details]).to include(:name, :status, :stages) + expect(subject[:details][:status]).to include(:icon, :favicon, :text, :label, :tooltip) + expect(subject[:flags]).to include(:merge_request_pipeline) + end + + it 'excludes coverage data when disabled' do + entity = described_class + .represent(pipeline, request: request, disable_coverage: true) + + expect(entity.as_json).not_to include(:coverage) + end + end +end diff --git a/spec/serializers/paginated_diff_entity_spec.rb b/spec/serializers/paginated_diff_entity_spec.rb index 30360b00537..a2c58baed55 100644 --- a/spec/serializers/paginated_diff_entity_spec.rb +++ b/spec/serializers/paginated_diff_entity_spec.rb @@ -14,6 +14,7 @@ RSpec.describe PaginatedDiffEntity do pagination_data: diff_batch.pagination_data } end + let(:entity) { described_class.new(diff_batch, options) } subject { entity.as_json } diff --git a/spec/serializers/pipeline_entity_spec.rb b/spec/serializers/pipeline_entity_spec.rb index e638b14765b..e00f05a8fe8 100644 --- a/spec/serializers/pipeline_entity_spec.rb +++ b/spec/serializers/pipeline_entity_spec.rb @@ -7,7 +7,6 @@ RSpec.describe PipelineEntity do let_it_be(:project) { create(:project) } let_it_be(:user) { create(:user) } - let_it_be(:project) { create(:project) } let(:request) { double('request') } before do @@ -265,24 +264,8 @@ RSpec.describe PipelineEntity do context 'when pipeline has build report results' do let(:pipeline) { create(:ci_pipeline, :with_report_results, project: project, user: user) } - context 'when feature is enabled' do - before do - stub_feature_flags(build_report_summary: true) - end - - it 'exposes tests total count' do - expect(subject[:tests_total_count]).to eq(2) - end - end - - context 'when feature is disabled' do - before do - stub_feature_flags(build_report_summary: false) - end - - it 'do not expose tests total count' do - expect(subject).not_to include(:tests_total_count) - end + it 'exposes tests total count' do + expect(subject[:tests_total_count]).to eq(2) end end end diff --git a/spec/serializers/pipeline_serializer_spec.rb b/spec/serializers/pipeline_serializer_spec.rb index c1386ac4eb2..dfe51e9006f 100644 --- a/spec/serializers/pipeline_serializer_spec.rb +++ b/spec/serializers/pipeline_serializer_spec.rb @@ -160,20 +160,6 @@ RSpec.describe PipelineSerializer do expect(recorded.count).to be_within(2).of(expected_queries) expect(recorded.cached_count).to eq(0) end - - context 'with the :build_report_summary flag turned off' do - before do - stub_feature_flags(build_report_summary: false) - end - - it 'verifies number of queries', :request_store do - recorded = ActiveRecord::QueryRecorder.new { subject } - expected_queries = Gitlab.ee? ? 43 : 40 - - expect(recorded.count).to be_within(2).of(expected_queries) - expect(recorded.cached_count).to eq(0) - end - end end context 'with different refs' do @@ -195,20 +181,6 @@ RSpec.describe PipelineSerializer do expect(recorded.count).to be_within(2).of(expected_queries) expect(recorded.cached_count).to eq(0) end - - context 'with the :build_report_summary flag turned off' do - before do - stub_feature_flags(build_report_summary: false) - end - - it 'verifies number of queries', :request_store do - recorded = ActiveRecord::QueryRecorder.new { subject } - expected_queries = Gitlab.ee? ? 46 : 43 - - expect(recorded.count).to be_within(2).of(expected_queries) - expect(recorded.cached_count).to eq(0) - end - end end context 'with triggered pipelines' do @@ -231,7 +203,7 @@ RSpec.describe PipelineSerializer do # :source_pipeline and :source_job # Existing numbers are high and require performance optimization # https://gitlab.com/gitlab-org/gitlab/-/issues/225156 - expected_queries = Gitlab.ee? ? 101 : 92 + expected_queries = Gitlab.ee? ? 95 : 86 expect(recorded.count).to be_within(2).of(expected_queries) expect(recorded.cached_count).to eq(0) diff --git a/spec/serializers/prometheus_alert_entity_spec.rb b/spec/serializers/prometheus_alert_entity_spec.rb index aeee8de2a5b..ae8c97401f8 100644 --- a/spec/serializers/prometheus_alert_entity_spec.rb +++ b/spec/serializers/prometheus_alert_entity_spec.rb @@ -16,7 +16,7 @@ RSpec.describe PrometheusAlertEntity do end it 'exposes prometheus_alert attributes' do - expect(subject).to include(:id, :title, :query, :operator, :threshold) + expect(subject).to include(:id, :title, :query, :operator, :threshold, :runbook_url) end it 'exposes alert_path' do diff --git a/spec/serializers/release_serializer_spec.rb b/spec/serializers/release_serializer_spec.rb new file mode 100644 index 00000000000..518d281f370 --- /dev/null +++ b/spec/serializers/release_serializer_spec.rb @@ -0,0 +1,32 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe ReleaseSerializer do + let(:user) { create(:user) } + let(:project) { create :project } + + subject { described_class.new.represent(resource, current_user: user) } + + before do + project.add_developer(user) + end + + describe '#represent' do + context 'when a single object is being serialized' do + let(:resource) { create(:release, project: project) } + + it 'serializes the label object' do + expect(subject[:tag]).to eq resource.tag + end + end + + context 'when multiple objects are being serialized' do + let(:resource) { create_list(:release, 3) } + + it 'serializes the array of releases' do + expect(subject.size).to eq(3) + end + end + end +end diff --git a/spec/serializers/suggestion_entity_spec.rb b/spec/serializers/suggestion_entity_spec.rb index b133c3fb82e..25301bb20cc 100644 --- a/spec/serializers/suggestion_entity_spec.rb +++ b/spec/serializers/suggestion_entity_spec.rb @@ -36,87 +36,11 @@ RSpec.describe SuggestionEntity do let(:can_apply_suggestion) { true } before do - allow(suggestion).to receive(:appliable?).and_return(appliable) + allow(suggestion).to receive(:inapplicable_reason).and_return("Can't apply this suggestion.") end - context 'and suggestion is appliable' do - let(:appliable) { true } - - it 'returns nil' do - expect(inapplicable_reason).to be_nil - end - end - - context 'but suggestion is not applicable' do - let(:appliable) { false } - - before do - allow(suggestion).to receive(:inapplicable_reason).and_return(reason) - end - - context 'and merge request was merged' do - let(:reason) { :merge_request_merged } - - it 'returns appropriate message' do - expect(inapplicable_reason).to eq("This merge request was merged. To apply this suggestion, edit this file directly.") - end - end - - context 'and source branch was deleted' do - let(:reason) { :source_branch_deleted } - - it 'returns appropriate message' do - expect(inapplicable_reason).to eq("Can't apply as the source branch was deleted.") - end - end - - context 'and merge request is closed' do - let(:reason) { :merge_request_closed } - - it 'returns appropriate message' do - expect(inapplicable_reason).to eq("This merge request is closed. To apply this suggestion, edit this file directly.") - end - end - - context 'and suggestion is outdated' do - let(:reason) { :outdated } - - before do - allow(suggestion).to receive(:single_line?).and_return(single_line) - end - - context 'and suggestion is for a single line' do - let(:single_line) { true } - - it 'returns appropriate message' do - expect(inapplicable_reason).to eq("Can't apply as this line was changed in a more recent version.") - end - end - - context 'and suggestion is for multiple lines' do - let(:single_line) { false } - - it 'returns appropriate message' do - expect(inapplicable_reason).to eq("Can't apply as these lines were changed in a more recent version.") - end - end - end - - context 'and suggestion has the same content' do - let(:reason) { :same_content } - - it 'returns appropriate message' do - expect(inapplicable_reason).to eq("This suggestion already matches its content.") - end - end - - context 'and suggestion is inapplicable for other reasons' do - let(:reason) { :some_other_reason } - - it 'returns default message' do - expect(inapplicable_reason).to eq("Can't apply this suggestion.") - end - end + it 'returns the inapplicable reason' do + expect(inapplicable_reason).to eq(suggestion.inapplicable_reason) end end diff --git a/spec/serializers/test_report_summary_entity_spec.rb b/spec/serializers/test_report_summary_entity_spec.rb index fcac9af5c23..4b0af398b83 100644 --- a/spec/serializers/test_report_summary_entity_spec.rb +++ b/spec/serializers/test_report_summary_entity_spec.rb @@ -9,12 +9,8 @@ RSpec.describe TestReportSummaryEntity do describe '#as_json' do subject(:as_json) { entity.as_json } - it 'contains the total time' do - expect(as_json).to include(:total_time) - end - - it 'contains the counts' do - expect(as_json).to include(:total_count, :success_count, :failed_count, :skipped_count, :error_count) + it 'contains the total' do + expect(as_json).to include(:total) end context 'when summary has test suites' do diff --git a/spec/serializers/test_suite_summary_entity_spec.rb b/spec/serializers/test_suite_summary_entity_spec.rb index d26592bc60e..864781ccfce 100644 --- a/spec/serializers/test_suite_summary_entity_spec.rb +++ b/spec/serializers/test_suite_summary_entity_spec.rb @@ -4,7 +4,7 @@ require 'spec_helper' RSpec.describe TestSuiteSummaryEntity do let(:pipeline) { create(:ci_pipeline, :with_report_results) } - let(:entity) { described_class.new(pipeline.test_report_summary.total) } + let(:entity) { described_class.new(pipeline.test_report_summary.test_suites.each_value.first) } describe '#as_json' do subject(:as_json) { entity.as_json } |