diff options
author | Dylan Griffith <dyl.griffith@gmail.com> | 2018-05-10 12:40:30 +0200 |
---|---|---|
committer | Dylan Griffith <dyl.griffith@gmail.com> | 2018-05-10 12:40:30 +0200 |
commit | cd834b46a8b84eaf14891854925502800acff475 (patch) | |
tree | 8f6cc1350cc33568b1ba7640cf3cafad11797355 | |
parent | 84fa061086250b9f59eb51eb8728702dfedb7546 (diff) | |
download | gitlab-ce-correct-runner-type-when-assigning-shared-to-project.tar.gz |
Ensure Ci::Runner#assign_to errors for group runnerscorrect-runner-type-when-assigning-shared-to-project
-rw-r--r-- | app/models/ci/runner.rb | 2 | ||||
-rw-r--r-- | spec/models/ci/runner_spec.rb | 27 |
2 files changed, 22 insertions, 7 deletions
diff --git a/app/models/ci/runner.rb b/app/models/ci/runner.rb index 359a87a3f77..bda69f85a78 100644 --- a/app/models/ci/runner.rb +++ b/app/models/ci/runner.rb @@ -111,6 +111,8 @@ module Ci 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 diff --git a/spec/models/ci/runner_spec.rb b/spec/models/ci/runner_spec.rb index 49d096ebb39..e2b212f4f4c 100644 --- a/spec/models/ci/runner_spec.rb +++ b/spec/models/ci/runner_spec.rb @@ -200,16 +200,29 @@ describe Ci::Runner do describe '#assign_to' do let!(:project) { FactoryBot.create(:project) } - let!(:shared_runner) { FactoryBot.create(:ci_runner, :shared) } - 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).to be_project_type } - 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 |