BigW Consortium Gitlab

Commit 07f7a01b by Shinya Maeda

Improve spec. Add validation for accel_level on runner.

parent d3bf0160
......@@ -35,6 +35,7 @@ module Ci
end
validate :tag_constraints
validates :access_level, presence: true
acts_as_taggable
......
......@@ -23,11 +23,11 @@ FactoryGirl.define do
end
trait :ref_protected do
access_level 'ref_protected'
access_level :ref_protected
end
trait :not_protected do
access_level 'not_protected'
access_level :not_protected
end
end
end
......@@ -44,13 +44,25 @@ describe Ci::Build do
end
describe '.ref_protected' do
let!(:protected_job) { create(:ci_build, :protected) }
let!(:unprotected_job) { create(:ci_build, :unprotected) }
subject { described_class.ref_protected }
it { is_expected.to include(protected_job) }
it { is_expected.not_to include(unprotected_job) }
context 'when protected is true' do
let!(:job) { create(:ci_build, :protected) }
it { is_expected.to include(job) }
end
context 'when protected is false' do
let!(:job) { create(:ci_build, :unprotected) }
it { is_expected.not_to include(job) }
end
context 'when protected is false' do
let!(:job) { create(:ci_build, protected: nil) }
it { is_expected.not_to include(job) }
end
end
describe '#actionize' do
......
......@@ -2,6 +2,8 @@ require 'spec_helper'
describe Ci::Runner do
describe 'validation' do
it { is_expected.to validate_presence_of(:access_level) }
context 'when runner is not allowed to pick untagged jobs' do
context 'when runner does not have tags' do
it 'is not valid' do
......@@ -19,6 +21,34 @@ describe Ci::Runner do
end
end
describe '#access_level' do
context 'when creating new runner and access_level is nil' do
let(:runner) do
build(:ci_runner, access_level: nil)
end
it "object is invalid" do
expect(runner).not_to be_valid
end
end
context 'when creating new runner and access_level is defined in enum' do
let(:runner) do
build(:ci_runner, access_level: :not_protected)
end
it "object is valid" do
expect(runner).to be_valid
end
end
context 'when creating new runner and access_level is not defined in enum' do
it "raises an error" do
expect { build(:ci_runner, access_level: :this_is_not_defined) }.to raise_error(ArgumentError)
end
end
end
describe '#display_name' do
it 'returns the description if it has a value' do
runner = FactoryGirl.build(:ci_runner, description: 'Linux/Ruby-1.9.3-p448')
......@@ -480,28 +510,4 @@ describe Ci::Runner do
expect(described_class.search(runner.description.upcase)).to eq([runner])
end
end
describe '.access_level' do
context 'when access_level of a runner is ref_protected' do
before do
create(:ci_runner, :ref_protected)
end
it 'a protected runner exists' do
expect(described_class.count).to eq(1)
expect(described_class.last.ref_protected?).to eq(true)
end
end
context 'when access_level of a runner is not_protected' do
before do
create(:ci_runner, :not_protected)
end
it 'an not_protected runner exists' do
expect(described_class.count).to eq(1)
expect(described_class.last.not_protected?).to eq(true)
end
end
end
end
......@@ -215,7 +215,9 @@ module Ci
end
end
context 'when a runner is not_protected' do
context 'when access_level of runner is not_protected' do
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) }
......@@ -233,7 +235,7 @@ module Ci
end
end
context 'when a runner is ref_protected' do
context 'when access_level of runner is ref_protected' do
let!(:specific_runner) { create(:ci_runner, :ref_protected, :specific) }
context 'when a job is protected' do
......
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