diff options
author | Shinya Maeda <shinya@gitlab.com> | 2017-08-22 17:01:11 +0900 |
---|---|---|
committer | Shinya Maeda <shinya@gitlab.com> | 2017-09-03 23:49:10 +0900 |
commit | bbe967abeba7be1db79e34439e74cd113c240b52 (patch) | |
tree | b498f626149dc0e8ed541352fa9080e10a99fb34 /spec | |
parent | eda34b1a1846a5d5b55cc127a32b0c7628580f25 (diff) | |
download | gitlab-ce-bbe967abeba7be1db79e34439e74cd113c240b52.tar.gz |
Add the rest of specs
Diffstat (limited to 'spec')
-rw-r--r-- | spec/factories/ci/builds.rb | 8 | ||||
-rw-r--r-- | spec/lib/gitlab/ci/stage/seed_spec.rb | 11 | ||||
-rw-r--r-- | spec/models/ci/build_spec.rb | 10 | ||||
-rw-r--r-- | spec/services/ci/register_job_service_spec.rb | 38 |
4 files changed, 67 insertions, 0 deletions
diff --git a/spec/factories/ci/builds.rb b/spec/factories/ci/builds.rb index 5bba1dec7db..f8922275860 100644 --- a/spec/factories/ci/builds.rb +++ b/spec/factories/ci/builds.rb @@ -226,5 +226,13 @@ FactoryGirl.define do status 'created' self.when 'manual' end + + trait(:protected) do + protected true + end + + trait(:unprotected) do + protected false + end end end diff --git a/spec/lib/gitlab/ci/stage/seed_spec.rb b/spec/lib/gitlab/ci/stage/seed_spec.rb index d7e91a5a62c..1e9cbbdfb77 100644 --- a/spec/lib/gitlab/ci/stage/seed_spec.rb +++ b/spec/lib/gitlab/ci/stage/seed_spec.rb @@ -26,6 +26,17 @@ describe Gitlab::Ci::Stage::Seed do expect(subject.builds).to all(include(project: pipeline.project)) expect(subject.builds) .to all(include(trigger_request: pipeline.trigger_requests.first)) + expect(subject.builds).to all(include(protected: true)) + end + + context 'when a ref is unprotected' do + before do + allow_any_instance_of(Project).to receive(:protected_for?).and_return(false) + end + + it 'returns unprotected builds' do + expect(subject.builds).to all(include(protected: false)) + end end end diff --git a/spec/models/ci/build_spec.rb b/spec/models/ci/build_spec.rb index 0c35ad3c9d8..1673d873b57 100644 --- a/spec/models/ci/build_spec.rb +++ b/spec/models/ci/build_spec.rb @@ -43,6 +43,16 @@ describe Ci::Build do it { is_expected.not_to include(manual_but_created) } end + describe '.protected_' do + let!(:protected_job) { create(:ci_build, :protected) } + let!(:unprotected_job) { create(:ci_build, :unprotected) } + + subject { described_class.protected_ } + + it { is_expected.to include(protected_job) } + it { is_expected.not_to include(unprotected_job) } + end + describe '#actionize' do context 'when build is a created' do before do diff --git a/spec/services/ci/register_job_service_spec.rb b/spec/services/ci/register_job_service_spec.rb index 8eb0d2d10a4..99f2507e59c 100644 --- a/spec/services/ci/register_job_service_spec.rb +++ b/spec/services/ci/register_job_service_spec.rb @@ -215,6 +215,44 @@ module Ci end end + context 'when a runner is unprotected' do + context 'when a job is protected' do + let!(:pending_build) { create(:ci_build, :protected, pipeline: pipeline) } + + it 'picks the protected job' do + expect(execute(specific_runner)).to eq(pending_build) + end + end + + context 'when a job is unprotected' do + let!(:pending_build) { create(:ci_build, :unprotected, pipeline: pipeline) } + + it 'picks the unprotected job' do + expect(execute(specific_runner)).to eq(pending_build) + end + end + end + + context 'when a runner is protected' do + let!(:specific_runner) { create(:ci_runner, :protected, :specific) } + + context 'when a job is protected' do + let!(:pending_build) { create(:ci_build, :protected, pipeline: pipeline) } + + it 'picks the protected job' do + expect(execute(specific_runner)).to eq(pending_build) + end + end + + context 'when a job is unprotected' do + let!(:unprotected_job) { create(:ci_build, :unprotected, pipeline: pipeline) } + + it 'does not pick the unprotected job' do + expect(execute(specific_runner)).to be_nil + end + end + end + def execute(runner) described_class.new(runner).execute.build end |