Commit 46484525 authored by Dylan Griffith's avatar Dylan Griffith

Merge branch 'disable_joins_ci_runner_groups' into 'master'

Disable_joins for Ci::Runner groups

See merge request gitlab-org/gitlab!70677
parents 652e2b92 8a6d62b6
......@@ -51,7 +51,7 @@ module Ci
has_many :runner_projects, inverse_of: :runner, autosave: true, dependent: :destroy # rubocop:disable Cop/ActiveRecordDependent
has_many :projects, through: :runner_projects
has_many :runner_namespaces, inverse_of: :runner, autosave: true
has_many :groups, through: :runner_namespaces
has_many :groups, through: :runner_namespaces, disable_joins: true
has_one :last_build, -> { order('id DESC') }, class_name: 'Ci::Build'
......
......@@ -5,6 +5,20 @@ require 'spec_helper'
RSpec.describe Ci::Runner do
it_behaves_like 'having unique enum values'
describe 'groups association' do
# Due to other assoctions such as projects this whole spec is allowed to
# generate cross-database queries. So we have this temporary spec to
# validate that at least groups association does not generate cross-DB
# queries.
it 'does not create a cross-database query' do
runner = create(:ci_runner, :group)
with_cross_joins_prevented do
expect(runner.groups.count).to eq(1)
end
end
end
describe 'validation' do
it { is_expected.to validate_presence_of(:access_level) }
it { is_expected.to validate_presence_of(:runner_type) }
......
......@@ -291,6 +291,16 @@ RSpec.describe API::Ci::Runners do
end
end
context 'when the runner is a group runner' do
it "returns the runner's details" do
get api("/runners/#{group_runner_a.id}", admin)
expect(response).to have_gitlab_http_status(:ok)
expect(json_response['description']).to eq(group_runner_a.description)
expect(json_response['groups'].first['id']).to eq(group.id)
end
end
context "runner project's administrative user" do
context 'when runner is not shared' do
it "returns runner's details" 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