Commit 1b481342 authored by Shinya Maeda's avatar Shinya Maeda

Fix spec

parent eab938d5
...@@ -231,9 +231,5 @@ FactoryGirl.define do ...@@ -231,9 +231,5 @@ FactoryGirl.define do
trait :protected do trait :protected do
protected true protected true
end end
trait :unprotected do
protected false
end
end end
end end
...@@ -64,10 +64,6 @@ FactoryGirl.define do ...@@ -64,10 +64,6 @@ FactoryGirl.define do
trait :protected do trait :protected do
protected true protected true
end end
trait :unprotected do
protected false
end
end end
end end
end end
...@@ -5,6 +5,7 @@ FactoryGirl.define do ...@@ -5,6 +5,7 @@ FactoryGirl.define do
platform "darwin" platform "darwin"
is_shared false is_shared false
active true active true
access_level :not_protected
trait :online do trait :online do
contacted_at Time.now contacted_at Time.now
...@@ -25,9 +26,5 @@ FactoryGirl.define do ...@@ -25,9 +26,5 @@ FactoryGirl.define do
trait :ref_protected do trait :ref_protected do
access_level :ref_protected access_level :ref_protected
end end
trait :not_protected do
access_level :not_protected
end
end end
end end
...@@ -53,7 +53,7 @@ describe Ci::Build do ...@@ -53,7 +53,7 @@ describe Ci::Build do
end end
context 'when protected is false' do context 'when protected is false' do
let!(:job) { create(:ci_build, :unprotected) } let!(:job) { create(:ci_build) }
it { is_expected.not_to include(job) } it { is_expected.not_to include(job) }
end end
......
...@@ -255,7 +255,29 @@ describe Ci::Runner do ...@@ -255,7 +255,29 @@ describe Ci::Runner do
end end
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 before do
runner.ref_protected! runner.ref_protected!
end end
......
...@@ -391,14 +391,16 @@ describe Ci::CreatePipelineService do ...@@ -391,14 +391,16 @@ describe Ci::CreatePipelineService do
end end
context 'when user is master' do context 'when user is master' do
let(:pipeline) { execute_service }
before do before do
project.add_master(user) project.add_master(user)
end end
it 'creates a pipeline' do it 'creates a protected pipeline' do
expect(execute_service).to be_persisted expect(pipeline).to be_persisted
expect(pipeline).to be_protected
expect(Ci::Pipeline.count).to eq(1) expect(Ci::Pipeline.count).to eq(1)
expect(Ci::Pipeline.last).to be_protected
end end
end end
...@@ -469,12 +471,12 @@ describe Ci::CreatePipelineService do ...@@ -469,12 +471,12 @@ describe Ci::CreatePipelineService do
let(:user) {} let(:user) {}
let(:trigger) { create(:ci_trigger, owner: nil) } let(:trigger) { create(:ci_trigger, owner: nil) }
let(:trigger_request) { create(:ci_trigger_request, trigger: trigger) } let(:trigger_request) { create(:ci_trigger_request, trigger: trigger) }
let(:pipeline) { execute_service(trigger_request: trigger_request) }
it 'creates a pipeline' do it 'creates an unprotected pipeline' do
expect(execute_service(trigger_request: trigger_request)) expect(pipeline).to be_persisted
.to be_persisted expect(pipeline).not_to be_protected
expect(Ci::Pipeline.count).to eq(1) expect(Ci::Pipeline.count).to eq(1)
expect(Ci::Pipeline.last).not_to be_protected
end end
end end
end end
......
...@@ -219,18 +219,30 @@ module Ci ...@@ -219,18 +219,30 @@ module Ci
let!(:specific_runner) { create(:ci_runner, :not_protected, :specific) } let!(:specific_runner) { create(:ci_runner, :not_protected, :specific) }
context 'when a job is protected' do 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 it 'picks the protected job' do
expect(execute(specific_runner)).to eq(pending_build) expect(execute(specific_runner)).to eq(protected_job)
end end
end end
context 'when a job is unprotected' do 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 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 end
end end
...@@ -239,20 +251,32 @@ module Ci ...@@ -239,20 +251,32 @@ module Ci
let!(:specific_runner) { create(:ci_runner, :ref_protected, :specific) } let!(:specific_runner) { create(:ci_runner, :ref_protected, :specific) }
context 'when a job is protected' do 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 it 'picks the protected job' do
expect(execute(specific_runner)).to eq(pending_build) expect(execute(specific_runner)).to eq(protected_job)
end end
end end
context 'when a job is unprotected' do 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 it 'does not pick the unprotected job' do
expect(execute(specific_runner)).to be_nil expect(execute(specific_runner)).to be_nil
end end
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 end
def execute(runner) def execute(runner)
......
...@@ -81,7 +81,7 @@ module CycleAnalyticsHelpers ...@@ -81,7 +81,7 @@ module CycleAnalyticsHelpers
ref: 'master', ref: 'master',
source: :push, source: :push,
project: project, project: project,
protected: true) protected: false)
end end
def new_dummy_job(environment) def new_dummy_job(environment)
...@@ -95,7 +95,7 @@ module CycleAnalyticsHelpers ...@@ -95,7 +95,7 @@ module CycleAnalyticsHelpers
tag: false, tag: false,
name: 'dummy', name: 'dummy',
pipeline: dummy_pipeline, pipeline: dummy_pipeline,
protected: true) protected: false)
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