summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShinya Maeda <shinya@gitlab.com>2017-08-21 17:24:44 +0900
committerShinya Maeda <shinya@gitlab.com>2017-09-03 23:49:10 +0900
commiteda34b1a1846a5d5b55cc127a32b0c7628580f25 (patch)
treef4400330322a6104e5f04356ac04e8eea56559cc
parente1ef436d1fd6419ce8a08c4ac33bf664786c80b0 (diff)
downloadgitlab-ce-eda34b1a1846a5d5b55cc127a32b0c7628580f25.tar.gz
Add spec. Fix runner setting page. It worked.
-rw-r--r--app/controllers/projects/runners_controller.rb4
-rw-r--r--app/views/projects/runners/_form.html.haml2
-rw-r--r--db/migrate/20170816133938_add_access_level_to_ci_runners.rb4
-rw-r--r--lib/gitlab/ci/stage/seed.rb2
-rw-r--r--spec/factories/ci/runners.rb8
-rw-r--r--spec/models/ci/runner_spec.rb24
6 files changed, 39 insertions, 5 deletions
diff --git a/app/controllers/projects/runners_controller.rb b/app/controllers/projects/runners_controller.rb
index 9f9773575a5..bacecff3e7c 100644
--- a/app/controllers/projects/runners_controller.rb
+++ b/app/controllers/projects/runners_controller.rb
@@ -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
diff --git a/app/views/projects/runners/_form.html.haml b/app/views/projects/runners/_form.html.haml
index 2942ce541ed..d66383bd8f1 100644
--- a/app/views/projects/runners/_form.html.haml
+++ b/app/views/projects/runners/_form.html.haml
@@ -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'
diff --git a/db/migrate/20170816133938_add_access_level_to_ci_runners.rb b/db/migrate/20170816133938_add_access_level_to_ci_runners.rb
index 58317d46eac..cb8d023e439 100644
--- a/db/migrate/20170816133938_add_access_level_to_ci_runners.rb
+++ b/db/migrate/20170816133938_add_access_level_to_ci_runners.rb
@@ -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
diff --git a/lib/gitlab/ci/stage/seed.rb b/lib/gitlab/ci/stage/seed.rb
index d9ac46908b0..2bc78b4f004 100644
--- a/lib/gitlab/ci/stage/seed.rb
+++ b/lib/gitlab/ci/stage/seed.rb
@@ -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
diff --git a/spec/factories/ci/runners.rb b/spec/factories/ci/runners.rb
index 05abf60d5ce..3a7da2e47d0 100644
--- a/spec/factories/ci/runners.rb
+++ b/spec/factories/ci/runners.rb
@@ -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
diff --git a/spec/models/ci/runner_spec.rb b/spec/models/ci/runner_spec.rb
index 48f878bbee6..45a64b6f76f 100644
--- a/spec/models/ci/runner_spec.rb
+++ b/spec/models/ci/runner_spec.rb
@@ -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