From c86fa0e45e4a053090b5c17b9678120e39f696a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matija=20=C4=8Cupi=C4=87?= Date: Tue, 21 May 2019 00:56:19 +0200 Subject: Rename with_all_reports to with_reports --- app/models/ci/job_artifact.rb | 13 +++++++++---- app/serializers/build_details_entity.rb | 2 +- app/serializers/job_artifact_report_entity.rb | 4 +--- spec/models/ci/job_artifact_spec.rb | 4 ++-- 4 files changed, 13 insertions(+), 10 deletions(-) diff --git a/app/models/ci/job_artifact.rb b/app/models/ci/job_artifact.rb index 16fa77e0048..0dbeab30498 100644 --- a/app/models/ci/job_artifact.rb +++ b/app/models/ci/job_artifact.rb @@ -26,10 +26,13 @@ module Ci metrics: 'metrics.txt' }.freeze - TYPE_AND_FORMAT_PAIRS = { + INTERNAL_TYPES = { archive: :zip, metadata: :gzip, - trace: :raw, + trace: :raw + }.freeze + + REPORT_TYPES = { junit: :gzip, metrics: :gzip, @@ -45,6 +48,8 @@ module Ci performance: :raw }.freeze + TYPE_AND_FORMAT_PAIRS = INTERNAL_TYPES.merge(REPORT_TYPES).freeze + belongs_to :project belongs_to :job, class_name: "Ci::Build", foreign_key: :job_id @@ -66,8 +71,8 @@ module Ci where(file_type: types) end - scope :with_all_reports, -> do - where(file_type: self.file_types.values.drop(3)) + scope :with_reports, -> do + with_file_types(REPORT_TYPES.keys.map(&:to_s)) end scope :test_reports, -> do diff --git a/app/serializers/build_details_entity.rb b/app/serializers/build_details_entity.rb index 601b2c47678..6be0a8d1499 100644 --- a/app/serializers/build_details_entity.rb +++ b/app/serializers/build_details_entity.rb @@ -43,7 +43,7 @@ class BuildDetailsEntity < JobEntity end expose :reports, if: -> (*) { can?(current_user, :read_build, build) }, using: JobArtifactReportEntity do |build| - build.job_artifacts.merge(Ci::JobArtifact.with_all_reports) + build.job_artifacts.with_reports end expose :erased_by, if: -> (*) { build.erased? }, using: UserEntity diff --git a/app/serializers/job_artifact_report_entity.rb b/app/serializers/job_artifact_report_entity.rb index 857cbfe8ee8..4280351a6b0 100644 --- a/app/serializers/job_artifact_report_entity.rb +++ b/app/serializers/job_artifact_report_entity.rb @@ -8,8 +8,6 @@ class JobArtifactReportEntity < Grape::Entity expose :size expose :download_path do |artifact| - download_project_job_artifacts_path(job.project, job, file_type: artifact.file_format) + download_project_job_artifacts_path(artifact.job.project, artifact.job, file_type: artifact.file_format) end - - alias_method :job, :object end diff --git a/spec/models/ci/job_artifact_spec.rb b/spec/models/ci/job_artifact_spec.rb index d3809f0a460..e6d682c24d9 100644 --- a/spec/models/ci/job_artifact_spec.rb +++ b/spec/models/ci/job_artifact_spec.rb @@ -23,10 +23,10 @@ describe Ci::JobArtifact do it_behaves_like 'having unique enum values' - describe '.with_all_reports' do + describe '.with_reports' do let!(:artifact) { create(:ci_job_artifact, :archive) } - subject { described_class.with_all_reports } + subject { described_class.with_reports } it { is_expected.to be_empty } -- cgit v1.2.1