Commit b8cf2a34 authored by Grzegorz Bizon's avatar Grzegorz Bizon

Set run untagged option when registering a runner

parent 9ba72378
......@@ -28,20 +28,17 @@ module Ci
post "register" do
required_attributes! [:token]
attributes = { description: params[:description],
tag_list: params[:tag_list],
run_untagged: params[:run_untagged] || true }
runner =
if runner_registration_token_valid?
# Create shared runner. Requires admin access
Ci::Runner.create(
description: params[:description],
tag_list: params[:tag_list],
is_shared: true
)
Ci::Runner.create(attributes.merge(is_shared: true))
elsif project = Project.find_by(runners_token: params[:token])
# Create a specific runner for project.
project.runners.create(
description: params[:description],
tag_list: params[:tag_list]
)
project.runners.create(attributes)
end
return forbidden! unless runner
......
......@@ -15,13 +15,17 @@ describe Ci::API::API do
context 'when runner token is provided' do
before { post ci_api("/runners/register"), token: registration_token }
it 'creates runner' do
it 'creates runner with default values' do
expect(response.status).to eq(201)
expect(Ci::Runner.first.run_untagged).to be true
end
end
context 'when runner description is provided' do
before { post ci_api("/runners/register"), token: registration_token, description: "server.hostname" }
before do
post ci_api("/runners/register"), token: registration_token,
description: "server.hostname"
end
it 'creates runner' do
expect(response.status).to eq(201)
......@@ -30,7 +34,10 @@ describe Ci::API::API do
end
context 'when runner tags are provided' do
before { post ci_api("/runners/register"), token: registration_token, tag_list: "tag1, tag2" }
before do
post ci_api("/runners/register"), token: registration_token,
tag_list: "tag1, tag2"
end
it 'creates runner' do
expect(response.status).to eq(201)
......@@ -38,6 +45,28 @@ describe Ci::API::API do
end
end
context 'when option for running untagged jobs is provided' do
context 'when tags are provided' do
it 'creates runner' do
post ci_api("/runners/register"), token: registration_token,
run_untagged: false,
tag_list: ['tag']
expect(response.status).to eq(201)
expect(Ci::Runner.first.run_untagged).to be false
end
end
context 'when tags are not provided' do
it 'does not create runner' do
post ci_api("/runners/register"), token: registration_token,
run_untagged: false
expect(response.status).to eq(404)
end
end
end
context 'when project token is provided' do
let(:project) { FactoryGirl.create(:empty_project) }
before { post ci_api("/runners/register"), token: project.runners_token }
......
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