Ensure we validate Runner#runner_type when persisting RunnerNamespace

This commit is contained in:
Dylan Griffith 2018-05-14 15:54:47 +02:00
parent ab489d293d
commit 0a2f5065f2
2 changed files with 8 additions and 1 deletions

View File

@ -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

View File

@ -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