Commit eda34b1a authored by Shinya Maeda's avatar Shinya Maeda

Add spec. Fix runner setting page. It worked.

parent e1ef436d
......@@ -59,6 +59,8 @@ class Projects::RunnersController < Projects::ApplicationController
end
def runner_params
params.require(:runner).permit(Ci::Runner::FORM_EDITABLE)
params.require(:runner).permit(Ci::Runner::FORM_EDITABLE).tap do |params|
params['access_level'] = params['access_level']&.to_i
end
end
end
......@@ -10,7 +10,7 @@
= label :protected, "Protected", class: 'control-label'
.col-sm-10
.checkbox
= f.check_box :access_level, 1, 0
= f.check_box :access_level, {}, Ci::Runner.access_levels['protected_'], Ci::Runner.access_levels['unprotected']
%span.light This runner will only run on pipelines trigged on protected branches
.form-group
= label :run_untagged, 'Run untagged jobs', class: 'control-label'
......
......@@ -6,8 +6,8 @@ class AddAccessLevelToCiRunners < ActiveRecord::Migration
disable_ddl_transaction!
def up
# Ci::Runner.unprotected: 0
add_column_with_default(:ci_runners, :access_level, :integer, default: 0)
add_column_with_default(:ci_runners, :access_level, :integer,
default: Ci::Runner.access_levels['unprotected'])
end
def down
......
......@@ -28,7 +28,7 @@ module Gitlab
attributes.merge(project: project,
ref: pipeline.ref,
tag: pipeline.tag,
trigger_request: trigger
trigger_request: trigger,
protected: protected?)
end
end
......
......@@ -21,5 +21,13 @@ FactoryGirl.define do
trait :inactive do
active false
end
trait :protected do
access_level Ci::Runner.access_levels['protected_']
end
trait :unprotected do
access_level Ci::Runner.access_levels['unprotected']
end
end
end
......@@ -456,4 +456,28 @@ 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 protected' do
before do
create(:ci_runner, :protected)
end
it 'a protected runner exists' do
expect(Ci::Runner.count).to eq(1)
expect(Ci::Runner.last.protected_?).to eq(true)
end
end
context 'when access_level of a runner is unprotected' do
before do
create(:ci_runner, :unprotected)
end
it 'an unprotected runner exists' do
expect(Ci::Runner.count).to eq(1)
expect(Ci::Runner.last.unprotected?).to eq(true)
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