From d3bcb06dc6365129b62dadf49efc58daecd39a83 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kamil=20Trzci=C5=84ski?= Date: Wed, 4 Jul 2018 11:02:45 +0200 Subject: [PATCH] Make deprecated scopes of Runner explicit --- app/models/ci/runner.rb | 4 ++-- lib/api/runners.rb | 5 +++++ spec/requests/api/runners_spec.rb | 13 ++++++++++++- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/app/models/ci/runner.rb b/app/models/ci/runner.rb index 89e69c60c4f..bcd0c206bca 100644 --- a/app/models/ci/runner.rb +++ b/app/models/ci/runner.rb @@ -30,9 +30,9 @@ module Ci scope :ordered, -> { order(id: :desc) } # BACKWARD COMPATIBILITY: There are needed to maintain compatibility with `AVAILABLE_SCOPES` used by `lib/api/runners.rb` - scope :shared, -> { instance_type } + scope :deprecated_shared, -> { instance_type } # this should get replaced with `project_type.or(group_type)` once using Rails5 - scope :specific, -> { where(runner_type: [runner_types[:project_type], runner_types[:group_type]]) } + scope :deprecated_specific, -> { where(runner_type: [runner_types[:project_type], runner_types[:group_type]]) } scope :belonging_to_project, -> (project_id) { joins(:runner_projects).where(ci_runner_projects: { project_id: project_id }) diff --git a/lib/api/runners.rb b/lib/api/runners.rb index 6443e88e806..2071c5a62c1 100644 --- a/lib/api/runners.rb +++ b/lib/api/runners.rb @@ -170,6 +170,11 @@ module API render_api_error!('Scope contains invalid value', 400) end + # Support deprecated scopes + if runners.respond_to?("deprecated_#{scope}") + scope = "deprecated_#{scope}" + end + runners.public_send(scope) # rubocop:disable GitlabSecurity/PublicSend end diff --git a/spec/requests/api/runners_spec.rb b/spec/requests/api/runners_spec.rb index 0ad6472a59c..b5e4b6011ea 100644 --- a/spec/requests/api/runners_spec.rb +++ b/spec/requests/api/runners_spec.rb @@ -89,6 +89,17 @@ describe API::Runners do end end + it 'filters runners by scope' do + get api('/runners/all?scope=shared', admin) + + shared = json_response.all? { |r| r['is_shared'] } + expect(response).to have_gitlab_http_status(200) + expect(response).to include_pagination_headers + expect(json_response).to be_an Array + expect(json_response[0]).to have_key('ip_address') + expect(shared).to be_truthy + end + it 'filters runners by scope' do get api('/runners/all?scope=specific', admin) @@ -584,7 +595,7 @@ describe API::Runners do end end - it 'enables a instance-wide runner' do + it 'enables a instance type runner' do expect do post api("/projects/#{project.id}/runners", admin), runner_id: shared_runner.id end.to change { project.runners.count }.by(1)