diff options
-rw-r--r-- | app/models/ci/runner.rb | 8 | ||||
-rw-r--r-- | spec/models/ci/runner_spec.rb | 29 |
2 files changed, 31 insertions, 6 deletions
diff --git a/app/models/ci/runner.rb b/app/models/ci/runner.rb index 23078f1c3ed..9b76817b4c8 100644 --- a/app/models/ci/runner.rb +++ b/app/models/ci/runner.rb @@ -107,7 +107,13 @@ module Ci end 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 project.runner_projects.create(runner_id: self.id) end diff --git a/spec/models/ci/runner_spec.rb b/spec/models/ci/runner_spec.rb index cc4d4e5e4ae..ef769a617ed 100644 --- a/spec/models/ci/runner_spec.rb +++ b/spec/models/ci/runner_spec.rb @@ -198,16 +198,35 @@ describe Ci::Runner do end describe '#assign_to' do +<<<<<<< HEAD let!(:project) { FactoryBot.create :project } let!(:shared_runner) { FactoryBot.create(:ci_runner, :shared) } +======= + let!(:project) { FactoryBot.create(:project) } +>>>>>>> f91aaccf4d0... Merge branch 'correct-runner-type-when-assigning-shared-to-project' into 'master' - before do - shared_runner.assign_to(project) + subject { 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 - it { expect(shared_runner).to be_specific } - it { expect(shared_runner.projects).to eq([project]) } - it { expect(shared_runner.only_for?(project)).to be_truthy } + context 'with group runner' do + let!(:runner) { FactoryBot.create(:ci_runner, runner_type: :group_type) } + + 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 describe '.online' do |