From 0a2f5065f26f259ed66359f3754ecc21505fea0d Mon Sep 17 00:00:00 2001 From: Dylan Griffith Date: Mon, 14 May 2018 15:54:47 +0200 Subject: [PATCH] Ensure we validate Runner#runner_type when persisting RunnerNamespace --- app/models/ci/runner_namespace.rb | 2 +- spec/models/ci/runner_spec.rb | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) 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