2019-03-30 07:23:56 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-07-26 09:31:09 +00:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-24 18:09:03 +00:00
|
|
|
RSpec.describe Ci::PipelineVariable do
|
2017-07-26 09:31:09 +00:00
|
|
|
subject { build(:ci_pipeline_variable) }
|
|
|
|
|
2019-05-06 13:11:42 +00:00
|
|
|
it_behaves_like "CI variable"
|
|
|
|
|
2021-09-07 09:11:43 +00:00
|
|
|
it { is_expected.to validate_presence_of(:key) }
|
2018-10-01 17:22:41 +00:00
|
|
|
|
|
|
|
describe '#hook_attrs' do
|
|
|
|
let(:variable) { create(:ci_pipeline_variable, key: 'foo', value: 'bar') }
|
|
|
|
|
|
|
|
subject { variable.hook_attrs }
|
|
|
|
|
|
|
|
it { is_expected.to be_a(Hash) }
|
|
|
|
it { is_expected.to eq({ key: 'foo', value: 'bar' }) }
|
|
|
|
end
|
2022-09-14 12:12:34 +00:00
|
|
|
|
|
|
|
describe 'partitioning' do
|
|
|
|
context 'with pipeline' do
|
|
|
|
let(:pipeline) { build(:ci_pipeline, partition_id: 123) }
|
|
|
|
let(:variable) { build(:ci_pipeline_variable, pipeline: pipeline, partition_id: nil) }
|
|
|
|
|
|
|
|
it 'copies the partition_id from pipeline' do
|
|
|
|
expect { variable.valid? }.to change(variable, :partition_id).from(nil).to(123)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'without pipeline' do
|
|
|
|
subject(:variable) { build(:ci_pipeline_variable, pipeline: nil, partition_id: nil) }
|
|
|
|
|
|
|
|
it { is_expected.to validate_presence_of(:partition_id) }
|
|
|
|
|
|
|
|
it 'does not change the partition_id value' do
|
|
|
|
expect { variable.valid? }.not_to change(variable, :partition_id)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2017-07-26 09:31:09 +00:00
|
|
|
end
|