Commit 0884cb30 authored by Matija Čupić's avatar Matija Čupić

Move needs to Ci::Processable

parent e36c7247
...@@ -42,7 +42,6 @@ module Ci ...@@ -42,7 +42,6 @@ module Ci
has_one :deployment, as: :deployable, class_name: 'Deployment' has_one :deployment, as: :deployable, class_name: 'Deployment'
has_many :trace_sections, class_name: 'Ci::BuildTraceSection' has_many :trace_sections, class_name: 'Ci::BuildTraceSection'
has_many :trace_chunks, class_name: 'Ci::BuildTraceChunk', foreign_key: :build_id has_many :trace_chunks, class_name: 'Ci::BuildTraceChunk', foreign_key: :build_id
has_many :needs, class_name: 'Ci::BuildNeed', foreign_key: :build_id, inverse_of: :build
has_many :job_artifacts, class_name: 'Ci::JobArtifact', foreign_key: :job_id, dependent: :destroy, inverse_of: :job # rubocop:disable Cop/ActiveRecordDependent has_many :job_artifacts, class_name: 'Ci::JobArtifact', foreign_key: :job_id, dependent: :destroy, inverse_of: :job # rubocop:disable Cop/ActiveRecordDependent
has_many :job_variables, class_name: 'Ci::JobVariable', foreign_key: :job_id has_many :job_variables, class_name: 'Ci::JobVariable', foreign_key: :job_id
...@@ -56,7 +55,6 @@ module Ci ...@@ -56,7 +55,6 @@ module Ci
accepts_nested_attributes_for :runner_session accepts_nested_attributes_for :runner_session
accepts_nested_attributes_for :job_variables accepts_nested_attributes_for :job_variables
accepts_nested_attributes_for :needs
delegate :url, to: :runner_session, prefix: true, allow_nil: true delegate :url, to: :runner_session, prefix: true, allow_nil: true
delegate :terminal_specification, to: :runner_session, allow_nil: true delegate :terminal_specification, to: :runner_session, allow_nil: true
......
...@@ -8,6 +8,14 @@ module Ci ...@@ -8,6 +8,14 @@ module Ci
# #
# #
module Processable module Processable
extend ActiveSupport::Concern
included do
has_many :needs, class_name: 'Ci::BuildNeed', foreign_key: :build_id, inverse_of: :build
accepts_nested_attributes_for :needs
end
def schedulable? def schedulable?
raise NotImplementedError raise NotImplementedError
end end
......
# frozen_string_literal: true
require 'spec_helper'
describe Ci::CreatePipelineService do
subject(:execute) { service.execute(:push) }
let(:project) { create(:project, :repository) }
let(:user) { create(:admin) }
let(:service) { described_class.new(project, user, { ref: 'refs/heads/master' }) }
let(:config) do
<<~EOY
regular_job:
stage: build
script:
- echo 'hello'
bridge_dag_job:
stage: test
needs:
- regular_job
trigger: 'some/project'
EOY
end
before do
stub_ci_pipeline_yaml_file(config)
end
it 'persists pipeline' do
expect(execute).to be_persisted
end
it 'persists both jobs' do
expect { execute }.to change(Ci::Build, :count).from(0).to(1)
.and change(Ci::Bridge, :count).from(0).to(1)
end
it 'persists bridge needs' do
job = execute.builds.first
bridge = execute.stages.last.bridges.first
expect(bridge.needs.first.name).to eq(job.name)
end
it 'persists bridge target project' do
bridge = execute.stages.last.bridges.first
expect(bridge.downstream_project).to eq('some/project')
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