summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKamil TrzciƄski <ayufan@ayufan.eu>2018-05-28 12:49:08 +0200
committerDylan Griffith <dyl.griffith@gmail.com>2018-05-31 10:56:41 +0200
commitc6e95b04405f1e07f76505b03c6c096f4c4d084b (patch)
treec1d36122def40f8b0912b822bfcab764d646f39b
parentd9251f2ea047d359d1d7d4799d1ba84da5896f64 (diff)
downloadgitlab-ce-c6e95b04405f1e07f76505b03c6c096f4c4d084b.tar.gz
Improve `Ci::Runner#assign_to` to return a flag whether it succeeded or not
-rw-r--r--app/controllers/admin/runner_projects_controller.rb4
-rw-r--r--app/controllers/projects/runner_projects_controller.rb3
-rw-r--r--app/models/ci/runner.rb5
-rw-r--r--lib/api/runners.rb4
-rw-r--r--spec/models/ci/runner_spec.rb2
5 files changed, 6 insertions, 12 deletions
diff --git a/app/controllers/admin/runner_projects_controller.rb b/app/controllers/admin/runner_projects_controller.rb
index 7ed2de71028..7aba77d8129 100644
--- a/app/controllers/admin/runner_projects_controller.rb
+++ b/app/controllers/admin/runner_projects_controller.rb
@@ -4,9 +4,7 @@ class Admin::RunnerProjectsController < Admin::ApplicationController
def create
@runner = Ci::Runner.find(params[:runner_project][:runner_id])
- runner_project = @runner.assign_to(@project, current_user)
-
- if runner_project.persisted?
+ if @runner.assign_to(@project, current_user)
redirect_to admin_runner_path(@runner)
else
redirect_to admin_runner_path(@runner), alert: 'Failed adding runner to project'
diff --git a/app/controllers/projects/runner_projects_controller.rb b/app/controllers/projects/runner_projects_controller.rb
index 0ec2490655f..a080724634b 100644
--- a/app/controllers/projects/runner_projects_controller.rb
+++ b/app/controllers/projects/runner_projects_controller.rb
@@ -9,9 +9,8 @@ class Projects::RunnerProjectsController < Projects::ApplicationController
return head(403) unless can?(current_user, :assign_runner, @runner)
path = project_runners_path(project)
- runner_project = @runner.assign_to(project, current_user)
- if runner_project.persisted?
+ if @runner.assign_to(project, current_user)
redirect_to path
else
redirect_to path, alert: 'Failed adding runner to project'
diff --git a/app/models/ci/runner.rb b/app/models/ci/runner.rb
index 5cec88660f8..e2a1c9fb929 100644
--- a/app/models/ci/runner.rb
+++ b/app/models/ci/runner.rb
@@ -120,9 +120,8 @@ module Ci
raise ArgumentError, 'Transitioning a group runner to a project runner is not supported'
end
- runner_project = project.runner_projects.create(runner_id: self.id)
- self.save!
- runner_project
+ self.projects << project
+ self.save
end
def display_name
diff --git a/lib/api/runners.rb b/lib/api/runners.rb
index 5cb96d467c0..d9a42960cb6 100644
--- a/lib/api/runners.rb
+++ b/lib/api/runners.rb
@@ -133,9 +133,7 @@ module API
runner = get_runner(params[:runner_id])
authenticate_enable_runner!(runner)
- runner_project = runner.assign_to(user_project)
-
- if runner_project.persisted?
+ if runner.assign_to(user_project)
present runner, with: Entities::Runner
else
conflict!("Runner was already enabled for this project")
diff --git a/spec/models/ci/runner_spec.rb b/spec/models/ci/runner_spec.rb
index 08578c27e37..2f254956f92 100644
--- a/spec/models/ci/runner_spec.rb
+++ b/spec/models/ci/runner_spec.rb
@@ -200,7 +200,7 @@ describe Ci::Runner do
let(:runner) { create(:ci_runner, :instance) }
it 'transitions shared runner to project runner and assigns project' do
- subject
+ expect(subject).to be_truthy
expect(runner).to be_specific
expect(runner).to be_project_type