Commit a5d6a17a authored by Erick Bajao's avatar Erick Bajao

Refactor based on review feedback

Cleaned up the specs and also included head_pipeline prefix to
delegated method.
parent 333b881d
......@@ -295,8 +295,7 @@ class MergeRequest < ApplicationRecord
alias_attribute :auto_merge_enabled, :merge_when_pipeline_succeeds
alias_method :issuing_parent, :target_project
delegate :builds_with_coverage, to: :head_pipeline, allow_nil: true
delegate :active?, to: :head_pipeline, prefix: true, allow_nil: true
delegate :active?, :builds_with_coverage, to: :head_pipeline, prefix: true, allow_nil: true
delegate :success?, :active?, to: :actual_head_pipeline, prefix: true, allow_nil: true
RebaseLockTimeout = Class.new(StandardError)
......
......@@ -73,7 +73,7 @@ class MergeRequestPollWidgetEntity < Grape::Entity
presenter(merge_request).pipeline_coverage_delta
end
expose :builds_with_coverage, using: BuildCoverageEntity
expose :head_pipeline_builds_with_coverage, as: :builds_with_coverage, using: BuildCoverageEntity
expose :cancel_auto_merge_path do |merge_request|
presenter(merge_request).cancel_auto_merge_path
......
......@@ -3440,4 +3440,16 @@ RSpec.describe Ci::Pipeline, :mailer, factory_default: :keep do
it { is_expected.to eq(Gitlab::Git::TAG_REF_PREFIX + pipeline.source_ref.to_s) }
end
end
describe "#builds_with_coverage" do
let!(:rspec) { create(:ci_build, name: 'rspec', coverage: 97.1, pipeline: pipeline) }
let!(:jest) { create(:ci_build, name: 'jest', coverage: 94.1, pipeline: pipeline) }
let!(:karma) { create(:ci_build, name: 'karma', coverage: nil, pipeline: pipeline) }
subject(:builds) { pipeline.builds_with_coverage }
it 'returns builds with coverage only' do
expect(builds).to match_array([rspec, jest])
end
end
end
......@@ -4113,27 +4113,13 @@ RSpec.describe MergeRequest, factory_default: :keep do
end
end
describe '#builds_with_coverage' do
let(:builds) { subject.builds_with_coverage }
let(:head_pipeline) { create(:ci_empty_pipeline) }
let!(:rspec) { create(:ci_build, name: 'rspec', coverage: 97.1, pipeline: head_pipeline) }
let!(:jest) { create(:ci_build, name: 'jest', coverage: 94.1, pipeline: head_pipeline) }
let!(:karma) { create(:ci_build, name: 'karma', coverage: nil, pipeline: head_pipeline) }
context 'when head_pipeline is not present' do
it 'returns nil' do
expect(builds).to be_nil
end
end
context 'when head_pipeline is present' do
before do
subject.update_attribute(:head_pipeline_id, head_pipeline.id)
end
it 'returns the builds with coverage' do
expect(builds).to match_array([rspec, jest])
end
describe '#head_pipeline_builds_with_coverage' do
it do
is_expected
.to delegate_method(:builds_with_coverage)
.to(:head_pipeline)
.with_prefix
.with_arguments(allow_nil: true)
end
end
end
......@@ -296,7 +296,7 @@ RSpec.describe MergeRequestPollWidgetEntity do
end
before do
allow(resource).to receive(:builds_with_coverage).and_return(builds)
allow(resource).to receive(:head_pipeline_builds_with_coverage).and_return(builds)
end
it 'serializes the builds with coverage' do
......
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