debian-mirror-gitlab/spec/models/ci/build_need_spec.rb

97 lines
3.1 KiB
Ruby
Raw Normal View History

2019-10-12 21:52:04 +05:30
# frozen_string_literal: true
require 'spec_helper'
2023-03-04 22:38:38 +05:30
RSpec.describe Ci::BuildNeed, model: true, feature_category: :continuous_integration do
2019-10-12 21:52:04 +05:30
let(:build_need) { build(:ci_build_need) }
2021-03-08 18:12:59 +05:30
it { is_expected.to belong_to(:build).class_name('Ci::Processable') }
2019-10-12 21:52:04 +05:30
it { is_expected.to validate_presence_of(:build) }
it { is_expected.to validate_presence_of(:name) }
it { is_expected.to validate_length_of(:name).is_at_most(128) }
2020-01-01 13:55:28 +05:30
describe '.artifacts' do
let_it_be(:with_artifacts) { create(:ci_build_need, artifacts: true) }
let_it_be(:without_artifacts) { create(:ci_build_need, artifacts: false) }
it { expect(described_class.artifacts).to contain_exactly(with_artifacts) }
end
2020-07-28 23:09:34 +05:30
describe 'BulkInsertSafe' do
let(:ci_build) { build(:ci_build) }
it "bulk inserts from Ci::Build model" do
ci_build.needs_attributes = [
{ name: "build", artifacts: true },
{ name: "build2", artifacts: true },
{ name: "build3", artifacts: true }
]
expect(described_class).to receive(:bulk_insert!).and_call_original
BulkInsertableAssociations.with_bulk_insert do
ci_build.save!
end
end
end
2023-03-04 22:38:38 +05:30
describe 'partitioning' do
context 'with build' do
let(:build) { FactoryBot.build(:ci_build, partition_id: ci_testing_partition_id) }
let(:build_need) { FactoryBot.build(:ci_build_need, build: build) }
it 'sets partition_id to the current partition value' do
expect { build_need.valid? }.to change { build_need.partition_id }.to(ci_testing_partition_id)
end
context 'when it is already set' do
let(:build_need) { FactoryBot.build(:ci_build_need, partition_id: 125) }
it 'does not change the partition_id value' do
expect { build_need.valid? }.not_to change { build_need.partition_id }
end
end
end
context 'without build' do
let(:build_need) { FactoryBot.build(:ci_build_need, build: nil) }
it { is_expected.to validate_presence_of(:partition_id) }
it 'does not change the partition_id value' do
expect { build_need.valid? }.not_to change { build_need.partition_id }
end
end
context 'when using bulk_insert' do
include Ci::PartitioningHelpers
let(:new_pipeline) { create(:ci_pipeline) }
let(:ci_build) { build(:ci_build, pipeline: new_pipeline) }
before do
stub_current_partition_id
end
2023-06-20 00:43:36 +05:30
it 'creates build needs successfully', :aggregate_failures, :ci_partitionable do
2023-03-04 22:38:38 +05:30
ci_build.needs_attributes = [
{ name: "build", artifacts: true },
{ name: "build2", artifacts: true },
{ name: "build3", artifacts: true }
]
expect(described_class).to receive(:bulk_insert!).and_call_original
BulkInsertableAssociations.with_bulk_insert do
ci_build.save!
end
expect(described_class.count).to eq(3)
expect(described_class.first.partition_id).to eq(ci_testing_partition_id)
expect(described_class.second.partition_id).to eq(ci_testing_partition_id)
end
end
end
2019-10-12 21:52:04 +05:30
end