Improve `Ci::Runner#assign_to` to return a flag whether it succeeded or not

This commit is contained in:
Kamil Trzciński 2018-05-28 12:49:08 +02:00 committed by Dylan Griffith
parent d9251f2ea0
commit c6e95b0440
5 changed files with 6 additions and 12 deletions

View File

@ -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'

View File

@ -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'

View File

@ -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

View File

@ -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")

View File

@ -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