This commit is contained in:
Shinya Maeda 2017-09-02 16:31:14 +09:00
parent eab938d505
commit 1b481342a0
8 changed files with 67 additions and 30 deletions

View file

@ -231,9 +231,5 @@ FactoryGirl.define do
trait :protected do
protected true
end
trait :unprotected do
protected false
end
end
end

View file

@ -64,10 +64,6 @@ FactoryGirl.define do
trait :protected do
protected true
end
trait :unprotected do
protected false
end
end
end
end

View file

@ -5,6 +5,7 @@ FactoryGirl.define do
platform "darwin"
is_shared false
active true
access_level :not_protected
trait :online do
contacted_at Time.now
@ -25,9 +26,5 @@ FactoryGirl.define do
trait :ref_protected do
access_level :ref_protected
end
trait :not_protected do
access_level :not_protected
end
end
end

View file

@ -53,7 +53,7 @@ describe Ci::Build do
end
context 'when protected is false' do
let!(:job) { create(:ci_build, :unprotected) }
let!(:job) { create(:ci_build) }
it { is_expected.not_to include(job) }
end

View file

@ -255,7 +255,29 @@ describe Ci::Runner do
end
end
context 'when runner is protected' do
context 'when access_level of runner is not_protected' do
before do
runner.not_protected!
end
context 'when build is protected' do
before do
build.protected = true
end
it { is_expected.to be_truthy }
end
context 'when build is unprotected' do
before do
build.protected = false
end
it { is_expected.to be_truthy }
end
end
context 'when access_level of runner is ref_protected' do
before do
runner.ref_protected!
end

View file

@ -391,14 +391,16 @@ describe Ci::CreatePipelineService do
end
context 'when user is master' do
let(:pipeline) { execute_service }
before do
project.add_master(user)
end
it 'creates a pipeline' do
expect(execute_service).to be_persisted
it 'creates a protected pipeline' do
expect(pipeline).to be_persisted
expect(pipeline).to be_protected
expect(Ci::Pipeline.count).to eq(1)
expect(Ci::Pipeline.last).to be_protected
end
end
@ -469,12 +471,12 @@ describe Ci::CreatePipelineService do
let(:user) {}
let(:trigger) { create(:ci_trigger, owner: nil) }
let(:trigger_request) { create(:ci_trigger_request, trigger: trigger) }
let(:pipeline) { execute_service(trigger_request: trigger_request) }
it 'creates a pipeline' do
expect(execute_service(trigger_request: trigger_request))
.to be_persisted
it 'creates an unprotected pipeline' do
expect(pipeline).to be_persisted
expect(pipeline).not_to be_protected
expect(Ci::Pipeline.count).to eq(1)
expect(Ci::Pipeline.last).not_to be_protected
end
end
end

View file

@ -219,18 +219,30 @@ module Ci
let!(:specific_runner) { create(:ci_runner, :not_protected, :specific) }
context 'when a job is protected' do
let!(:pending_build) { create(:ci_build, :protected, pipeline: pipeline) }
let!(:protected_job) { create(:ci_build, :protected, pipeline: pipeline) }
it 'picks the protected job' do
expect(execute(specific_runner)).to eq(pending_build)
expect(execute(specific_runner)).to eq(protected_job)
end
end
context 'when a job is unprotected' do
let!(:pending_build) { create(:ci_build, :unprotected, pipeline: pipeline) }
let!(:unprotected_job) { create(:ci_build, pipeline: pipeline) }
it 'picks the unprotected job' do
expect(execute(specific_runner)).to eq(pending_build)
expect(execute(specific_runner)).to eq(unprotected_job)
end
end
context 'when protected attribute of a job is nil' do
let!(:legacy_job) { create(:ci_build, pipeline: pipeline) }
before do
legacy_job.update_attribute(:protected, nil)
end
it 'picks the legacy job' do
expect(execute(specific_runner)).to eq(legacy_job)
end
end
end
@ -239,20 +251,32 @@ module Ci
let!(:specific_runner) { create(:ci_runner, :ref_protected, :specific) }
context 'when a job is protected' do
let!(:pending_build) { create(:ci_build, :protected, pipeline: pipeline) }
let!(:protected_job) { create(:ci_build, :protected, pipeline: pipeline) }
it 'picks the protected job' do
expect(execute(specific_runner)).to eq(pending_build)
expect(execute(specific_runner)).to eq(protected_job)
end
end
context 'when a job is unprotected' do
let!(:unprotected_job) { create(:ci_build, :unprotected, pipeline: pipeline) }
let!(:unprotected_job) { create(:ci_build, pipeline: pipeline) }
it 'does not pick the unprotected job' do
expect(execute(specific_runner)).to be_nil
end
end
context 'when protected attribute of a job is nil' do
let!(:legacy_job) { create(:ci_build, pipeline: pipeline) }
before do
legacy_job.update_attribute(:protected, nil)
end
it 'does not pick the legacy job' do
expect(execute(specific_runner)).to be_nil
end
end
end
def execute(runner)

View file

@ -81,7 +81,7 @@ module CycleAnalyticsHelpers
ref: 'master',
source: :push,
project: project,
protected: true)
protected: false)
end
def new_dummy_job(environment)
@ -95,7 +95,7 @@ module CycleAnalyticsHelpers
tag: false,
name: 'dummy',
pipeline: dummy_pipeline,
protected: true)
protected: false)
end
end