Commit e077af9b authored by drew cimino's avatar drew cimino

Remove Ci::PipelineDelegator in favor of Ci:Processable

- Moved all delegations into Ci::Processable
- Added specs for delegated method into Processable spec
- Created EE Processable spec for merge train related methods
parent bf76a753
...@@ -3,7 +3,6 @@ ...@@ -3,7 +3,6 @@
module Ci module Ci
class Bridge < Ci::Processable class Bridge < Ci::Processable
include Ci::Contextable include Ci::Contextable
include Ci::PipelineDelegator
include Ci::Metadatable include Ci::Metadatable
include Importable include Importable
include AfterCommitQueue include AfterCommitQueue
......
...@@ -4,7 +4,6 @@ module Ci ...@@ -4,7 +4,6 @@ module Ci
class Build < Ci::Processable class Build < Ci::Processable
include Ci::Metadatable include Ci::Metadatable
include Ci::Contextable include Ci::Contextable
include Ci::PipelineDelegator
include TokenAuthenticatable include TokenAuthenticatable
include AfterCommitQueue include AfterCommitQueue
include ObjectStorage::BackgroundMove include ObjectStorage::BackgroundMove
......
...@@ -51,6 +51,12 @@ module Ci ...@@ -51,6 +51,12 @@ module Ci
validates :type, presence: true validates :type, presence: true
validates :scheduling_type, presence: true, on: :create, if: :validate_scheduling_type? validates :scheduling_type, presence: true, on: :create, if: :validate_scheduling_type?
delegate :merge_request?,
:merge_request_ref?,
:legacy_detached_merge_request_pipeline?,
:merge_train_pipeline?,
to: :pipeline
def aggregated_needs_names def aggregated_needs_names
read_attribute(:aggregated_needs_names) read_attribute(:aggregated_needs_names)
end end
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
## ##
# We will disable `ref` and `sha` attributes in `Ci::Build` in the future # We will disable `ref` and `sha` attributes in `Ci::Build` in the future
# and remove this module in favor of Ci::PipelineDelegator. # and remove this module in favor of Ci::Processable.
module Ci module Ci
module HasRef module HasRef
extend ActiveSupport::Concern extend ActiveSupport::Concern
......
# frozen_string_literal: true
##
# This module is mainly used by child associations of `Ci::Pipeline` that needs to look up
# single source of truth. For example, `Ci::Build` has `git_ref` method, which behaves
# slightly different from `Ci::Pipeline`'s `git_ref`. This is very confusing as
# the system could behave differently time to time.
# We should have a single interface in `Ci::Pipeline` and access the method always.
module Ci
module PipelineDelegator
extend ActiveSupport::Concern
included do
delegate :merge_request?,
:merge_request_ref?,
:legacy_detached_merge_request_pipeline?,
:merge_train_pipeline?, to: :pipeline
end
end
end
# frozen_string_literal: true
require 'spec_helper'
describe Ci::Processable do
let_it_be(:project) { create(:project) }
let_it_be(:pipeline) { create(:ci_pipeline, project: project) }
let_it_be(:detached_merge_request_pipeline) do
create(:ci_pipeline, :detached_merge_request_pipeline, :with_job, project: project)
end
let_it_be(:legacy_detached_merge_request_pipeline) do
create(:ci_pipeline, :legacy_detached_merge_request_pipeline, :with_job, project: project)
end
let_it_be(:merged_result_pipeline) do
create(:ci_pipeline, :merged_result_pipeline, :with_job, project: project)
end
describe '#merge_train_pipeline?' do
subject { pipeline.processables.first.merge_train_pipeline? }
context 'in a detached merge request pipeline' do
let(:pipeline) { detached_merge_request_pipeline }
it { is_expected.to eq(pipeline.merge_train_pipeline?) }
end
context 'in a legacy detached merge_request_pipeline' do
let(:pipeline) { legacy_detached_merge_request_pipeline }
it { is_expected.to eq(pipeline.merge_train_pipeline?) }
end
context 'in a pipeline for merged results' do
let(:pipeline) { merged_result_pipeline }
it { is_expected.to eq(pipeline.merge_train_pipeline?) }
end
end
end
...@@ -17,8 +17,6 @@ describe Ci::Bridge do ...@@ -17,8 +17,6 @@ describe Ci::Bridge do
{ trigger: { project: 'my/project', branch: 'master' } } { trigger: { project: 'my/project', branch: 'master' } }
end end
it { is_expected.to include_module(Ci::PipelineDelegator) }
it 'has many sourced pipelines' do it 'has many sourced pipelines' do
expect(bridge).to have_many(:sourced_pipelines) expect(bridge).to have_many(:sourced_pipelines)
end end
......
...@@ -37,8 +37,6 @@ describe Ci::Build do ...@@ -37,8 +37,6 @@ describe Ci::Build do
it { is_expected.to delegate_method(:merge_request_ref?).to(:pipeline) } it { is_expected.to delegate_method(:merge_request_ref?).to(:pipeline) }
it { is_expected.to delegate_method(:legacy_detached_merge_request_pipeline?).to(:pipeline) } it { is_expected.to delegate_method(:legacy_detached_merge_request_pipeline?).to(:pipeline) }
it { is_expected.to include_module(Ci::PipelineDelegator) }
describe 'associations' do describe 'associations' do
it 'has a bidirectional relationship with projects' do it 'has a bidirectional relationship with projects' do
expect(described_class.reflect_on_association(:project).has_inverse?).to eq(:builds) expect(described_class.reflect_on_association(:project).has_inverse?).to eq(:builds)
......
...@@ -6,6 +6,18 @@ describe Ci::Processable do ...@@ -6,6 +6,18 @@ describe Ci::Processable do
let_it_be(:project) { create(:project) } let_it_be(:project) { create(:project) }
let_it_be(:pipeline) { create(:ci_pipeline, project: project) } let_it_be(:pipeline) { create(:ci_pipeline, project: project) }
let_it_be(:detached_merge_request_pipeline) do
create(:ci_pipeline, :detached_merge_request_pipeline, :with_job, project: project)
end
let_it_be(:legacy_detached_merge_request_pipeline) do
create(:ci_pipeline, :legacy_detached_merge_request_pipeline, :with_job, project: project)
end
let_it_be(:merged_result_pipeline) do
create(:ci_pipeline, :merged_result_pipeline, :with_job, project: project)
end
describe '#aggregated_needs_names' do describe '#aggregated_needs_names' do
let(:with_aggregated_needs) { pipeline.processables.select_with_aggregated_needs(project) } let(:with_aggregated_needs) { pipeline.processables.select_with_aggregated_needs(project) }
...@@ -155,4 +167,70 @@ describe Ci::Processable do ...@@ -155,4 +167,70 @@ describe Ci::Processable do
end end
end end
end end
describe '#merge_request?' do
subject { pipeline.processables.first.merge_request? }
context 'in a detached merge request pipeline' do
let(:pipeline) { detached_merge_request_pipeline }
it { is_expected.to eq(pipeline.merge_request?) }
end
context 'in a legacy detached merge_request_pipeline' do
let(:pipeline) { legacy_detached_merge_request_pipeline }
it { is_expected.to eq(pipeline.merge_request?) }
end
context 'in a pipeline for merged results' do
let(:pipeline) { merged_result_pipeline }
it { is_expected.to eq(pipeline.merge_request?) }
end
end
describe '#merge_request_ref?' do
subject { pipeline.processables.first.merge_request_ref? }
context 'in a detached merge request pipeline' do
let(:pipeline) { detached_merge_request_pipeline }
it { is_expected.to eq(pipeline.merge_request_ref?) }
end
context 'in a legacy detached merge_request_pipeline' do
let(:pipeline) { legacy_detached_merge_request_pipeline }
it { is_expected.to eq(pipeline.merge_request_ref?) }
end
context 'in a pipeline for merged results' do
let(:pipeline) { merged_result_pipeline }
it { is_expected.to eq(pipeline.merge_request_ref?) }
end
end
describe '#legacy_detached_merge_request_pipeline?' do
subject { pipeline.processables.first.legacy_detached_merge_request_pipeline? }
context 'in a detached merge request pipeline' do
let(:pipeline) { detached_merge_request_pipeline }
it { is_expected.to eq(pipeline.legacy_detached_merge_request_pipeline?) }
end
context 'in a legacy detached merge_request_pipeline' do
let(:pipeline) { legacy_detached_merge_request_pipeline }
it { is_expected.to eq(pipeline.legacy_detached_merge_request_pipeline?) }
end
context 'in a pipeline for merged results' do
let(:pipeline) { merged_result_pipeline }
it { is_expected.to eq(pipeline.legacy_detached_merge_request_pipeline?) }
end
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