From 973e4030b13adbcc4eb7fad347b928a5164a04ff Mon Sep 17 00:00:00 2001 From: Tomasz Maczukin Date: Thu, 22 Mar 2018 17:52:28 +0100 Subject: [PATCH] Refactor build_metadata --- .../jobs/components/sidebar_details_block.vue | 12 +++++++++--- app/models/ci/build.rb | 2 +- app/models/ci/build_metadata.rb | 16 ++++------------ app/serializers/build_details_entity.rb | 4 +--- spec/factories/ci/build_metadata.rb | 9 +++++++++ spec/models/ci/build_metadata_spec.rb | 10 +--------- 6 files changed, 25 insertions(+), 28 deletions(-) create mode 100644 spec/factories/ci/build_metadata.rb diff --git a/app/assets/javascripts/jobs/components/sidebar_details_block.vue b/app/assets/javascripts/jobs/components/sidebar_details_block.vue index 6ff3fa6e099..172de6b3679 100644 --- a/app/assets/javascripts/jobs/components/sidebar_details_block.vue +++ b/app/assets/javascripts/jobs/components/sidebar_details_block.vue @@ -44,10 +44,16 @@ runnerId() { return `#${this.job.runner.id}`; }, + hasTimeout() { + return this.job.metadata != null && this.job.metadata.timeout_human_readable !== ''; + }, timeout() { - let t = `${this.job.metadata.timeout_human_readable}`; + if (this.job.metadata == null) { + return ''; + } - if (this.job.metadata.timeout_source != null) { + let t = this.job.metadata.timeout_human_readable; + if (this.job.metadata.timeout_source !== '') { t += ` (from ${this.job.metadata.timeout_source})`; } @@ -130,7 +136,7 @@ /> (*) { build.erased? }, using: UserEntity expose :erase_path, if: -> (*) { build.erasable? && can?(current_user, :erase_build, build) } do |build| diff --git a/spec/factories/ci/build_metadata.rb b/spec/factories/ci/build_metadata.rb new file mode 100644 index 00000000000..66bbd977b88 --- /dev/null +++ b/spec/factories/ci/build_metadata.rb @@ -0,0 +1,9 @@ +FactoryBot.define do + factory :ci_build_metadata, class: Ci::BuildMetadata do + build factory: :ci_build + + after(:build) do |build_metadata, _| + build_metadata.project ||= build_metadata.build.project + end + end +end diff --git a/spec/models/ci/build_metadata_spec.rb b/spec/models/ci/build_metadata_spec.rb index 4758738cdd0..d21e9600e42 100644 --- a/spec/models/ci/build_metadata_spec.rb +++ b/spec/models/ci/build_metadata_spec.rb @@ -13,15 +13,7 @@ describe Ci::BuildMetadata do end let(:build) { create(:ci_build, pipeline: pipeline) } - let(:build_metadata) { described_class.create(build: build) } - - context 'when creating' do - subject { build_metadata.project_id } - - it 'saves project_id' do - is_expected.to eq(project.id) - end - end + let(:build_metadata) { create(:ci_build_metadata, build: build) } describe '#save_timeout_state!' do subject { build_metadata }