Commit afcc57ab authored by Tomasz Maczukin's avatar Tomasz Maczukin

Rename metadata relation and methods

parent 4c348234
......@@ -24,7 +24,7 @@ module Ci
has_one :job_artifacts_metadata, -> { where(file_type: Ci::JobArtifact.file_types[:metadata]) }, class_name: 'Ci::JobArtifact', inverse_of: :job, foreign_key: :job_id
has_one :job_artifacts_trace, -> { where(file_type: Ci::JobArtifact.file_types[:trace]) }, class_name: 'Ci::JobArtifact', inverse_of: :job, foreign_key: :job_id
has_one :build_metadata, class_name: 'Ci::BuildMetadata'
has_one :metadata, class_name: 'Ci::BuildMetadata'
# The "environment" field for builds is a String, and is the unexpanded name
def persisted_environment
......@@ -157,12 +157,12 @@ module Ci
end
before_transition pending: :running do |build|
build.metadata.save_timeout_state!
build.ensure_metadata.save_timeout_state!
end
end
def metadata
self.build_metadata ||= Ci::BuildMetadata.new
def ensure_metadata
metadata || build_metadata
end
def detailed_status(current_user)
......@@ -242,7 +242,7 @@ module Ci
end
def timeout
metadata.timeout
ensure_metadata.timeout
end
def triggered_by?(current_user)
......
......@@ -5,7 +5,9 @@ class BuildDetailsEntity < JobEntity
expose :runner, using: RunnerEntity
expose :pipeline, using: PipelineEntity
expose :metadata, using: BuildMetadataEntity
expose :metadata, using: BuildMetadataEntity do |build|
build.ensure_metadata
end
expose :erased_by, if: -> (*) { build.erased? }, using: UserEntity
expose :erase_path, if: -> (*) { build.erasable? && can?(current_user, :erase_build, build) } do |build|
......
......@@ -2052,11 +2052,11 @@ describe Ci::Build do
shared_examples 'saves data on transition' do
it 'saves timeout' do
expect { job.run! }.to change { job.reload.metadata.timeout }.from(nil).to(expected_timeout)
expect { job.run! }.to change { job.reload.ensure_metadata.timeout }.from(nil).to(expected_timeout)
end
it 'saves timeout_source' do
expect { job.run! }.to change { job.reload.metadata.timeout_source }.from('unknown_timeout_source').to(expected_timeout_source)
expect { job.run! }.to change { job.reload.ensure_metadata.timeout_source }.from('unknown_timeout_source').to(expected_timeout_source)
end
end
......
......@@ -30,7 +30,7 @@ describe Ci::RetryBuildService do
runner_id tag_taggings taggings tags trigger_request_id
user_id auto_canceled_by_id retried failure_reason
artifacts_file_store artifacts_metadata_store
build_metadata].freeze
metadata].freeze
shared_examples 'build duplication' do
let(:another_pipeline) { create(:ci_empty_pipeline, project: project) }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment