2020-01-17 15:08:37 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-24 18:09:03 +00:00
|
|
|
RSpec.describe Ci::Processable do
|
2020-02-12 15:09:37 +00:00
|
|
|
let_it_be(:project) { create(:project) }
|
|
|
|
let_it_be(:pipeline) { create(:ci_pipeline, project: project) }
|
2020-01-17 15:08:37 +00:00
|
|
|
|
2020-04-21 15:21:10 +00:00
|
|
|
describe 'delegations' do
|
|
|
|
subject { Ci::Processable.new }
|
2020-04-16 06:09:39 +00:00
|
|
|
|
2020-04-21 15:21:10 +00:00
|
|
|
it { is_expected.to delegate_method(:merge_request?).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) }
|
2020-04-16 06:09:39 +00:00
|
|
|
end
|
|
|
|
|
2020-01-17 15:08:37 +00:00
|
|
|
describe '#aggregated_needs_names' do
|
|
|
|
let(:with_aggregated_needs) { pipeline.processables.select_with_aggregated_needs(project) }
|
|
|
|
|
|
|
|
context 'with created status' do
|
|
|
|
let!(:processable) { create(:ci_build, :created, project: project, pipeline: pipeline) }
|
|
|
|
|
|
|
|
context 'with needs' do
|
|
|
|
before do
|
|
|
|
create(:ci_build_need, build: processable, name: 'test1')
|
|
|
|
create(:ci_build_need, build: processable, name: 'test2')
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns all processables' do
|
|
|
|
expect(with_aggregated_needs).to contain_exactly(processable)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns all needs' do
|
|
|
|
expect(with_aggregated_needs.first.aggregated_needs_names).to contain_exactly('test1', 'test2')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'without needs' do
|
|
|
|
it 'returns all processables' do
|
|
|
|
expect(with_aggregated_needs).to contain_exactly(processable)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns empty needs' do
|
|
|
|
expect(with_aggregated_needs.first.aggregated_needs_names).to be_nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2020-02-12 06:09:05 +00:00
|
|
|
|
|
|
|
describe 'validate presence of scheduling_type' do
|
2020-04-21 15:21:10 +00:00
|
|
|
using RSpec::Parameterized::TableSyntax
|
2020-02-12 06:09:05 +00:00
|
|
|
|
2020-04-21 15:21:10 +00:00
|
|
|
subject { build(:ci_build, project: project, pipeline: pipeline, importing: importing) }
|
2020-02-12 06:09:05 +00:00
|
|
|
|
2020-05-14 12:08:21 +00:00
|
|
|
where(:importing, :should_validate) do
|
|
|
|
false | true
|
|
|
|
true | false
|
2020-04-21 15:21:10 +00:00
|
|
|
end
|
2020-02-12 06:09:05 +00:00
|
|
|
|
2020-04-21 15:21:10 +00:00
|
|
|
with_them do
|
|
|
|
context 'on create' do
|
|
|
|
it 'validates presence' do
|
|
|
|
if should_validate
|
|
|
|
is_expected.to validate_presence_of(:scheduling_type).on(:create)
|
|
|
|
else
|
|
|
|
is_expected.not_to validate_presence_of(:scheduling_type).on(:create)
|
2020-02-12 06:09:05 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-04-21 15:21:10 +00:00
|
|
|
context 'on update' do
|
|
|
|
it { is_expected.not_to validate_presence_of(:scheduling_type).on(:update) }
|
2020-02-12 06:09:05 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2020-02-14 12:09:03 +00:00
|
|
|
|
|
|
|
describe '.populate_scheduling_type!' do
|
|
|
|
let!(:build_without_needs) { create(:ci_build, project: project, pipeline: pipeline) }
|
|
|
|
let!(:build_with_needs) { create(:ci_build, project: project, pipeline: pipeline) }
|
|
|
|
let!(:needs_relation) { create(:ci_build_need, build: build_with_needs) }
|
|
|
|
let!(:another_build) { create(:ci_build, project: project) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
Ci::Processable.update_all(scheduling_type: nil)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'populates scheduling_type of processables' do
|
|
|
|
expect do
|
|
|
|
pipeline.processables.populate_scheduling_type!
|
|
|
|
end.to change(pipeline.processables.where(scheduling_type: nil), :count).from(2).to(0)
|
|
|
|
|
|
|
|
expect(build_without_needs.reload.scheduling_type).to eq('stage')
|
|
|
|
expect(build_with_needs.reload.scheduling_type).to eq('dag')
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not affect processables from other pipelines' do
|
|
|
|
pipeline.processables.populate_scheduling_type!
|
|
|
|
expect(another_build.reload.scheduling_type).to be_nil
|
|
|
|
end
|
|
|
|
end
|
2020-02-26 15:08:56 +00:00
|
|
|
|
|
|
|
describe '#needs_attributes' do
|
|
|
|
let(:build) { create(:ci_build, :created, project: project, pipeline: pipeline) }
|
|
|
|
|
2020-04-21 15:21:10 +00:00
|
|
|
subject { build.needs_attributes }
|
|
|
|
|
2020-02-26 15:08:56 +00:00
|
|
|
context 'with needs' do
|
|
|
|
before do
|
|
|
|
create(:ci_build_need, build: build, name: 'test1')
|
|
|
|
create(:ci_build_need, build: build, name: 'test2')
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns all needs attributes' do
|
2020-04-21 15:21:10 +00:00
|
|
|
is_expected.to contain_exactly(
|
2020-02-26 15:08:56 +00:00
|
|
|
{ 'artifacts' => true, 'name' => 'test1' },
|
|
|
|
{ 'artifacts' => true, 'name' => 'test2' }
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'without needs' do
|
2020-04-21 15:21:10 +00:00
|
|
|
it { is_expected.to be_empty }
|
2020-04-16 06:09:39 +00:00
|
|
|
end
|
|
|
|
end
|
2020-01-17 15:08:37 +00:00
|
|
|
end
|