Commit f91aaccf authored by Kamil Trzciński's avatar Kamil Trzciński

Merge branch 'correct-runner-type-when-assigning-shared-to-project' into 'master'

Ensure runner_type is updated correctly when assigning shared runner to project

See merge request gitlab-org/gitlab-ce!18874
parents e6b8f89d cd834b46
...@@ -108,7 +108,13 @@ module Ci ...@@ -108,7 +108,13 @@ module Ci
end end
def assign_to(project, current_user = nil) def assign_to(project, current_user = nil)
self.is_shared = false if shared? if shared?
self.is_shared = false if shared?
self.runner_type = :project_type
elsif group_type?
raise ArgumentError, 'Transitioning a group runner to a project runner is not supported'
end
self.save self.save
project.runner_projects.create(runner_id: self.id) project.runner_projects.create(runner_id: self.id)
end end
......
...@@ -200,15 +200,29 @@ describe Ci::Runner do ...@@ -200,15 +200,29 @@ describe Ci::Runner do
describe '#assign_to' do describe '#assign_to' do
let!(:project) { FactoryBot.create(:project) } let!(:project) { FactoryBot.create(:project) }
let!(:shared_runner) { FactoryBot.create(:ci_runner, :shared) }
before do subject { runner.assign_to(project) }
shared_runner.assign_to(project)
context 'with shared_runner' do
let!(:runner) { FactoryBot.create(:ci_runner, :shared) }
it 'transitions shared runner to project runner and assigns project' do
subject
expect(runner).to be_specific
expect(runner).to be_project_type
expect(runner.projects).to eq([project])
expect(runner.only_for?(project)).to be_truthy
end
end end
it { expect(shared_runner).to be_specific } context 'with group runner' do
it { expect(shared_runner.projects).to eq([project]) } let!(:runner) { FactoryBot.create(:ci_runner, runner_type: :group_type) }
it { expect(shared_runner.only_for?(project)).to be_truthy }
it 'raises an error' do
expect { subject }
.to raise_error(ArgumentError, 'Transitioning a group runner to a project runner is not supported')
end
end
end end
describe '.online' do describe '.online' do
......
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