Commit af15b6f0 authored by Dylan Griffith's avatar Dylan Griffith

Fix Project#group_runners_enabled as it was doing nothing

parent bf790c26
...@@ -234,7 +234,7 @@ class Project < ActiveRecord::Base ...@@ -234,7 +234,7 @@ class Project < ActiveRecord::Base
has_many :custom_attributes, class_name: 'ProjectCustomAttribute' has_many :custom_attributes, class_name: 'ProjectCustomAttribute'
has_many :project_badges, class_name: 'ProjectBadge' has_many :project_badges, class_name: 'ProjectBadge'
has_one :ci_cd_settings, class_name: 'ProjectCiCdSetting' has_one :ci_cd_settings, class_name: 'ProjectCiCdSetting', inverse_of: :project, autosave: true
accepts_nested_attributes_for :variables, allow_destroy: true accepts_nested_attributes_for :variables, allow_destroy: true
accepts_nested_attributes_for :project_feature, update_only: true accepts_nested_attributes_for :project_feature, update_only: true
...@@ -331,6 +331,11 @@ class Project < ActiveRecord::Base ...@@ -331,6 +331,11 @@ class Project < ActiveRecord::Base
scope :with_issues_available_for_user, ->(current_user) { with_feature_available_for_user(:issues, current_user) } scope :with_issues_available_for_user, ->(current_user) { with_feature_available_for_user(:issues, current_user) }
scope :with_merge_requests_enabled, -> { with_feature_enabled(:merge_requests) } scope :with_merge_requests_enabled, -> { with_feature_enabled(:merge_requests) }
scope :with_group_runners_enabled, -> do
joins(:ci_cd_settings)
.where(project_ci_cd_settings: { group_runners_enabled: true })
end
enum auto_cancel_pending_pipelines: { disabled: 0, enabled: 1 } enum auto_cancel_pending_pipelines: { disabled: 0, enabled: 1 }
chronic_duration_attr :build_timeout_human_readable, :build_timeout, default: 3600 chronic_duration_attr :build_timeout_human_readable, :build_timeout, default: 3600
......
class ProjectCiCdSetting < ActiveRecord::Base class ProjectCiCdSetting < ActiveRecord::Base
belongs_to :project belongs_to :project, inverse_of: :ci_cd_settings
# The version of the schema that first introduced this model/table. # The version of the schema that first introduced this model/table.
MINIMUM_SCHEMA_VERSION = 20180403035759 MINIMUM_SCHEMA_VERSION = 20180403035759
......
...@@ -91,7 +91,10 @@ module Ci ...@@ -91,7 +91,10 @@ module Ci
def builds_for_group_runner def builds_for_group_runner
hierarchy_groups = Gitlab::GroupHierarchy.new(runner.groups).base_and_descendants hierarchy_groups = Gitlab::GroupHierarchy.new(runner.groups).base_and_descendants
projects = Project.where(namespace_id: hierarchy_groups) projects = Project.where(namespace_id: hierarchy_groups)
new_builds.where(project: projects.without_deleted.with_builds_enabled).order('created_at ASC') .with_group_runners_enabled
.with_builds_enabled
.without_deleted
new_builds.where(project: projects).order('created_at ASC')
end end
def running_builds_for_shared_runners def running_builds_for_shared_runners
......
...@@ -2,13 +2,13 @@ require 'spec_helper' ...@@ -2,13 +2,13 @@ require 'spec_helper'
module Ci module Ci
describe RegisterJobService do describe RegisterJobService do
let!(:project) { create :project, shared_runners_enabled: false } set(:group) { create(:group) }
let!(:group) { create :group } set(:project) { create(:project, group: group, shared_runners_enabled: false, group_runners_enabled: false) }
let!(:pipeline) { create :ci_pipeline, project: project } set(:pipeline) { create(:ci_pipeline, project: project) }
let!(:pending_job) { create :ci_build, pipeline: pipeline } let!(:shared_runner) { create(:ci_runner, is_shared: true) }
let!(:shared_runner) { create :ci_runner, is_shared: true } let!(:specific_runner) { create(:ci_runner, is_shared: false) }
let!(:specific_runner) { create :ci_runner, is_shared: false } let!(:group_runner) { create(:ci_runner, groups: [group], runner_type: :group_type) }
let!(:group_runner) { create :ci_runner, groups: [group], runner_type: :group_type } let!(:pending_job) { create(:ci_build, pipeline: pipeline) }
before do before do
specific_runner.assign_to(project) specific_runner.assign_to(project)
...@@ -152,7 +152,7 @@ module Ci ...@@ -152,7 +152,7 @@ module Ci
context 'disallow when builds are disabled' do context 'disallow when builds are disabled' do
before do before do
project.update(shared_runners_enabled: true) project.update(shared_runners_enabled: true, group_runners_enabled: true)
project.project_feature.update_attribute(:builds_access_level, ProjectFeature::DISABLED) project.project_feature.update_attribute(:builds_access_level, ProjectFeature::DISABLED)
end end
...@@ -162,7 +162,13 @@ module Ci ...@@ -162,7 +162,13 @@ module Ci
it { expect(build).to be_nil } it { expect(build).to be_nil }
end end
context 'and uses specific runner' do context 'and uses group runner' do
let(:build) { execute(group_runner) }
it { expect(build).to be_nil }
end
context 'and uses project runner' do
let(:build) { execute(specific_runner) } let(:build) { execute(specific_runner) }
it { expect(build).to be_nil } it { expect(build).to be_nil }
...@@ -171,7 +177,7 @@ module Ci ...@@ -171,7 +177,7 @@ module Ci
context 'allow group runners' do context 'allow group runners' do
before do before do
project.update!(group_runners_enabled: true, group: group) project.update!(group_runners_enabled: true)
end end
context 'for multiple builds' do context 'for multiple builds' do
...@@ -230,7 +236,7 @@ module Ci ...@@ -230,7 +236,7 @@ module Ci
context 'disallow group runners' do context 'disallow group runners' do
before do before do
project.update(group_runners_enabled: false) project.update!(group_runners_enabled: false)
end end
context 'group runner' do context 'group runner' do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment