diff options
author | Kamil Trzciński <ayufan@ayufan.eu> | 2018-07-04 11:02:45 +0200 |
---|---|---|
committer | Kamil Trzciński <ayufan@ayufan.eu> | 2018-07-04 11:02:45 +0200 |
commit | d3bcb06dc6365129b62dadf49efc58daecd39a83 (patch) | |
tree | f44332a1d3dccfabd84df94c44eacfb459f34385 | |
parent | ca93faf15f822cbf3eda5e87d4aaaaa81d413a8b (diff) | |
download | gitlab-ce-d3bcb06dc6365129b62dadf49efc58daecd39a83.tar.gz |
Make deprecated scopes of Runner explicit
-rw-r--r-- | app/models/ci/runner.rb | 4 | ||||
-rw-r--r-- | lib/api/runners.rb | 5 | ||||
-rw-r--r-- | 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 @@ -90,6 +90,17 @@ describe API::Runners do 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) shared = json_response.any? { |r| r['is_shared'] } @@ -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) |