summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDylan Griffith <dyl.griffith@gmail.com>2018-05-14 15:54:47 +0200
committerDylan Griffith <dyl.griffith@gmail.com>2018-05-31 10:46:19 +0200
commit0a2f5065f26f259ed66359f3754ecc21505fea0d (patch)
treefac04c5b46e13121b8b0b95a62791ae1947e93ba
parentab489d293d6ee3e30673817ce4652c7b413988c0 (diff)
downloadgitlab-ce-0a2f5065f26f259ed66359f3754ecc21505fea0d.tar.gz
Ensure we validate Runner#runner_type when persisting RunnerNamespace
-rw-r--r--app/models/ci/runner_namespace.rb2
-rw-r--r--spec/models/ci/runner_spec.rb7
2 files changed, 8 insertions, 1 deletions
diff --git a/app/models/ci/runner_namespace.rb b/app/models/ci/runner_namespace.rb
index 3269f86e8ca..420e34df091 100644
--- a/app/models/ci/runner_namespace.rb
+++ b/app/models/ci/runner_namespace.rb
@@ -2,7 +2,7 @@ module Ci
class RunnerNamespace < ActiveRecord::Base
extend Gitlab::Ci::Model
- belongs_to :runner
+ belongs_to :runner, validate: true
belongs_to :namespace, class_name: '::Namespace'
belongs_to :group, class_name: '::Group', foreign_key: :namespace_id
end
diff --git a/spec/models/ci/runner_spec.rb b/spec/models/ci/runner_spec.rb
index 4dc990350d2..51d5e666cd6 100644
--- a/spec/models/ci/runner_spec.rb
+++ b/spec/models/ci/runner_spec.rb
@@ -66,6 +66,13 @@ describe Ci::Runner do
expect(instance_runner).not_to be_valid
expect(instance_runner.errors.full_messages).to include('Runner cannot assign project to a non-project runner')
end
+
+ it 'should fail to save a group assigned to a project runner even if the runner is already saved' do
+ group_runner
+
+ expect { create(:group, runners: [project_runner]) }
+ .to raise_error(ActiveRecord::RecordInvalid)
+ end
end
end