Commit c6e95b04 authored by Kamil Trzciński's avatar Kamil Trzciński Committed by Dylan Griffith

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

parent d9251f2e
......@@ -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'
......
......@@ -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'
......
......@@ -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
......
......@@ -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")
......
......@@ -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
......
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