diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-07-20 12:26:25 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-07-20 12:26:25 +0000 |
commit | a09983ae35713f5a2bbb100981116d31ce99826e (patch) | |
tree | 2ee2af7bd104d57086db360a7e6d8c9d5d43667a /spec/serializers | |
parent | 18c5ab32b738c0b6ecb4d0df3994000482f34bd8 (diff) | |
download | gitlab-ce-a09983ae35713f5a2bbb100981116d31ce99826e.tar.gz |
Add latest changes from gitlab-org/gitlab@13-2-stable-ee
Diffstat (limited to 'spec/serializers')
125 files changed, 739 insertions, 196 deletions
diff --git a/spec/serializers/accessibility_error_entity_spec.rb b/spec/serializers/accessibility_error_entity_spec.rb index e9bfabb7aa8..afbff15a195 100644 --- a/spec/serializers/accessibility_error_entity_spec.rb +++ b/spec/serializers/accessibility_error_entity_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe AccessibilityErrorEntity do +RSpec.describe AccessibilityErrorEntity do let(:entity) { described_class.new(accessibility_error) } describe '#as_json' do diff --git a/spec/serializers/accessibility_reports_comparer_entity_spec.rb b/spec/serializers/accessibility_reports_comparer_entity_spec.rb index ed2c17de640..3024974710e 100644 --- a/spec/serializers/accessibility_reports_comparer_entity_spec.rb +++ b/spec/serializers/accessibility_reports_comparer_entity_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe AccessibilityReportsComparerEntity do +RSpec.describe AccessibilityReportsComparerEntity do let(:entity) { described_class.new(comparer) } let(:comparer) { Gitlab::Ci::Reports::AccessibilityReportsComparer.new(base_report, head_report) } let(:base_report) { Gitlab::Ci::Reports::AccessibilityReports.new } diff --git a/spec/serializers/accessibility_reports_comparer_serializer_spec.rb b/spec/serializers/accessibility_reports_comparer_serializer_spec.rb index 37dc760fdec..ef56f5b6b6b 100644 --- a/spec/serializers/accessibility_reports_comparer_serializer_spec.rb +++ b/spec/serializers/accessibility_reports_comparer_serializer_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe AccessibilityReportsComparerSerializer do +RSpec.describe AccessibilityReportsComparerSerializer do let(:project) { double(:project) } let(:serializer) { described_class.new(project: project).represent(comparer) } let(:comparer) { Gitlab::Ci::Reports::AccessibilityReportsComparer.new(base_report, head_report) } diff --git a/spec/serializers/analytics_build_entity_spec.rb b/spec/serializers/analytics_build_entity_spec.rb index dfa16075d20..20bd017d1cf 100644 --- a/spec/serializers/analytics_build_entity_spec.rb +++ b/spec/serializers/analytics_build_entity_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe AnalyticsBuildEntity do +RSpec.describe AnalyticsBuildEntity do let(:entity) do described_class.new(build, request: double) end diff --git a/spec/serializers/analytics_build_serializer_spec.rb b/spec/serializers/analytics_build_serializer_spec.rb index 04a387fd353..94a42ba4ffa 100644 --- a/spec/serializers/analytics_build_serializer_spec.rb +++ b/spec/serializers/analytics_build_serializer_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe AnalyticsBuildSerializer do +RSpec.describe AnalyticsBuildSerializer do let(:resource) { create(:ci_build) } subject { described_class.new.represent(resource) } diff --git a/spec/serializers/analytics_issue_entity_spec.rb b/spec/serializers/analytics_issue_entity_spec.rb index 555efe136e6..2518eec8c23 100644 --- a/spec/serializers/analytics_issue_entity_spec.rb +++ b/spec/serializers/analytics_issue_entity_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe AnalyticsIssueEntity do +RSpec.describe AnalyticsIssueEntity do let(:user) { create(:user) } let(:entity_hash) do { diff --git a/spec/serializers/analytics_issue_serializer_spec.rb b/spec/serializers/analytics_issue_serializer_spec.rb index 9b29739a8f2..5d268fe514b 100644 --- a/spec/serializers/analytics_issue_serializer_spec.rb +++ b/spec/serializers/analytics_issue_serializer_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe AnalyticsIssueSerializer do +RSpec.describe AnalyticsIssueSerializer do subject do described_class .new(entity: :merge_request) diff --git a/spec/serializers/analytics_merge_request_serializer_spec.rb b/spec/serializers/analytics_merge_request_serializer_spec.rb index c82eb28a28b..adf7321c738 100644 --- a/spec/serializers/analytics_merge_request_serializer_spec.rb +++ b/spec/serializers/analytics_merge_request_serializer_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe AnalyticsMergeRequestSerializer do +RSpec.describe AnalyticsMergeRequestSerializer do subject do described_class .new(entity: :merge_request) diff --git a/spec/serializers/analytics_stage_serializer_spec.rb b/spec/serializers/analytics_stage_serializer_spec.rb index 1f1a0180b1f..0f2de262188 100644 --- a/spec/serializers/analytics_stage_serializer_spec.rb +++ b/spec/serializers/analytics_stage_serializer_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe AnalyticsStageSerializer do +RSpec.describe AnalyticsStageSerializer do subject do described_class.new.represent(resource) end diff --git a/spec/serializers/analytics_summary_serializer_spec.rb b/spec/serializers/analytics_summary_serializer_spec.rb index ed126720a55..cd8be07827d 100644 --- a/spec/serializers/analytics_summary_serializer_spec.rb +++ b/spec/serializers/analytics_summary_serializer_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe AnalyticsSummarySerializer do +RSpec.describe AnalyticsSummarySerializer do subject do described_class.new.represent(resource) end diff --git a/spec/serializers/blob_entity_spec.rb b/spec/serializers/blob_entity_spec.rb index 3cd967ed44c..b8c8c4c17de 100644 --- a/spec/serializers/blob_entity_spec.rb +++ b/spec/serializers/blob_entity_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe BlobEntity do +RSpec.describe BlobEntity do let(:user) { create(:user) } let(:project) { create(:project, :repository) } let(:blob) { project.commit('master').diffs.diff_files.first.blob } diff --git a/spec/serializers/board_serializer_spec.rb b/spec/serializers/board_serializer_spec.rb index 8a633e46316..9e6d5a93d53 100644 --- a/spec/serializers/board_serializer_spec.rb +++ b/spec/serializers/board_serializer_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe BoardSerializer do +RSpec.describe BoardSerializer do let(:resource) { create(:board) } let(:json_entity) do described_class.new diff --git a/spec/serializers/build_action_entity_spec.rb b/spec/serializers/build_action_entity_spec.rb index 7cd1fdcda22..75ae244db83 100644 --- a/spec/serializers/build_action_entity_spec.rb +++ b/spec/serializers/build_action_entity_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe BuildActionEntity do +RSpec.describe BuildActionEntity do let(:job) { create(:ci_build, name: 'test_job') } let(:request) { double('request') } let(:user) { create(:user) } diff --git a/spec/serializers/build_artifact_entity_spec.rb b/spec/serializers/build_artifact_entity_spec.rb index afa2aa3d254..02c172d723f 100644 --- a/spec/serializers/build_artifact_entity_spec.rb +++ b/spec/serializers/build_artifact_entity_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe BuildArtifactEntity do +RSpec.describe BuildArtifactEntity do let(:job) { create(:ci_build) } let(:artifact) { create(:ci_job_artifact, :codequality, expire_at: 1.hour.from_now, job: job) } diff --git a/spec/serializers/build_details_entity_spec.rb b/spec/serializers/build_details_entity_spec.rb index 92917f6ea25..ef6472e07a0 100644 --- a/spec/serializers/build_details_entity_spec.rb +++ b/spec/serializers/build_details_entity_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe BuildDetailsEntity do +RSpec.describe BuildDetailsEntity do include ProjectForksHelper let_it_be(:user) { create(:admin) } diff --git a/spec/serializers/build_serializer_spec.rb b/spec/serializers/build_serializer_spec.rb index c7bb6864361..f3584beb39b 100644 --- a/spec/serializers/build_serializer_spec.rb +++ b/spec/serializers/build_serializer_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe BuildSerializer do +RSpec.describe BuildSerializer do let(:user) { create(:user) } let(:serializer) do diff --git a/spec/serializers/build_trace_entity_spec.rb b/spec/serializers/build_trace_entity_spec.rb index bafead04a51..82bd56caaac 100644 --- a/spec/serializers/build_trace_entity_spec.rb +++ b/spec/serializers/build_trace_entity_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe BuildTraceEntity do +RSpec.describe BuildTraceEntity do let(:build) { build_stubbed(:ci_build) } let(:request) { double('request') } @@ -13,7 +13,7 @@ describe BuildTraceEntity do end let(:build_trace) do - Ci::BuildTrace.new(build: build, stream: stream, content_format: content_format, state: nil) + Ci::BuildTrace.new(build: build, stream: stream, state: nil) end let(:entity) do @@ -22,42 +22,24 @@ describe BuildTraceEntity do subject { entity.as_json } - shared_examples 'includes build and trace metadata' do - it 'includes build attributes' do - expect(subject[:id]).to eq(build.id) - expect(subject[:status]).to eq(build.status) - expect(subject[:complete]).to eq(build.complete?) - end - - it 'includes trace metadata' do - expect(subject).to include(:state) - expect(subject).to include(:append) - expect(subject).to include(:truncated) - expect(subject).to include(:offset) - expect(subject).to include(:size) - expect(subject).to include(:total) - end + it 'includes build attributes' do + expect(subject[:id]).to eq(build.id) + expect(subject[:status]).to eq(build.status) + expect(subject[:complete]).to eq(build.complete?) end - context 'when content format is :json' do - let(:content_format) { :json } - - it_behaves_like 'includes build and trace metadata' - - it 'includes the trace content in json' do - expect(subject[:lines]).to eq([ - { offset: 0, content: [{ text: 'the-trace' }] } - ]) - end + it 'includes trace metadata' do + expect(subject).to include(:state) + expect(subject).to include(:append) + expect(subject).to include(:truncated) + expect(subject).to include(:offset) + expect(subject).to include(:size) + expect(subject).to include(:total) end - context 'when content format is :html' do - let(:content_format) { :html } - - it_behaves_like 'includes build and trace metadata' - - it 'includes the trace content in json' do - expect(subject[:html]).to eq('<span>the-trace</span>') - end + it 'includes the trace content in json' do + expect(subject[:lines]).to eq([ + { offset: 0, content: [{ text: 'the-trace' }] } + ]) end end diff --git a/spec/serializers/ci/dag_job_entity_spec.rb b/spec/serializers/ci/dag_job_entity_spec.rb index eaaf39d6bfc..5e2b186186f 100644 --- a/spec/serializers/ci/dag_job_entity_spec.rb +++ b/spec/serializers/ci/dag_job_entity_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Ci::DagJobEntity do +RSpec.describe Ci::DagJobEntity do let_it_be(:request) { double(:request) } let(:job) { create(:ci_build, name: 'dag_job') } @@ -11,10 +11,18 @@ describe Ci::DagJobEntity do describe '#as_json' do subject { entity.as_json } + RSpec.shared_examples "matches schema" do + it "matches schema" do + expect(subject.to_json).to match_schema('entities/dag_job') + end + end + it 'contains the name' do expect(subject[:name]).to eq 'dag_job' end + it_behaves_like "matches schema" + context 'when job is stage scheduled' do it 'contains the name scheduling_type' do expect(subject[:scheduling_type]).to eq 'stage' @@ -23,6 +31,8 @@ describe Ci::DagJobEntity do it 'does not expose needs' do expect(subject).not_to include(:needs) end + + it_behaves_like "matches schema" end context 'when job is dag scheduled' do @@ -32,18 +42,24 @@ describe Ci::DagJobEntity do expect(subject[:scheduling_type]).to eq 'dag' end + it_behaves_like "matches schema" + context 'when job has needs' do let!(:need) { create(:ci_build_need, build: job, name: 'compile') } it 'exposes the array of needs' do expect(subject[:needs]).to eq ['compile'] end + + it_behaves_like "matches schema" end context 'when job has empty needs' do it 'exposes an empty array of needs' do expect(subject[:needs]).to eq [] end + + it_behaves_like "matches schema" end end end diff --git a/spec/serializers/ci/dag_job_group_entity_spec.rb b/spec/serializers/ci/dag_job_group_entity_spec.rb index a25723894fd..5a75c04efe5 100644 --- a/spec/serializers/ci/dag_job_group_entity_spec.rb +++ b/spec/serializers/ci/dag_job_group_entity_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Ci::DagJobGroupEntity do +RSpec.describe Ci::DagJobGroupEntity do let_it_be(:request) { double(:request) } let_it_be(:pipeline) { create(:ci_pipeline) } let_it_be(:stage) { create(:ci_stage, pipeline: pipeline) } @@ -31,6 +31,10 @@ describe Ci::DagJobGroupEntity do expect(exposed_jobs.size).to eq 1 expect(exposed_jobs.first.fetch(:name)).to eq 'test' end + + it 'matches schema' do + expect(subject.to_json).to match_schema('entities/dag_job_group') + end end context 'when group contains multiple parallel jobs' do @@ -53,6 +57,10 @@ describe Ci::DagJobGroupEntity do expect(exposed_jobs.first.fetch(:name)).to eq 'test 1/2' expect(exposed_jobs.last.fetch(:name)).to eq 'test 2/2' end + + it 'matches schema' do + expect(subject.to_json).to match_schema('entities/dag_job_group') + end end end end diff --git a/spec/serializers/ci/dag_pipeline_entity_spec.rb b/spec/serializers/ci/dag_pipeline_entity_spec.rb index fab8798effc..e1703b09f97 100644 --- a/spec/serializers/ci/dag_pipeline_entity_spec.rb +++ b/spec/serializers/ci/dag_pipeline_entity_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Ci::DagPipelineEntity do +RSpec.describe Ci::DagPipelineEntity do let_it_be(:request) { double(:request) } let(:pipeline) { create(:ci_pipeline) } @@ -11,12 +11,20 @@ describe Ci::DagPipelineEntity do describe '#as_json' do subject { entity.as_json } + RSpec.shared_examples "matches schema" do + it 'matches schema' do + expect(subject.to_json).to match_schema('entities/dag_pipeline') + end + end + context 'when pipeline is empty' do it 'contains stages' do expect(subject).to include(:stages) expect(subject[:stages]).to be_empty end + + it_behaves_like "matches schema" end context 'when pipeline has jobs' do @@ -30,6 +38,8 @@ describe Ci::DagPipelineEntity do expect(stages.size).to eq 3 expect(stages.map { |s| s[:name] }).to contain_exactly('build', 'test', 'deploy') end + + it_behaves_like "matches schema" end context 'when pipeline has parallel jobs, DAG needs and GenericCommitStatus' do @@ -138,6 +148,8 @@ describe Ci::DagPipelineEntity do expect(subject.fetch(:stages)[2].fetch(:name)).to eq 'deploy' expect(subject.fetch(:stages)[2]).to eq expected_result.fetch(:stages)[2] end + + it_behaves_like "matches schema" end end end diff --git a/spec/serializers/ci/dag_pipeline_serializer_spec.rb b/spec/serializers/ci/dag_pipeline_serializer_spec.rb index abf895c3e77..856f6760d5d 100644 --- a/spec/serializers/ci/dag_pipeline_serializer_spec.rb +++ b/spec/serializers/ci/dag_pipeline_serializer_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Ci::DagPipelineSerializer do +RSpec.describe Ci::DagPipelineSerializer do describe '#represent' do subject { described_class.new.represent(pipeline) } @@ -13,5 +13,9 @@ describe Ci::DagPipelineSerializer do expect(subject[:stages]).to be_present expect(subject[:stages].size).to eq 1 end + + it 'matches schema' do + expect(subject.to_json).to match_schema('entities/dag_pipeline') + end end end diff --git a/spec/serializers/ci/dag_stage_entity_spec.rb b/spec/serializers/ci/dag_stage_entity_spec.rb index 5c6aa7faee4..0262ccdac68 100644 --- a/spec/serializers/ci/dag_stage_entity_spec.rb +++ b/spec/serializers/ci/dag_stage_entity_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Ci::DagStageEntity do +RSpec.describe Ci::DagStageEntity do let_it_be(:pipeline) { create(:ci_pipeline) } let_it_be(:request) { double(:request) } @@ -27,5 +27,9 @@ describe Ci::DagStageEntity do expect(job_group[:size]).to eq 1 expect(job_group[:jobs]).not_to be_empty end + + it "matches schema" do + expect(subject.to_json).to match_schema('entities/dag_stage') + end end end diff --git a/spec/serializers/ci/daily_build_group_report_result_entity_spec.rb b/spec/serializers/ci/daily_build_group_report_result_entity_spec.rb index cc35b3bc8b8..f468acdcc64 100644 --- a/spec/serializers/ci/daily_build_group_report_result_entity_spec.rb +++ b/spec/serializers/ci/daily_build_group_report_result_entity_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Ci::DailyBuildGroupReportResultEntity do +RSpec.describe Ci::DailyBuildGroupReportResultEntity do let(:report_result) { double(date: '2020-05-20', group_name: 'rspec', data: { 'coverage' => 79.1 }) } let(:entity) { described_class.new(report_result, param_type: param_type) } let(:param_type) { 'coverage' } 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 4a781971ae0..69bf599c0dd 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 @@ -2,7 +2,7 @@ require 'spec_helper' -describe Ci::DailyBuildGroupReportResultSerializer do +RSpec.describe Ci::DailyBuildGroupReportResultSerializer do let(:report_result) do [ double(date: '2020-05-20', group_name: 'rspec', data: { 'coverage' => 79.1 }), diff --git a/spec/serializers/group_variable_entity_spec.rb b/spec/serializers/ci/group_variable_entity_spec.rb index e6b51e0d626..a7e12905924 100644 --- a/spec/serializers/group_variable_entity_spec.rb +++ b/spec/serializers/ci/group_variable_entity_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe GroupVariableEntity do +RSpec.describe Ci::GroupVariableEntity do let(:variable) { create(:ci_group_variable) } let(:entity) { described_class.new(variable) } diff --git a/spec/serializers/variable_entity_spec.rb b/spec/serializers/ci/variable_entity_spec.rb index 3cb18dab314..38da0b16bbd 100644 --- a/spec/serializers/variable_entity_spec.rb +++ b/spec/serializers/ci/variable_entity_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe VariableEntity do +RSpec.describe Ci::VariableEntity do let(:variable) { create(:ci_variable) } let(:entity) { described_class.new(variable) } diff --git a/spec/serializers/cluster_application_entity_spec.rb b/spec/serializers/cluster_application_entity_spec.rb index b81bdaa0d72..aa2bb25b17c 100644 --- a/spec/serializers/cluster_application_entity_spec.rb +++ b/spec/serializers/cluster_application_entity_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe ClusterApplicationEntity do +RSpec.describe ClusterApplicationEntity do describe '#as_json' do let(:application) { build(:clusters_applications_helm, version: '0.1.1') } diff --git a/spec/serializers/cluster_entity_spec.rb b/spec/serializers/cluster_entity_spec.rb index 16247eef655..223d37b6acd 100644 --- a/spec/serializers/cluster_entity_spec.rb +++ b/spec/serializers/cluster_entity_spec.rb @@ -2,9 +2,14 @@ require 'spec_helper' -describe ClusterEntity do +RSpec.describe ClusterEntity do + include Gitlab::Routing.url_helpers + describe '#as_json' do - subject { described_class.new(cluster).as_json } + let(:user) { nil } + let(:request) { EntityRequest.new({ current_user: user }) } + + subject { described_class.new(cluster, request: request).as_json } context 'when provider type is gcp' do let(:cluster) { create(:cluster, :instance, provider_type: :gcp, provider_gcp: provider) } @@ -40,7 +45,7 @@ describe ClusterEntity do context 'when no application has been installed' do let(:cluster) { create(:cluster, :instance) } - subject { described_class.new(cluster).as_json[:applications]} + subject { described_class.new(cluster, request: request).as_json[:applications]} it 'contains helm as not_installable' do expect(subject).not_to be_empty @@ -50,5 +55,28 @@ describe ClusterEntity do expect(helm[:status]).to eq(:not_installable) end end + + context 'gitlab_managed_apps_logs_path' do + let(:cluster) { create(:cluster, :project) } + let(:user) { create(:user) } + + subject { described_class.new(cluster, request: request).as_json } + + before do + allow_next_instance_of(Clusters::ClusterPresenter) do |presenter| + allow(presenter).to receive(:show_path).and_return(nil) + end + end + + it 'return projects log explorer path' do + log_explorer_path = project_logs_path(cluster.project, cluster_id: cluster.id) + + expect_next_instance_of(Clusters::ClusterPresenter, cluster, current_user: user) do |presenter| + expect(presenter).to receive(:gitlab_managed_apps_logs_path).and_return(log_explorer_path) + end + + expect(subject[:gitlab_managed_apps_logs_path]).to eq(log_explorer_path) + end + end end end diff --git a/spec/serializers/cluster_serializer_spec.rb b/spec/serializers/cluster_serializer_spec.rb index b7d7307d40b..ea1cf6ff59a 100644 --- a/spec/serializers/cluster_serializer_spec.rb +++ b/spec/serializers/cluster_serializer_spec.rb @@ -2,17 +2,18 @@ require 'spec_helper' -describe ClusterSerializer do +RSpec.describe ClusterSerializer do let(:cluster) { create(:cluster, :project, provider_type: :user) } describe '#represent_list' do - subject { described_class.new.represent_list(cluster).keys } + subject { described_class.new(current_user: nil).represent_list(cluster).keys } it 'serializes attrs correctly' do is_expected.to contain_exactly( :cluster_type, :enabled, :environment_scope, + :gitlab_managed_apps_logs_path, :name, :nodes, :path, @@ -22,7 +23,7 @@ describe ClusterSerializer do end describe '#represent_status' do - subject { described_class.new.represent_status(cluster).keys } + subject { described_class.new(current_user: nil).represent_status(cluster).keys } context 'when provider type is gcp and cluster is errored' do let(:cluster) do diff --git a/spec/serializers/commit_entity_spec.rb b/spec/serializers/commit_entity_spec.rb index 6abe8504b93..e2ea63893a4 100644 --- a/spec/serializers/commit_entity_spec.rb +++ b/spec/serializers/commit_entity_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe CommitEntity do +RSpec.describe CommitEntity do let(:signature_html) { 'TEST' } let(:entity) do diff --git a/spec/serializers/container_repositories_serializer_spec.rb b/spec/serializers/container_repositories_serializer_spec.rb index 382778389b3..a0d08a8ba44 100644 --- a/spec/serializers/container_repositories_serializer_spec.rb +++ b/spec/serializers/container_repositories_serializer_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe ContainerRepositoriesSerializer do +RSpec.describe ContainerRepositoriesSerializer do let(:user) { create(:user) } let(:project) { create(:project) } let(:resource) { create(:container_repository, name: 'image', project: project) } diff --git a/spec/serializers/container_repository_entity_spec.rb b/spec/serializers/container_repository_entity_spec.rb index 1f85c6e6a46..43969c63471 100644 --- a/spec/serializers/container_repository_entity_spec.rb +++ b/spec/serializers/container_repository_entity_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe ContainerRepositoryEntity do +RSpec.describe ContainerRepositoryEntity do let_it_be(:project) { create(:project) } let_it_be(:user) { create(:user) } let_it_be(:repository) { create(:container_repository, project: project) } diff --git a/spec/serializers/container_tag_entity_spec.rb b/spec/serializers/container_tag_entity_spec.rb index 8440e56f08f..8e47a6269bc 100644 --- a/spec/serializers/container_tag_entity_spec.rb +++ b/spec/serializers/container_tag_entity_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe ContainerTagEntity do +RSpec.describe ContainerTagEntity do let_it_be(:project) { create(:project) } let_it_be(:user) { create(:user) } let_it_be(:repository) { create(:container_repository, name: 'image', project: project) } diff --git a/spec/serializers/deploy_key_entity_spec.rb b/spec/serializers/deploy_key_entity_spec.rb index 0dbbf0de59b..3404d27a23c 100644 --- a/spec/serializers/deploy_key_entity_spec.rb +++ b/spec/serializers/deploy_key_entity_spec.rb @@ -2,15 +2,16 @@ require 'spec_helper' -describe DeployKeyEntity do +RSpec.describe DeployKeyEntity do include RequestAwareEntity let(:user) { create(:user) } let(:project) { create(:project, :internal)} let(:project_private) { create(:project, :private)} let(:deploy_key) { create(:deploy_key) } + let(:options) { { user: user } } - let(:entity) { described_class.new(deploy_key, user: user) } + let(:entity) { described_class.new(deploy_key, options) } before do project.deploy_keys << deploy_key @@ -74,4 +75,42 @@ describe DeployKeyEntity do it { expect(entity_public.as_json).to include(can_edit: true) } end end + + describe 'with_owner option' do + it 'does not return an owner payload when it is set to false' do + options[:with_owner] = false + + payload = entity.as_json + + expect(payload[:owner]).not_to be_present + end + + describe 'when with_owner is set to true' do + before do + options[:with_owner] = true + end + + it 'returns an owner payload' do + payload = entity.as_json + + expect(payload[:owner]).to be_present + expect(payload[:owner].keys).to include(:id, :name, :username, :avatar_url) + end + + it 'does not return an owner if current_user cannot read the owner' do + allow(Ability).to receive(:allowed?).and_call_original + allow(Ability).to receive(:allowed?).with(options[:user], :read_user, deploy_key.user).and_return(false) + + payload = entity.as_json + + expect(payload[:owner]).to be_nil + end + end + end + + it 'does not return an owner payload with_owner option not passed in' do + payload = entity.as_json + + expect(payload[:owner]).not_to be_present + end end diff --git a/spec/serializers/deployment_cluster_entity_spec.rb b/spec/serializers/deployment_cluster_entity_spec.rb index b22a93fcec7..95f2f8ce6fc 100644 --- a/spec/serializers/deployment_cluster_entity_spec.rb +++ b/spec/serializers/deployment_cluster_entity_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe DeploymentClusterEntity do +RSpec.describe DeploymentClusterEntity do describe '#as_json' do subject { described_class.new(deployment, request: request).as_json } diff --git a/spec/serializers/deployment_entity_spec.rb b/spec/serializers/deployment_entity_spec.rb index 7abe74fae8f..27673b905d3 100644 --- a/spec/serializers/deployment_entity_spec.rb +++ b/spec/serializers/deployment_entity_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe DeploymentEntity do +RSpec.describe DeploymentEntity do let(:user) { developer } let(:developer) { create(:user) } let(:reporter) { create(:user) } diff --git a/spec/serializers/deployment_serializer_spec.rb b/spec/serializers/deployment_serializer_spec.rb index 67fccaa3f25..cfd43227b18 100644 --- a/spec/serializers/deployment_serializer_spec.rb +++ b/spec/serializers/deployment_serializer_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe DeploymentSerializer do +RSpec.describe DeploymentSerializer do let_it_be(:project) { create(:project, :repository) } let_it_be(:user) { create(:user, email: project.commit.author_email) } let(:resource) { create(:deployment, project: project, sha: project.commit.id) } diff --git a/spec/serializers/detailed_status_entity_spec.rb b/spec/serializers/detailed_status_entity_spec.rb index a4b51f1e02e..33ecb4572a8 100644 --- a/spec/serializers/detailed_status_entity_spec.rb +++ b/spec/serializers/detailed_status_entity_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe DetailedStatusEntity do +RSpec.describe DetailedStatusEntity do let(:entity) { described_class.new(status) } let(:status) do diff --git a/spec/serializers/diff_file_base_entity_spec.rb b/spec/serializers/diff_file_base_entity_spec.rb index 1fd697970de..153f854aa58 100644 --- a/spec/serializers/diff_file_base_entity_spec.rb +++ b/spec/serializers/diff_file_base_entity_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe DiffFileBaseEntity do +RSpec.describe DiffFileBaseEntity do let(:project) { create(:project, :repository) } let(:repository) { project.repository } let(:entity) { described_class.new(diff_file, options).as_json } @@ -40,10 +40,6 @@ describe DiffFileBaseEntity do let(:options) { { request: EntityRequest.new(current_user: create(:user)), merge_request: merge_request } } let(:params) { {} } - before do - stub_feature_flags(web_ide_default: false) - end - shared_examples 'a diff file edit path to the source branch' do it do expect(entity[:edit_path]).to eq(Gitlab::Routing.url_helpers.project_edit_blob_path(project, File.join(merge_request.source_branch, diff_file.new_path), params)) diff --git a/spec/serializers/diff_file_entity_spec.rb b/spec/serializers/diff_file_entity_spec.rb index e3ecd72b275..bebe2e2dfb5 100644 --- a/spec/serializers/diff_file_entity_spec.rb +++ b/spec/serializers/diff_file_entity_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe DiffFileEntity do +RSpec.describe DiffFileEntity do include RepoHelpers let_it_be(:project) { create(:project, :repository) } diff --git a/spec/serializers/diff_line_entity_spec.rb b/spec/serializers/diff_line_entity_spec.rb index 2549f64bcd3..862b06c800a 100644 --- a/spec/serializers/diff_line_entity_spec.rb +++ b/spec/serializers/diff_line_entity_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe DiffLineEntity do +RSpec.describe DiffLineEntity do include RepoHelpers let(:code) { 'hello world' } diff --git a/spec/serializers/diff_line_serializer_spec.rb b/spec/serializers/diff_line_serializer_spec.rb index bdfcb8e2459..b91f15211de 100644 --- a/spec/serializers/diff_line_serializer_spec.rb +++ b/spec/serializers/diff_line_serializer_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe DiffLineSerializer do +RSpec.describe DiffLineSerializer do let(:line) { Gitlab::Diff::Line.new('hello world', 'new', 1, nil, 1) } let(:serializer) { described_class.new.represent(line) } diff --git a/spec/serializers/diff_viewer_entity_spec.rb b/spec/serializers/diff_viewer_entity_spec.rb index 76d2728c597..53601fcff61 100644 --- a/spec/serializers/diff_viewer_entity_spec.rb +++ b/spec/serializers/diff_viewer_entity_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe DiffViewerEntity do +RSpec.describe DiffViewerEntity do include RepoHelpers let(:project) { create(:project, :repository) } diff --git a/spec/serializers/diffs_entity_spec.rb b/spec/serializers/diffs_entity_spec.rb index 435d8a6aff2..7c59e4aed83 100644 --- a/spec/serializers/diffs_entity_spec.rb +++ b/spec/serializers/diffs_entity_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe DiffsEntity do +RSpec.describe DiffsEntity do let(:user) { create(:user) } let(:project) { create(:project, :repository) } let(:request) { EntityRequest.new(project: project, current_user: user) } diff --git a/spec/serializers/diffs_metadata_entity_spec.rb b/spec/serializers/diffs_metadata_entity_spec.rb index 3ed2b7c9452..8ed47569b75 100644 --- a/spec/serializers/diffs_metadata_entity_spec.rb +++ b/spec/serializers/diffs_metadata_entity_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe DiffsMetadataEntity do +RSpec.describe DiffsMetadataEntity do let(:user) { create(:user) } let(:project) { create(:project, :repository) } let(:request) { EntityRequest.new(project: project, current_user: user) } diff --git a/spec/serializers/discussion_diff_file_entity_spec.rb b/spec/serializers/discussion_diff_file_entity_spec.rb index 101ac918a98..05438450d78 100644 --- a/spec/serializers/discussion_diff_file_entity_spec.rb +++ b/spec/serializers/discussion_diff_file_entity_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe DiscussionDiffFileEntity do +RSpec.describe DiscussionDiffFileEntity do include RepoHelpers let(:project) { create(:project, :repository) } diff --git a/spec/serializers/discussion_entity_spec.rb b/spec/serializers/discussion_entity_spec.rb index b441fd08b98..306a4fa43a9 100644 --- a/spec/serializers/discussion_entity_spec.rb +++ b/spec/serializers/discussion_entity_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe DiscussionEntity do +RSpec.describe DiscussionEntity do include RepoHelpers let(:user) { create(:user) } diff --git a/spec/serializers/entity_date_helper_spec.rb b/spec/serializers/entity_date_helper_spec.rb index 6f99074c3a2..a8c338675e2 100644 --- a/spec/serializers/entity_date_helper_spec.rb +++ b/spec/serializers/entity_date_helper_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe EntityDateHelper do +RSpec.describe EntityDateHelper do let(:date_helper_class) { Class.new { include EntityDateHelper }.new } it 'converts 0 seconds' do diff --git a/spec/serializers/entity_request_spec.rb b/spec/serializers/entity_request_spec.rb index 947c4b165d3..43a53b57c97 100644 --- a/spec/serializers/entity_request_spec.rb +++ b/spec/serializers/entity_request_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe EntityRequest do +RSpec.describe EntityRequest do subject do described_class.new(user: 'user', project: 'some project') end diff --git a/spec/serializers/environment_entity_spec.rb b/spec/serializers/environment_entity_spec.rb index 36e971c467a..6232a0d2973 100644 --- a/spec/serializers/environment_entity_spec.rb +++ b/spec/serializers/environment_entity_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe EnvironmentEntity do +RSpec.describe EnvironmentEntity do include Gitlab::Routing.url_helpers let(:request) { double('request') } diff --git a/spec/serializers/environment_serializer_spec.rb b/spec/serializers/environment_serializer_spec.rb index 304457d83a1..1e3980b7720 100644 --- a/spec/serializers/environment_serializer_spec.rb +++ b/spec/serializers/environment_serializer_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe EnvironmentSerializer do +RSpec.describe EnvironmentSerializer do let(:user) { create(:user) } let(:project) { create(:project) } diff --git a/spec/serializers/environment_status_entity_spec.rb b/spec/serializers/environment_status_entity_spec.rb index 11455c57677..a940c4b465e 100644 --- a/spec/serializers/environment_status_entity_spec.rb +++ b/spec/serializers/environment_status_entity_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe EnvironmentStatusEntity do +RSpec.describe EnvironmentStatusEntity do let(:user) { create(:user) } let(:request) { double('request', project: project) } diff --git a/spec/serializers/evidences/evidence_entity_spec.rb b/spec/serializers/evidences/evidence_entity_spec.rb index fa13bd21edd..8ec0422fea2 100644 --- a/spec/serializers/evidences/evidence_entity_spec.rb +++ b/spec/serializers/evidences/evidence_entity_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Evidences::EvidenceEntity do +RSpec.describe Evidences::EvidenceEntity do let_it_be(:project) { create(:project) } let(:release) { create(:release, project: project) } let(:evidence) { build(:evidence, release: release) } diff --git a/spec/serializers/evidences/evidence_serializer_spec.rb b/spec/serializers/evidences/evidence_serializer_spec.rb index 5322f6a43fc..73d0700b7cf 100644 --- a/spec/serializers/evidences/evidence_serializer_spec.rb +++ b/spec/serializers/evidences/evidence_serializer_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Evidences::EvidenceSerializer do +RSpec.describe Evidences::EvidenceSerializer do it 'represents an EvidenceEntity entity' do expect(described_class.entity_class).to eq(Evidences::EvidenceEntity) end diff --git a/spec/serializers/evidences/issue_entity_spec.rb b/spec/serializers/evidences/issue_entity_spec.rb index 915df986887..71392d0abd9 100644 --- a/spec/serializers/evidences/issue_entity_spec.rb +++ b/spec/serializers/evidences/issue_entity_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Evidences::IssueEntity do +RSpec.describe Evidences::IssueEntity do let(:entity) { described_class.new(build(:issue)) } subject { entity.as_json } diff --git a/spec/serializers/evidences/milestone_entity_spec.rb b/spec/serializers/evidences/milestone_entity_spec.rb index 68eb12093da..337ce966763 100644 --- a/spec/serializers/evidences/milestone_entity_spec.rb +++ b/spec/serializers/evidences/milestone_entity_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Evidences::MilestoneEntity do +RSpec.describe Evidences::MilestoneEntity do let(:milestone) { build(:milestone) } let(:entity) { described_class.new(milestone) } diff --git a/spec/serializers/evidences/project_entity_spec.rb b/spec/serializers/evidences/project_entity_spec.rb index 01c160425a8..d5cb1a53a7e 100644 --- a/spec/serializers/evidences/project_entity_spec.rb +++ b/spec/serializers/evidences/project_entity_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Evidences::ProjectEntity do +RSpec.describe Evidences::ProjectEntity do let(:entity) { described_class.new(build(:project)) } subject { entity.as_json } diff --git a/spec/serializers/evidences/release_entity_spec.rb b/spec/serializers/evidences/release_entity_spec.rb index 8e2be748169..63e25efc65f 100644 --- a/spec/serializers/evidences/release_entity_spec.rb +++ b/spec/serializers/evidences/release_entity_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Evidences::ReleaseEntity do +RSpec.describe Evidences::ReleaseEntity do let(:release) { build(:release) } let(:entity) { described_class.new(release) } diff --git a/spec/serializers/evidences/release_serializer_spec.rb b/spec/serializers/evidences/release_serializer_spec.rb index a0dbf50137c..c93e0cd7c19 100644 --- a/spec/serializers/evidences/release_serializer_spec.rb +++ b/spec/serializers/evidences/release_serializer_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Evidences::ReleaseSerializer do +RSpec.describe Evidences::ReleaseSerializer do it 'represents an Evidence::ReleaseEntity entity' do expect(described_class.entity_class).to eq(Evidences::ReleaseEntity) end diff --git a/spec/serializers/fork_namespace_entity_spec.rb b/spec/serializers/fork_namespace_entity_spec.rb new file mode 100644 index 00000000000..7ce6b77da44 --- /dev/null +++ b/spec/serializers/fork_namespace_entity_spec.rb @@ -0,0 +1,70 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe ForkNamespaceEntity do + include Gitlab::Routing.url_helpers + include ProjectForksHelper + + let_it_be(:user) { create(:user) } + let_it_be(:project) { create(:project) } + + let(:namespace) { create(:group, :with_avatar, description: 'test') } + let(:entity) { described_class.new(namespace, current_user: user, project: project) } + + subject(:json) { entity.as_json } + + before do + project.add_maintainer(user) + end + + it 'renders json' do + is_expected.not_to be_nil + end + + %w[id + name + description + markdown_description + visibility + full_name + created_at + updated_at + avatar_url].each do |attribute| + it "includes #{attribute}" do + expect(json[attribute.to_sym]).to be_present + end + end + + it 'exposes path for forking project to the namespace' do + expect(json[:fork_path]).to eq project_forks_path(project, namespace_key: namespace.id) + end + + it 'exposes forked_project_path when fork exists in namespace' do + namespace.add_maintainer(user) + fork_in_namespace = fork_project(project, user, namespace: namespace) + + expect(json[:forked_project_path]).to eql project_path(fork_in_namespace) + end + + it 'exposes relative path to the namespace' do + expect(json[:relative_path]).to eql polymorphic_path(namespace) + end + + it 'exposes human readable permission level' do + namespace.add_developer(user) + expect(json[:permission]).to eql 'Developer' + end + + it 'sets can_create_project to true when user can create projects in namespace' do + allow(user).to receive(:can?).with(:create_projects, namespace).and_return(true) + + expect(json[:can_create_project]).to be true + end + + it 'sets can_create_project to false when user is not allowed create projects in namespace' do + allow(user).to receive(:can?).with(:create_projects, namespace).and_return(false) + + expect(json[:can_create_project]).to be false + end +end diff --git a/spec/serializers/fork_namespace_serializer_spec.rb b/spec/serializers/fork_namespace_serializer_spec.rb new file mode 100644 index 00000000000..6793b900af6 --- /dev/null +++ b/spec/serializers/fork_namespace_serializer_spec.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe ForkNamespaceSerializer do + it 'represents ForkNamespaceEntity entities' do + expect(described_class.entity_class).to eq(ForkNamespaceEntity) + end +end diff --git a/spec/serializers/group_child_entity_spec.rb b/spec/serializers/group_child_entity_spec.rb index cae263e7fd5..7f330da44a7 100644 --- a/spec/serializers/group_child_entity_spec.rb +++ b/spec/serializers/group_child_entity_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe GroupChildEntity do +RSpec.describe GroupChildEntity do include ExternalAuthorizationServiceHelpers include Gitlab::Routing.url_helpers diff --git a/spec/serializers/group_child_serializer_spec.rb b/spec/serializers/group_child_serializer_spec.rb index 92f083ed23e..63582019d32 100644 --- a/spec/serializers/group_child_serializer_spec.rb +++ b/spec/serializers/group_child_serializer_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe GroupChildSerializer do +RSpec.describe GroupChildSerializer do let(:request) { double('request') } let(:user) { create(:user) } diff --git a/spec/serializers/import/bitbucket_provider_repo_entity_spec.rb b/spec/serializers/import/bitbucket_provider_repo_entity_spec.rb index ed3ef26db65..2a0386b779f 100644 --- a/spec/serializers/import/bitbucket_provider_repo_entity_spec.rb +++ b/spec/serializers/import/bitbucket_provider_repo_entity_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Import::BitbucketProviderRepoEntity do +RSpec.describe Import::BitbucketProviderRepoEntity do let(:repo_data) do { 'name' => 'repo_name', 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 9891809cc67..6e00d608d9a 100644 --- a/spec/serializers/import/bitbucket_server_provider_repo_entity_spec.rb +++ b/spec/serializers/import/bitbucket_server_provider_repo_entity_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Import::BitbucketServerProviderRepoEntity do +RSpec.describe Import::BitbucketServerProviderRepoEntity do let(:repo_data) do { 'name' => 'test', diff --git a/spec/serializers/import/fogbugz_provider_repo_entity_spec.rb b/spec/serializers/import/fogbugz_provider_repo_entity_spec.rb index b9029b67aab..748ddd2a108 100644 --- a/spec/serializers/import/fogbugz_provider_repo_entity_spec.rb +++ b/spec/serializers/import/fogbugz_provider_repo_entity_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Import::FogbugzProviderRepoEntity do +RSpec.describe Import::FogbugzProviderRepoEntity do let(:provider_url) { 'https://demo.fogbugz.com/' } let(:repo_data) do { diff --git a/spec/serializers/import/githubish_provider_repo_entity_spec.rb b/spec/serializers/import/githubish_provider_repo_entity_spec.rb index c6a07b2d64a..b8292f71714 100644 --- a/spec/serializers/import/githubish_provider_repo_entity_spec.rb +++ b/spec/serializers/import/githubish_provider_repo_entity_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Import::GithubishProviderRepoEntity do +RSpec.describe Import::GithubishProviderRepoEntity do let(:provider_url) { 'https://github.com/' } let(:repo) do { diff --git a/spec/serializers/import/gitlab_provider_repo_entity_spec.rb b/spec/serializers/import/gitlab_provider_repo_entity_spec.rb index 3f862c16fe2..25e445d336c 100644 --- a/spec/serializers/import/gitlab_provider_repo_entity_spec.rb +++ b/spec/serializers/import/gitlab_provider_repo_entity_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Import::GitlabProviderRepoEntity do +RSpec.describe Import::GitlabProviderRepoEntity do let(:repo_data) do { 'id' => 1, diff --git a/spec/serializers/import/provider_repo_serializer_spec.rb b/spec/serializers/import/provider_repo_serializer_spec.rb index 9bf55e6c65d..430bad151d3 100644 --- a/spec/serializers/import/provider_repo_serializer_spec.rb +++ b/spec/serializers/import/provider_repo_serializer_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Import::ProviderRepoSerializer do +RSpec.describe Import::ProviderRepoSerializer do using RSpec::Parameterized::TableSyntax describe '#represent' do diff --git a/spec/serializers/issuable_sidebar_extras_entity_spec.rb b/spec/serializers/issuable_sidebar_extras_entity_spec.rb index a1a7c554b49..f49b9acfd5d 100644 --- a/spec/serializers/issuable_sidebar_extras_entity_spec.rb +++ b/spec/serializers/issuable_sidebar_extras_entity_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe IssuableSidebarExtrasEntity do +RSpec.describe IssuableSidebarExtrasEntity do let(:user) { create(:user) } let(:project) { create(:project, :repository) } let(:resource) { create(:issue, project: project) } diff --git a/spec/serializers/issue_board_entity_spec.rb b/spec/serializers/issue_board_entity_spec.rb index d013b27369b..e60a063b9eb 100644 --- a/spec/serializers/issue_board_entity_spec.rb +++ b/spec/serializers/issue_board_entity_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe IssueBoardEntity do +RSpec.describe IssueBoardEntity do let_it_be(:project) { create(:project) } let_it_be(:resource) { create(:issue, project: project) } let_it_be(:user) { create(:user) } diff --git a/spec/serializers/issue_entity_spec.rb b/spec/serializers/issue_entity_spec.rb index a1868b2631b..5c5ac184778 100644 --- a/spec/serializers/issue_entity_spec.rb +++ b/spec/serializers/issue_entity_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe IssueEntity do +RSpec.describe IssueEntity do let(:project) { create(:project) } let(:resource) { create(:issue, project: project) } let(:user) { create(:user) } diff --git a/spec/serializers/issue_serializer_spec.rb b/spec/serializers/issue_serializer_spec.rb index e25becc4709..a51297d6d80 100644 --- a/spec/serializers/issue_serializer_spec.rb +++ b/spec/serializers/issue_serializer_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe IssueSerializer do +RSpec.describe IssueSerializer do let(:resource) { create(:issue) } let(:user) { create(:user) } let(:json_entity) do diff --git a/spec/serializers/job_artifact_report_entity_spec.rb b/spec/serializers/job_artifact_report_entity_spec.rb index 3cd12f0e9fe..1aaaad544ba 100644 --- a/spec/serializers/job_artifact_report_entity_spec.rb +++ b/spec/serializers/job_artifact_report_entity_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe JobArtifactReportEntity do +RSpec.describe JobArtifactReportEntity do let(:report) { create(:ci_job_artifact, :codequality) } let(:entity) { described_class.new(report, request: double) } diff --git a/spec/serializers/job_entity_spec.rb b/spec/serializers/job_entity_spec.rb index 60843f1a599..02262be9511 100644 --- a/spec/serializers/job_entity_spec.rb +++ b/spec/serializers/job_entity_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe JobEntity do +RSpec.describe JobEntity do let(:user) { create(:user) } let(:job) { create(:ci_build) } let(:project) { job.project } diff --git a/spec/serializers/label_serializer_spec.rb b/spec/serializers/label_serializer_spec.rb index 7e1bb2cc127..ae1466b16e5 100644 --- a/spec/serializers/label_serializer_spec.rb +++ b/spec/serializers/label_serializer_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe LabelSerializer do +RSpec.describe LabelSerializer do let(:user) { create(:user) } let(:serializer) do diff --git a/spec/serializers/lfs_file_lock_entity_spec.rb b/spec/serializers/lfs_file_lock_entity_spec.rb index 4ffffad7d5a..5869941c920 100644 --- a/spec/serializers/lfs_file_lock_entity_spec.rb +++ b/spec/serializers/lfs_file_lock_entity_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe LfsFileLockEntity do +RSpec.describe LfsFileLockEntity do let(:user) { create(:user) } let(:resource) { create(:lfs_file_lock, user: user) } diff --git a/spec/serializers/merge_request_basic_entity_spec.rb b/spec/serializers/merge_request_basic_entity_spec.rb index 53ba66a79ac..1cddd87e917 100644 --- a/spec/serializers/merge_request_basic_entity_spec.rb +++ b/spec/serializers/merge_request_basic_entity_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe MergeRequestBasicEntity do +RSpec.describe MergeRequestBasicEntity do let(:resource) { build(:merge_request) } subject do diff --git a/spec/serializers/merge_request_diff_entity_spec.rb b/spec/serializers/merge_request_diff_entity_spec.rb index 2e3b0d092fe..542ef6cb3c3 100644 --- a/spec/serializers/merge_request_diff_entity_spec.rb +++ b/spec/serializers/merge_request_diff_entity_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe MergeRequestDiffEntity do +RSpec.describe MergeRequestDiffEntity do let_it_be(:project) { create(:project, :repository) } let(:request) { EntityRequest.new(project: project) } let(:merge_request) { create(:merge_request_with_diffs, target_project: project, source_project: project) } diff --git a/spec/serializers/merge_request_for_pipeline_entity_spec.rb b/spec/serializers/merge_request_for_pipeline_entity_spec.rb index b39fbce8c3a..ed66716974a 100644 --- a/spec/serializers/merge_request_for_pipeline_entity_spec.rb +++ b/spec/serializers/merge_request_for_pipeline_entity_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe MergeRequestForPipelineEntity do +RSpec.describe MergeRequestForPipelineEntity do let(:project) { create(:project, :repository) } let(:user) { create(:user) } let(:request) { EntityRequest.new(project: project) } diff --git a/spec/serializers/merge_request_poll_cached_widget_entity_spec.rb b/spec/serializers/merge_request_poll_cached_widget_entity_spec.rb index 9f96e5711a4..51564de6041 100644 --- a/spec/serializers/merge_request_poll_cached_widget_entity_spec.rb +++ b/spec/serializers/merge_request_poll_cached_widget_entity_spec.rb @@ -2,8 +2,9 @@ require 'spec_helper' -describe MergeRequestPollCachedWidgetEntity do +RSpec.describe MergeRequestPollCachedWidgetEntity do include ProjectForksHelper + using RSpec::Parameterized::TableSyntax let(:project) { create :project, :repository } let(:resource) { create(:merge_request, source_project: project, target_project: project) } @@ -181,6 +182,27 @@ describe MergeRequestPollCachedWidgetEntity do end end + describe 'squash defaults for projects' do + where(:squash_option, :value, :default, :readonly) do + 'always' | true | true | true + 'never' | false | false | true + 'default_on' | false | true | false + 'default_off' | false | false | false + end + + with_them do + before do + project.project_setting.update!(squash_option: squash_option) + end + + it 'the key reflects the correct value' do + expect(subject[:squash_on_merge]).to eq(value) + expect(subject[:squash_enabled_by_default]).to eq(default) + expect(subject[:squash_readonly]).to eq(readonly) + end + end + end + describe 'attributes for squash commit message' do context 'when merge request is mergeable' do before do diff --git a/spec/serializers/merge_request_poll_widget_entity_spec.rb b/spec/serializers/merge_request_poll_widget_entity_spec.rb index 4b3bfc99c88..f0493699209 100644 --- a/spec/serializers/merge_request_poll_widget_entity_spec.rb +++ b/spec/serializers/merge_request_poll_widget_entity_spec.rb @@ -2,8 +2,9 @@ require 'spec_helper' -describe MergeRequestPollWidgetEntity do +RSpec.describe MergeRequestPollWidgetEntity do include ProjectForksHelper + using RSpec::Parameterized::TableSyntax let(:project) { create :project, :repository } let(:resource) { create(:merge_request, source_project: project, target_project: project) } @@ -171,6 +172,27 @@ describe MergeRequestPollWidgetEntity do end end + describe 'squash defaults for projects' do + where(:squash_option, :value, :default, :readonly) do + 'always' | true | true | true + 'never' | false | false | true + 'default_on' | false | true | false + 'default_off' | false | false | false + end + + with_them do + before do + project.project_setting.update!(squash_option: squash_option) + end + + it 'the key reflects the correct value' do + expect(subject[:squash_on_merge]).to eq(value) + expect(subject[:squash_enabled_by_default]).to eq(default) + expect(subject[:squash_readonly]).to eq(readonly) + end + end + end + context 'when head pipeline is finished' do before do create(:ci_pipeline, :success, project: project, diff --git a/spec/serializers/merge_request_serializer_spec.rb b/spec/serializers/merge_request_serializer_spec.rb index 90b3efae412..a2ce1ed4ac2 100644 --- a/spec/serializers/merge_request_serializer_spec.rb +++ b/spec/serializers/merge_request_serializer_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe MergeRequestSerializer do +RSpec.describe MergeRequestSerializer do let_it_be(:user) { create(:user) } let_it_be(:resource) { create(:merge_request, description: "Description") } diff --git a/spec/serializers/merge_request_sidebar_basic_entity_spec.rb b/spec/serializers/merge_request_sidebar_basic_entity_spec.rb index b2db57801ea..e950e6d6592 100644 --- a/spec/serializers/merge_request_sidebar_basic_entity_spec.rb +++ b/spec/serializers/merge_request_sidebar_basic_entity_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe MergeRequestSidebarBasicEntity do +RSpec.describe MergeRequestSidebarBasicEntity do let(:project) { create :project, :repository } let(:merge_request) { create(:merge_request, source_project: project, target_project: project) } let(:user) { create(:user) } diff --git a/spec/serializers/merge_request_user_entity_spec.rb b/spec/serializers/merge_request_user_entity_spec.rb index 47b9b0a57ab..8d6f066481e 100644 --- a/spec/serializers/merge_request_user_entity_spec.rb +++ b/spec/serializers/merge_request_user_entity_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe MergeRequestUserEntity do +RSpec.describe MergeRequestUserEntity do let(:user) { create(:user) } let(:project) { create(:project, :repository) } let(:request) { EntityRequest.new(project: project, current_user: user) } diff --git a/spec/serializers/merge_request_widget_commit_entity_spec.rb b/spec/serializers/merge_request_widget_commit_entity_spec.rb index ce83978c49a..0d13308f27d 100644 --- a/spec/serializers/merge_request_widget_commit_entity_spec.rb +++ b/spec/serializers/merge_request_widget_commit_entity_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe MergeRequestWidgetCommitEntity do +RSpec.describe MergeRequestWidgetCommitEntity do let(:project) { create(:project, :repository) } let(:commit) { project.commit } let(:request) { double('request') } diff --git a/spec/serializers/merge_request_widget_entity_spec.rb b/spec/serializers/merge_request_widget_entity_spec.rb index 039fb311bfc..aaee47fb981 100644 --- a/spec/serializers/merge_request_widget_entity_spec.rb +++ b/spec/serializers/merge_request_widget_entity_spec.rb @@ -2,11 +2,12 @@ require 'spec_helper' -describe MergeRequestWidgetEntity do +RSpec.describe MergeRequestWidgetEntity do include ProjectForksHelper let(:project) { create :project, :repository } let(:resource) { create(:merge_request, source_project: project, target_project: project) } + let(:pipeline) { create(:ci_empty_pipeline, project: project) } let(:user) { create(:user) } let(:request) { double('request', current_user: user, project: project) } @@ -53,6 +54,42 @@ describe MergeRequestWidgetEntity do .to eq("/#{resource.project.full_path}/-/merge_requests/#{resource.iid}.diff") end + it 'has blob path data' do + allow(resource).to receive_messages( + base_pipeline: pipeline, + head_pipeline: pipeline + ) + + expect(subject).to include(:blob_path) + expect(subject[:blob_path]).to include(:base_path) + expect(subject[:blob_path]).to include(:head_path) + end + + describe 'codequality report artifacts', :request_store do + before do + project.add_developer(user) + + allow(resource).to receive_messages( + base_pipeline: pipeline, + head_pipeline: pipeline + ) + end + + context "with report artifacts" do + let(:pipeline) { create(:ci_pipeline, :with_codequality_report, project: project) } + + it "has data entry" do + expect(subject).to include(:codeclimate) + end + end + + context "without artifacts" do + it "does not have data entry" do + expect(subject).not_to include(:codeclimate) + end + end + end + describe 'merge_request_add_ci_config_path' do let!(:project_auto_devops) { create(:project_auto_devops, :disabled, project: project) } @@ -155,6 +192,36 @@ describe MergeRequestWidgetEntity do expect(subject[:merge_request_add_ci_config_path]).to be_nil end end + + context 'when merge request is merged' do + before do + resource.mark_as_merged! + end + + it 'returns a blank ci config path' do + expect(subject[:merge_request_add_ci_config_path]).to be_nil + end + end + + context 'when merge request is closed' do + before do + resource.close! + end + + it 'returns a blank ci config path' do + expect(subject[:merge_request_add_ci_config_path]).to be_nil + end + end + + context 'when source branch does not exist' do + before do + resource.source_project.repository.rm_branch(user, resource.source_branch) + end + + it 'returns a blank ci config path' do + expect(subject[:merge_request_add_ci_config_path]).to be_nil + end + end end context 'when user does not have permissions' do diff --git a/spec/serializers/move_to_project_entity_spec.rb b/spec/serializers/move_to_project_entity_spec.rb index ac495eadb68..a14bc3ae622 100644 --- a/spec/serializers/move_to_project_entity_spec.rb +++ b/spec/serializers/move_to_project_entity_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe MoveToProjectEntity do +RSpec.describe MoveToProjectEntity do describe '#as_json' do let(:project) { build(:project, id: 1) } diff --git a/spec/serializers/move_to_project_serializer_spec.rb b/spec/serializers/move_to_project_serializer_spec.rb index 841ac969eeb..60bcca3269f 100644 --- a/spec/serializers/move_to_project_serializer_spec.rb +++ b/spec/serializers/move_to_project_serializer_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe MoveToProjectSerializer do +RSpec.describe MoveToProjectSerializer do describe '#represent' do it 'includes the name and name with namespace' do project = build(:project, id: 1) diff --git a/spec/serializers/namespace_basic_entity_spec.rb b/spec/serializers/namespace_basic_entity_spec.rb index d3d666d57aa..8b69af5696a 100644 --- a/spec/serializers/namespace_basic_entity_spec.rb +++ b/spec/serializers/namespace_basic_entity_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe NamespaceBasicEntity do +RSpec.describe NamespaceBasicEntity do let_it_be(:group) { create(:group) } let(:entity) do described_class.represent(group) diff --git a/spec/serializers/namespace_serializer_spec.rb b/spec/serializers/namespace_serializer_spec.rb index 6e5bdd8c52d..0c4b099ef60 100644 --- a/spec/serializers/namespace_serializer_spec.rb +++ b/spec/serializers/namespace_serializer_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe NamespaceSerializer do +RSpec.describe NamespaceSerializer do it 'represents NamespaceBasicEntity entities' do expect(described_class.entity_class).to eq(NamespaceBasicEntity) end diff --git a/spec/serializers/note_entity_spec.rb b/spec/serializers/note_entity_spec.rb index f37fffb5048..19438e69a10 100644 --- a/spec/serializers/note_entity_spec.rb +++ b/spec/serializers/note_entity_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe NoteEntity do +RSpec.describe NoteEntity do include Gitlab::Routing let(:request) { double('request', current_user: user, noteable: note.noteable) } diff --git a/spec/serializers/paginated_diff_entity_spec.rb b/spec/serializers/paginated_diff_entity_spec.rb index a6b83cb4286..30360b00537 100644 --- a/spec/serializers/paginated_diff_entity_spec.rb +++ b/spec/serializers/paginated_diff_entity_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe PaginatedDiffEntity do +RSpec.describe PaginatedDiffEntity do let(:user) { create(:user) } let(:request) { double('request', current_user: user) } let(:merge_request) { create(:merge_request, :with_diffs) } diff --git a/spec/serializers/pipeline_details_entity_spec.rb b/spec/serializers/pipeline_details_entity_spec.rb index 849dab102c2..35ce7c7175c 100644 --- a/spec/serializers/pipeline_details_entity_spec.rb +++ b/spec/serializers/pipeline_details_entity_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe PipelineDetailsEntity do +RSpec.describe PipelineDetailsEntity do let_it_be(:user) { create(:user) } let(:request) { double('request') } @@ -157,20 +157,30 @@ describe PipelineDetailsEntity do context 'when pipeline triggered other pipeline' do let(:pipeline) { create(:ci_empty_pipeline) } - let(:build) { create(:ci_build, pipeline: pipeline) } + let(:build) { create(:ci_build, name: 'child', stage: 'test', pipeline: pipeline) } + let(:bridge) { create(:ci_bridge, name: 'cross-project', stage: 'build', pipeline: pipeline) } + let(:child_pipeline) { create(:ci_pipeline, project: pipeline.project) } + let(:cross_project_pipeline) { create(:ci_pipeline) } before do - create(:ci_sources_pipeline, source_job: build) - create(:ci_sources_pipeline, source_job: build) + create(:ci_sources_pipeline, source_job: build, pipeline: child_pipeline) + create(:ci_sources_pipeline, source_job: bridge, pipeline: cross_project_pipeline) end - it 'contains an information about depedent pipeline' do + it 'contains an information about dependent pipeline', :aggregate_failures do expect(subject[:triggered]).to be_a(Array) expect(subject[:triggered].length).to eq(2) expect(subject[:triggered].first[:path]).not_to be_nil expect(subject[:triggered].first[:details]).not_to be_nil expect(subject[:triggered].first[:details][:status]).not_to be_nil expect(subject[:triggered].first[:project]).not_to be_nil + + source_jobs = subject[:triggered] + .index_by { |pipeline| pipeline[:id] } + .transform_values { |pipeline| pipeline.fetch(:source_job) } + + expect(source_jobs[cross_project_pipeline.id][:name]).to eq('cross-project') + expect(source_jobs[child_pipeline.id][:name]).to eq('child') end end end diff --git a/spec/serializers/pipeline_entity_spec.rb b/spec/serializers/pipeline_entity_spec.rb index 914f42054bd..e638b14765b 100644 --- a/spec/serializers/pipeline_entity_spec.rb +++ b/spec/serializers/pipeline_entity_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe PipelineEntity do +RSpec.describe PipelineEntity do include Gitlab::Routing let_it_be(:project) { create(:project) } @@ -261,5 +261,29 @@ describe PipelineEntity do end end end + + 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 + end + end end end diff --git a/spec/serializers/pipeline_serializer_spec.rb b/spec/serializers/pipeline_serializer_spec.rb index c8f25423f85..c1386ac4eb2 100644 --- a/spec/serializers/pipeline_serializer_spec.rb +++ b/spec/serializers/pipeline_serializer_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe PipelineSerializer do +RSpec.describe PipelineSerializer do let_it_be(:project) { create(:project, :repository) } let_it_be(:user) { create(:user) } @@ -155,11 +155,25 @@ describe PipelineSerializer do it 'verifies number of queries', :request_store do recorded = ActiveRecord::QueryRecorder.new { subject } - expected_queries = Gitlab.ee? ? 43 : 40 + expected_queries = Gitlab.ee? ? 46 : 43 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 @@ -176,7 +190,48 @@ 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? ? 46 : 43 + expected_queries = Gitlab.ee? ? 49 : 46 + + 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 + let(:ref) { 'feature' } + + before do + pipeline_1 = create(:ci_pipeline) + build_1 = create(:ci_build, pipeline: pipeline_1) + create(:ci_sources_pipeline, source_job: build_1) + + pipeline_2 = create(:ci_pipeline) + build_2 = create(:ci_build, pipeline: pipeline_2) + create(:ci_sources_pipeline, source_job: build_2) + end + + it 'verifies number of queries', :request_store do + recorded = ActiveRecord::QueryRecorder.new { subject } + + # 99 queries by default + 2 related to preloading + # :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 expect(recorded.count).to be_within(2).of(expected_queries) expect(recorded.cached_count).to eq(0) diff --git a/spec/serializers/project_import_entity_spec.rb b/spec/serializers/project_import_entity_spec.rb index 9ccae798091..1481d4122ae 100644 --- a/spec/serializers/project_import_entity_spec.rb +++ b/spec/serializers/project_import_entity_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe ProjectImportEntity do +RSpec.describe ProjectImportEntity do include ImportHelper let_it_be(:project) { create(:project, import_status: :started, import_source: 'namespace/project') } diff --git a/spec/serializers/project_mirror_entity_spec.rb b/spec/serializers/project_mirror_entity_spec.rb index 0d64199ecf6..7ed530ed9e8 100644 --- a/spec/serializers/project_mirror_entity_spec.rb +++ b/spec/serializers/project_mirror_entity_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe ProjectMirrorEntity do +RSpec.describe ProjectMirrorEntity do let(:project) { create(:project, :repository, :remote_mirror) } let(:entity) { described_class.new(project) } diff --git a/spec/serializers/project_mirror_serializer_spec.rb b/spec/serializers/project_mirror_serializer_spec.rb index b50c2267ced..0d83e25e27b 100644 --- a/spec/serializers/project_mirror_serializer_spec.rb +++ b/spec/serializers/project_mirror_serializer_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe ProjectMirrorSerializer do +RSpec.describe ProjectMirrorSerializer do it 'represents ProjectMirror entities' do expect(described_class.entity_class).to eq(ProjectMirrorEntity) end diff --git a/spec/serializers/project_note_entity_spec.rb b/spec/serializers/project_note_entity_spec.rb index 469bf2b86de..aaf7764a123 100644 --- a/spec/serializers/project_note_entity_spec.rb +++ b/spec/serializers/project_note_entity_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe ProjectNoteEntity do +RSpec.describe ProjectNoteEntity do include Gitlab::Routing let(:request) { double('request', current_user: user, noteable: note.noteable) } diff --git a/spec/serializers/project_serializer_spec.rb b/spec/serializers/project_serializer_spec.rb index ef3dd1dc15e..4bf0657129f 100644 --- a/spec/serializers/project_serializer_spec.rb +++ b/spec/serializers/project_serializer_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe ProjectSerializer do +RSpec.describe ProjectSerializer do let_it_be(:project) { create(:project) } let(:provider_url) { 'http://provider.com' } diff --git a/spec/serializers/prometheus_alert_entity_spec.rb b/spec/serializers/prometheus_alert_entity_spec.rb index 2b6d8b62c4d..aeee8de2a5b 100644 --- a/spec/serializers/prometheus_alert_entity_spec.rb +++ b/spec/serializers/prometheus_alert_entity_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe PrometheusAlertEntity do +RSpec.describe PrometheusAlertEntity do let(:user) { create(:user) } let(:prometheus_alert) { create(:prometheus_alert) } let(:request) { double('prometheus_alert', current_user: user) } diff --git a/spec/serializers/remote_mirror_entity_spec.rb b/spec/serializers/remote_mirror_entity_spec.rb index 27472c46436..4cbf87e4d67 100644 --- a/spec/serializers/remote_mirror_entity_spec.rb +++ b/spec/serializers/remote_mirror_entity_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe RemoteMirrorEntity do +RSpec.describe RemoteMirrorEntity do let(:project) { create(:project, :repository, :remote_mirror, url: "https://test:password@gitlab.com") } let(:remote_mirror) { project.remote_mirrors.first } let(:entity) { described_class.new(remote_mirror) } diff --git a/spec/serializers/request_aware_entity_spec.rb b/spec/serializers/request_aware_entity_spec.rb index 8ddb35f5f61..d5e87f0a618 100644 --- a/spec/serializers/request_aware_entity_spec.rb +++ b/spec/serializers/request_aware_entity_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe RequestAwareEntity do +RSpec.describe RequestAwareEntity do subject do Class.new.include(described_class).new end diff --git a/spec/serializers/review_app_setup_entity_spec.rb b/spec/serializers/review_app_setup_entity_spec.rb index 19949fa9282..0893d7ee47f 100644 --- a/spec/serializers/review_app_setup_entity_spec.rb +++ b/spec/serializers/review_app_setup_entity_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe ReviewAppSetupEntity do +RSpec.describe ReviewAppSetupEntity do let_it_be(:user) { create(:admin) } let(:project) { create(:project) } let(:presenter) { ProjectPresenter.new(project, current_user: user) } diff --git a/spec/serializers/runner_entity_spec.rb b/spec/serializers/runner_entity_spec.rb index 11a6aba431b..84c7d1720e2 100644 --- a/spec/serializers/runner_entity_spec.rb +++ b/spec/serializers/runner_entity_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe RunnerEntity do +RSpec.describe RunnerEntity do let(:project) { create(:project) } let(:runner) { create(:ci_runner, :project, projects: [project]) } let(:entity) { described_class.new(runner, request: request, current_user: user) } diff --git a/spec/serializers/serverless/domain_entity_spec.rb b/spec/serializers/serverless/domain_entity_spec.rb index bdf0ccb176c..4d73a0f651a 100644 --- a/spec/serializers/serverless/domain_entity_spec.rb +++ b/spec/serializers/serverless/domain_entity_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Serverless::DomainEntity do +RSpec.describe Serverless::DomainEntity do describe '#as_json' do let(:domain) { create(:pages_domain, :instance_serverless) } diff --git a/spec/serializers/service_event_entity_spec.rb b/spec/serializers/service_event_entity_spec.rb index fc11263807b..09bb8bca43b 100644 --- a/spec/serializers/service_event_entity_spec.rb +++ b/spec/serializers/service_event_entity_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe ServiceEventEntity do +RSpec.describe ServiceEventEntity do let(:request) { double('request') } subject { described_class.new(event, request: request, service: service).as_json } diff --git a/spec/serializers/service_field_entity_spec.rb b/spec/serializers/service_field_entity_spec.rb index 277890d143a..f10639dfa1b 100644 --- a/spec/serializers/service_field_entity_spec.rb +++ b/spec/serializers/service_field_entity_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe ServiceFieldEntity do +RSpec.describe ServiceFieldEntity do let(:request) { double('request') } subject { described_class.new(field, request: request, service: service).as_json } @@ -55,12 +55,12 @@ describe ServiceFieldEntity do end context 'EmailsOnPush Service' do - let(:service) { create(:emails_on_push_service) } + let(:service) { create(:emails_on_push_service, send_from_committer_email: '1') } context 'field with type checkbox' do let(:field) { service.global_fields.find { |field| field[:name] == 'send_from_committer_email' } } - it 'exposes correct attributes' do + it 'exposes correct attributes and casts value to Boolean' do expected_hash = { type: 'checkbox', name: 'send_from_committer_email', @@ -68,7 +68,7 @@ describe ServiceFieldEntity do placeholder: nil, required: nil, choices: nil, - value: true + value: 'true' } is_expected.to include(expected_hash) diff --git a/spec/serializers/stage_entity_spec.rb b/spec/serializers/stage_entity_spec.rb index fb08d6994ae..b977d5d33aa 100644 --- a/spec/serializers/stage_entity_spec.rb +++ b/spec/serializers/stage_entity_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe StageEntity do +RSpec.describe StageEntity do let(:pipeline) { create(:ci_pipeline) } let(:request) { double('request') } let(:user) { create(:user) } diff --git a/spec/serializers/stage_serializer_spec.rb b/spec/serializers/stage_serializer_spec.rb index aae17cfbcb9..0b5e87dc95b 100644 --- a/spec/serializers/stage_serializer_spec.rb +++ b/spec/serializers/stage_serializer_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe StageSerializer do +RSpec.describe StageSerializer do let(:project) { create(:project, :repository) } let(:user) { create(:user) } let(:resource) { create(:ci_stage_entity) } diff --git a/spec/serializers/suggestion_entity_spec.rb b/spec/serializers/suggestion_entity_spec.rb index d282a7f9c7a..b133c3fb82e 100644 --- a/spec/serializers/suggestion_entity_spec.rb +++ b/spec/serializers/suggestion_entity_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe SuggestionEntity do +RSpec.describe SuggestionEntity do include RepoHelpers let(:user) { create(:user) } @@ -13,10 +13,119 @@ describe SuggestionEntity do subject { entity.as_json } it 'exposes correct attributes' do - expect(subject.keys).to match_array([:id, :appliable, :applied, :diff_lines, :current_user]) + expect(subject.keys).to match_array([:id, :appliable, :applied, :diff_lines, :current_user, :inapplicable_reason]) end it 'exposes current user abilities' do expect(subject[:current_user]).to include(:can_apply) end + + describe 'inapplicable_reason' do + let(:inapplicable_reason) { subject[:inapplicable_reason] } + + before do + allow(Ability).to receive(:allowed?).and_call_original + + allow(Ability) + .to receive(:allowed?) + .with(user, :apply_suggestion, suggestion) + .and_return(can_apply_suggestion) + end + + context 'when user can apply suggestion' do + let(:can_apply_suggestion) { true } + + before do + allow(suggestion).to receive(:appliable?).and_return(appliable) + 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 + end + end + + context 'when user cannot apply suggestion' do + let(:can_apply_suggestion) { false } + + it 'returns appropriate message' do + expect(inapplicable_reason).to eq("You don't have write access to the source branch.") + end + end + end end diff --git a/spec/serializers/test_case_entity_spec.rb b/spec/serializers/test_case_entity_spec.rb index 9f1822ff581..bd2a1b0fb98 100644 --- a/spec/serializers/test_case_entity_spec.rb +++ b/spec/serializers/test_case_entity_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe TestCaseEntity do +RSpec.describe TestCaseEntity do include TestReportsHelper let(:entity) { described_class.new(test_case) } diff --git a/spec/serializers/test_report_entity_spec.rb b/spec/serializers/test_report_entity_spec.rb index 5913d1c0208..549b14c04dc 100644 --- a/spec/serializers/test_report_entity_spec.rb +++ b/spec/serializers/test_report_entity_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe TestReportEntity do +RSpec.describe TestReportEntity do let(:pipeline) { create(:ci_pipeline, :with_test_reports) } let(:entity) { described_class.new(pipeline.test_reports) } diff --git a/spec/serializers/test_report_summary_entity_spec.rb b/spec/serializers/test_report_summary_entity_spec.rb new file mode 100644 index 00000000000..fcac9af5c23 --- /dev/null +++ b/spec/serializers/test_report_summary_entity_spec.rb @@ -0,0 +1,31 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe TestReportSummaryEntity do + let(:pipeline) { create(:ci_pipeline, :with_report_results) } + let(:entity) { described_class.new(pipeline.test_report_summary) } + + 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) + end + + context 'when summary has test suites' do + it 'contains the test suites' do + expect(as_json).to include(:test_suites) + expect(as_json[:test_suites].count).to eq(1) + end + + it 'contains build_ids' do + expect(as_json[:test_suites].first).to include(:build_ids) + end + end + end +end diff --git a/spec/serializers/test_reports_comparer_entity_spec.rb b/spec/serializers/test_reports_comparer_entity_spec.rb index e7dabc67325..3f88438ccde 100644 --- a/spec/serializers/test_reports_comparer_entity_spec.rb +++ b/spec/serializers/test_reports_comparer_entity_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe TestReportsComparerEntity do +RSpec.describe TestReportsComparerEntity do include TestReportsHelper let(:entity) { described_class.new(comparer) } diff --git a/spec/serializers/test_reports_comparer_serializer_spec.rb b/spec/serializers/test_reports_comparer_serializer_spec.rb index 0d833afe9e4..f9c37f49039 100644 --- a/spec/serializers/test_reports_comparer_serializer_spec.rb +++ b/spec/serializers/test_reports_comparer_serializer_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe TestReportsComparerSerializer do +RSpec.describe TestReportsComparerSerializer do include TestReportsHelper let(:project) { double(:project) } diff --git a/spec/serializers/test_suite_comparer_entity_spec.rb b/spec/serializers/test_suite_comparer_entity_spec.rb index 9790777a570..882991a6208 100644 --- a/spec/serializers/test_suite_comparer_entity_spec.rb +++ b/spec/serializers/test_suite_comparer_entity_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe TestSuiteComparerEntity do +RSpec.describe TestSuiteComparerEntity do include TestReportsHelper let(:entity) { described_class.new(comparer) } diff --git a/spec/serializers/test_suite_entity_spec.rb b/spec/serializers/test_suite_entity_spec.rb index bd88d235013..83d3086ea6b 100644 --- a/spec/serializers/test_suite_entity_spec.rb +++ b/spec/serializers/test_suite_entity_spec.rb @@ -2,36 +2,46 @@ require 'spec_helper' -describe TestSuiteEntity do - let(:pipeline) { create(:ci_pipeline, :with_test_reports) } +RSpec.describe TestSuiteEntity do + let(:pipeline) { create(:ci_pipeline, :with_test_reports) } let(:test_suite) { pipeline.test_reports.test_suites.each_value.first } - let(:entity) { described_class.new(test_suite) } + let(:user) { create(:user) } + let(:request) { double('request', current_user: user) } - describe '#as_json' do - subject(:as_json) { entity.as_json } + subject { described_class.new(test_suite, request: request).as_json } + + context 'when details option is not present' do + it 'does not expose suite error and test cases', :aggregate_failures do + expect(subject).not_to include(:test_cases) + expect(subject).not_to include(:suite_error) + end + end + + context 'when details option is present' do + subject { described_class.new(test_suite, request: request, details: true).as_json } it 'contains the suite name' do - expect(as_json[:name]).to be_present + expect(subject[:name]).to be_present end it 'contains the total time' do - expect(as_json[:total_time]).to be_present + expect(subject[:total_time]).to be_present end it 'contains the counts' do - expect(as_json[:total_count]).to eq(4) - expect(as_json[:success_count]).to eq(2) - expect(as_json[:failed_count]).to eq(2) - expect(as_json[:skipped_count]).to eq(0) - expect(as_json[:error_count]).to eq(0) + expect(subject[:total_count]).to eq(4) + expect(subject[:success_count]).to eq(2) + expect(subject[:failed_count]).to eq(2) + expect(subject[:skipped_count]).to eq(0) + expect(subject[:error_count]).to eq(0) end it 'contains the test cases' do - expect(as_json[:test_cases].count).to eq(4) + expect(subject[:test_cases].count).to eq(4) end it 'contains an empty error message' do - expect(as_json[:suite_error]).to be_nil + expect(subject[:suite_error]).to be_nil end context 'with a suite error' do @@ -40,27 +50,27 @@ describe TestSuiteEntity do end it 'contains the suite name' do - expect(as_json[:name]).to be_present + expect(subject[:name]).to be_present end it 'contains the total time' do - expect(as_json[:total_time]).to be_present + expect(subject[:total_time]).to be_present end it 'returns all the counts as 0' do - expect(as_json[:total_count]).to eq(0) - expect(as_json[:success_count]).to eq(0) - expect(as_json[:failed_count]).to eq(0) - expect(as_json[:skipped_count]).to eq(0) - expect(as_json[:error_count]).to eq(0) + expect(subject[:total_count]).to eq(0) + expect(subject[:success_count]).to eq(0) + expect(subject[:failed_count]).to eq(0) + expect(subject[:skipped_count]).to eq(0) + expect(subject[:error_count]).to eq(0) end it 'returns no test cases' do - expect(as_json[:test_cases]).to be_empty + expect(subject[:test_cases]).to be_empty end it 'returns a suite error' do - expect(as_json[:suite_error]).to eq('a really bad error') + expect(subject[:suite_error]).to eq('a really bad error') end end end diff --git a/spec/serializers/test_suite_summary_entity_spec.rb b/spec/serializers/test_suite_summary_entity_spec.rb new file mode 100644 index 00000000000..d26592bc60e --- /dev/null +++ b/spec/serializers/test_suite_summary_entity_spec.rb @@ -0,0 +1,24 @@ +# frozen_string_literal: true + +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) } + + 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) + end + + it 'contains the build_ids' do + expect(as_json).to include(:build_ids) + end + end +end diff --git a/spec/serializers/trigger_variable_entity_spec.rb b/spec/serializers/trigger_variable_entity_spec.rb index f5a21f943d8..e90bfc24f9f 100644 --- a/spec/serializers/trigger_variable_entity_spec.rb +++ b/spec/serializers/trigger_variable_entity_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe TriggerVariableEntity do +RSpec.describe TriggerVariableEntity do let(:project) { create(:project) } let(:request) { double('request') } let(:user) { create(:user) } diff --git a/spec/serializers/user_entity_spec.rb b/spec/serializers/user_entity_spec.rb index 71107daf6ac..e9d86fe7282 100644 --- a/spec/serializers/user_entity_spec.rb +++ b/spec/serializers/user_entity_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe UserEntity do +RSpec.describe UserEntity do include Gitlab::Routing let(:entity) { described_class.new(user) } diff --git a/spec/serializers/user_serializer_spec.rb b/spec/serializers/user_serializer_spec.rb index 2e4a8c644fe..d54f33b6a23 100644 --- a/spec/serializers/user_serializer_spec.rb +++ b/spec/serializers/user_serializer_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe UserSerializer do +RSpec.describe UserSerializer do let(:user1) { create(:user) } let(:user2) { create(:user) } diff --git a/spec/serializers/web_ide_terminal_entity_spec.rb b/spec/serializers/web_ide_terminal_entity_spec.rb index e163afa14ed..a6f108bf25e 100644 --- a/spec/serializers/web_ide_terminal_entity_spec.rb +++ b/spec/serializers/web_ide_terminal_entity_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe WebIdeTerminalEntity do +RSpec.describe WebIdeTerminalEntity do let(:build) { create(:ci_build) } let(:entity) { described_class.new(WebIdeTerminal.new(build)) } diff --git a/spec/serializers/web_ide_terminal_serializer_spec.rb b/spec/serializers/web_ide_terminal_serializer_spec.rb index 01133deaf84..7ddc4bfedc8 100644 --- a/spec/serializers/web_ide_terminal_serializer_spec.rb +++ b/spec/serializers/web_ide_terminal_serializer_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe WebIdeTerminalSerializer do +RSpec.describe WebIdeTerminalSerializer do let(:build) { create(:ci_build) } subject { described_class.new.represent(WebIdeTerminal.new(build)) } |