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 ...@@ -4,9 +4,7 @@ class Admin::RunnerProjectsController < Admin::ApplicationController
def create def create
@runner = Ci::Runner.find(params[:runner_project][:runner_id]) @runner = Ci::Runner.find(params[:runner_project][:runner_id])
runner_project = @runner.assign_to(@project, current_user) if @runner.assign_to(@project, current_user)
if runner_project.persisted?
redirect_to admin_runner_path(@runner) redirect_to admin_runner_path(@runner)
else else
redirect_to admin_runner_path(@runner), alert: 'Failed adding runner to project' redirect_to admin_runner_path(@runner), alert: 'Failed adding runner to project'
......
...@@ -9,9 +9,8 @@ class Projects::RunnerProjectsController < Projects::ApplicationController ...@@ -9,9 +9,8 @@ class Projects::RunnerProjectsController < Projects::ApplicationController
return head(403) unless can?(current_user, :assign_runner, @runner) return head(403) unless can?(current_user, :assign_runner, @runner)
path = project_runners_path(project) 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 redirect_to path
else else
redirect_to path, alert: 'Failed adding runner to project' redirect_to path, alert: 'Failed adding runner to project'
......
...@@ -120,9 +120,8 @@ module Ci ...@@ -120,9 +120,8 @@ module Ci
raise ArgumentError, 'Transitioning a group runner to a project runner is not supported' raise ArgumentError, 'Transitioning a group runner to a project runner is not supported'
end end
runner_project = project.runner_projects.create(runner_id: self.id) self.projects << project
self.save! self.save
runner_project
end end
def display_name def display_name
......
...@@ -133,9 +133,7 @@ module API ...@@ -133,9 +133,7 @@ module API
runner = get_runner(params[:runner_id]) runner = get_runner(params[:runner_id])
authenticate_enable_runner!(runner) authenticate_enable_runner!(runner)
runner_project = runner.assign_to(user_project) if runner.assign_to(user_project)
if runner_project.persisted?
present runner, with: Entities::Runner present runner, with: Entities::Runner
else else
conflict!("Runner was already enabled for this project") conflict!("Runner was already enabled for this project")
......
...@@ -200,7 +200,7 @@ describe Ci::Runner do ...@@ -200,7 +200,7 @@ describe Ci::Runner do
let(:runner) { create(:ci_runner, :instance) } let(:runner) { create(:ci_runner, :instance) }
it 'transitions shared runner to project runner and assigns project' do 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_specific
expect(runner).to be_project_type 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