Commit bbe967ab authored by Shinya Maeda's avatar Shinya Maeda
Browse files

Add the rest of specs

parent bf3f9d6d22ce
......@@ -29,14 +29,10 @@ def builds
ref: pipeline.ref,
tag: pipeline.tag,
trigger_request: trigger,
protected: protected?)
protected: protected_ref?)
end
end
def protected?
@protected ||= project.protected_for?(pipeline.ref)
end
def create!
pipeline.stages.create!(stage).tap do |stage|
builds_attributes = builds.map do |attributes|
......@@ -48,6 +44,12 @@ def create!
end
end
end
private
def protected_ref?
@protected_ref ||= project.protected_for?(pipeline.ref)
end
end
end
end
......
......@@ -226,5 +226,13 @@
status 'created'
self.when 'manual'
end
trait(:protected) do
protected true
end
trait(:unprotected) do
protected false
end
end
end
......@@ -26,6 +26,17 @@
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
......
......@@ -43,6 +43,16 @@
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
......
......@@ -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
......
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