Commit 9144dbc3 authored by Dylan Griffith's avatar Dylan Griffith

Merge branch 'refactor-ci-processable-validation-specs' into 'master'

Refactor Ci::Processable validation specs

See merge request gitlab-org/gitlab!29626
parents ba453d1c 9684084f
...@@ -52,69 +52,34 @@ describe Ci::Processable do ...@@ -52,69 +52,34 @@ describe Ci::Processable do
end end
describe 'validate presence of scheduling_type' do describe 'validate presence of scheduling_type' do
context 'on create' do using RSpec::Parameterized::TableSyntax
let(:processable) do
build(
:ci_build, :created, project: project, pipeline: pipeline,
importing: importing, scheduling_type: nil
)
end
context 'when importing' do subject { build(:ci_build, project: project, pipeline: pipeline, importing: importing) }
let(:importing) { true }
context 'when validate_scheduling_type_of_processables is true' do
before do
stub_feature_flags(validate_scheduling_type_of_processables: true)
end
it 'does not validate' do
expect(processable).to be_valid
end
end
context 'when validate_scheduling_type_of_processables is false' do where(:importing, :validate_scheduling_type_flag, :should_validate) do
before do false | true | true
stub_feature_flags(validate_scheduling_type_of_processables: false) false | false | false
end true | true | false
true | false | false
end
it 'does not validate' do with_them do
expect(processable).to be_valid before do
end stub_feature_flags(validate_scheduling_type_of_processables: validate_scheduling_type_flag)
end
end end
context 'when not importing' do context 'on create' do
let(:importing) { false } it 'validates presence' do
if should_validate
context 'when validate_scheduling_type_of_processables is true' do is_expected.to validate_presence_of(:scheduling_type).on(:create)
before do else
stub_feature_flags(validate_scheduling_type_of_processables: true) is_expected.not_to validate_presence_of(:scheduling_type).on(:create)
end
it 'validates' do
expect(processable).not_to be_valid
end
end
context 'when validate_scheduling_type_of_processables is false' do
before do
stub_feature_flags(validate_scheduling_type_of_processables: false)
end
it 'does not validate' do
expect(processable).to be_valid
end end
end end
end end
end
context 'on update' do
let(:processable) { create(:ci_build, :created, project: project, pipeline: pipeline) }
it 'does not validate' do context 'on update' do
processable.scheduling_type = nil it { is_expected.not_to validate_presence_of(:scheduling_type).on(:update) }
expect(processable).to be_valid
end end
end end
end end
...@@ -147,6 +112,8 @@ describe Ci::Processable do ...@@ -147,6 +112,8 @@ describe Ci::Processable do
describe '#needs_attributes' do describe '#needs_attributes' do
let(:build) { create(:ci_build, :created, project: project, pipeline: pipeline) } let(:build) { create(:ci_build, :created, project: project, pipeline: pipeline) }
subject { build.needs_attributes }
context 'with needs' do context 'with needs' do
before do before do
create(:ci_build_need, build: build, name: 'test1') create(:ci_build_need, build: build, name: 'test1')
...@@ -154,7 +121,7 @@ describe Ci::Processable do ...@@ -154,7 +121,7 @@ describe Ci::Processable do
end end
it 'returns all needs attributes' do it 'returns all needs attributes' do
expect(build.needs_attributes).to contain_exactly( is_expected.to contain_exactly(
{ 'artifacts' => true, 'name' => 'test1' }, { 'artifacts' => true, 'name' => 'test1' },
{ 'artifacts' => true, 'name' => 'test2' } { 'artifacts' => true, 'name' => 'test2' }
) )
...@@ -162,9 +129,7 @@ describe Ci::Processable do ...@@ -162,9 +129,7 @@ describe Ci::Processable do
end end
context 'without needs' do context 'without needs' do
it 'returns all needs attributes' do it { is_expected.to be_empty }
expect(build.needs_attributes).to be_empty
end
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