Commit 5261047c authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Refactor codeclimate related code for build and pipeline

Signed-off-by: default avatarDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
parent 87d1a814
......@@ -441,6 +441,11 @@ module Ci
trace
end
def has_codeclimate_json?
options.dig(:artifacts, :paths) == ['codeclimate.json'] &&
artifacts_metadata?
end
private
def update_artifacts_size
......
......@@ -397,10 +397,7 @@ module Ci
end
def codeclimate_artifact
artifacts.codeclimate.find do |artifact|
artifact.options[:artifacts][:paths] == ['codeclimate.json'] &&
artifact.artifacts_metadata?
end
artifacts.codeclimate.find(&:has_codeclimate_json?)
end
private
......
......@@ -1367,4 +1367,38 @@ describe Ci::Build, :models do
build.enqueue
end
end
describe '#has_codeclimate_json?' do
context 'valid build' do
let!(:build) do
create(
:ci_build,
:artifacts,
name: 'codeclimate',
pipeline: pipeline,
options: {
artifacts: {
paths: ['codeclimate.json']
}
}
)
end
it { expect(build.has_codeclimate_json?).to be_truthy }
end
context 'invalid build' do
let!(:build) do
create(
:ci_build,
:artifacts,
name: 'codeclimate',
pipeline: pipeline,
options: {}
)
end
it { expect(build.has_codeclimate_json?).to be_falsey }
end
end
end
......@@ -1220,22 +1220,28 @@ describe Ci::Pipeline, models: true do
end
describe '#codeclimate_artifact' do
let!(:build) do
create(
:ci_build,
:artifacts,
name: 'codeclimate',
pipeline: pipeline,
options: {
artifacts: {
paths: ['codeclimate.json']
context 'has codeclimate build' do
let!(:build) do
create(
:ci_build,
:artifacts,
name: 'codeclimate',
pipeline: pipeline,
options: {
artifacts: {
paths: ['codeclimate.json']
}
}
}
)
)
end
it { expect(pipeline.codeclimate_artifact).to eq(build) }
end
it do
expect(pipeline.codeclimate_artifact).to eq(build)
context 'no codeclimate build' do
before { create(:ci_build, pipeline: pipeline) }
it { expect(pipeline.codeclimate_artifact).to be_nil }
end
end
end
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