Commit ad42e5ed authored by Sean McGivern's avatar Sean McGivern

Merge branch 'pedropombeiro/328518/move-pagination-to-controllers' into 'master'

Move runner pagination support to controllers

See merge request gitlab-org/gitlab!61585
parents c26630ac af91f2ca
......@@ -7,9 +7,11 @@ class Admin::RunnersController < Admin::ApplicationController
feature_category :continuous_integration
NUMBER_OF_RUNNERS_PER_PAGE = 30
def index
finder = Ci::RunnersFinder.new(current_user: current_user, params: params)
@runners = finder.execute
@runners = finder.execute.page(params[:page]).per(NUMBER_OF_RUNNERS_PER_PAGE)
@active_runners_count = Ci::Runner.online.count
@sort = finder.sort_key
end
......
......@@ -4,8 +4,6 @@ module Ci
class RunnersFinder < UnionFinder
include Gitlab::Allowable
NUMBER_OF_RUNNERS_PER_PAGE = 30
def initialize(current_user:, group: nil, params:)
@params = params
@group = group
......@@ -18,7 +16,6 @@ module Ci
filter_by_runner_type!
filter_by_tag_list!
sort!
paginate!
@runners.with_tags
......@@ -77,10 +74,6 @@ module Ci
@runners = @runners.order_by(sort_key)
end
def paginate!
@runners = @runners.page(@params[:page]).per(NUMBER_OF_RUNNERS_PER_PAGE)
end
def filter_by!(scope_name, available_scopes)
scope = @params[scope_name]
......
......@@ -34,6 +34,17 @@ RSpec.describe Admin::RunnersController do
expect(response.body).to have_content('tag1')
expect(response.body).to have_content('tag2')
end
it 'paginates runners' do
stub_const("Admin::RunnersController::NUMBER_OF_RUNNERS_PER_PAGE", 1)
create(:ci_runner)
get :index
expect(response).to have_gitlab_http_status(:ok)
expect(assigns(:runners).count).to be(1)
end
end
describe '#show' do
......
......@@ -32,6 +32,17 @@ RSpec.describe Groups::Settings::CiCdController do
expect(response).to render_template(:show)
expect(assigns(:group_runners)).to match_array([runner_group, runner_project_1, runner_project_2, runner_project_3])
end
it 'paginates runners' do
stub_const("Groups::Settings::CiCdController::NUMBER_OF_RUNNERS_PER_PAGE", 1)
create(:ci_runner)
get :show, params: { group_id: group }
expect(response).to have_gitlab_http_status(:ok)
expect(assigns(:group_runners).count).to be(1)
end
end
context 'when user is not owner' do
......
......@@ -72,17 +72,6 @@ RSpec.describe Ci::RunnersFinder do
end
end
context 'paginate' do
it 'returns the runners for the specified page' do
stub_const('Ci::RunnersFinder::NUMBER_OF_RUNNERS_PER_PAGE', 1)
runner1 = create :ci_runner, created_at: '2018-07-12 07:00'
runner2 = create :ci_runner, created_at: '2018-07-12 08:00'
expect(described_class.new(current_user: admin, params: { page: 1 }).execute).to eq [runner2]
expect(described_class.new(current_user: admin, params: { page: 2 }).execute).to eq [runner1]
end
end
context 'non admin user' do
it 'returns no runners' do
user = create :user
......@@ -172,38 +161,6 @@ RSpec.describe Ci::RunnersFinder do
end
end
context 'paginate' do
using RSpec::Parameterized::TableSyntax
let(:runners) do
[[runner_project_7, runner_project_6, runner_project_5],
[runner_project_4, runner_project_3, runner_project_2],
[runner_project_1, runner_sub_group_4, runner_sub_group_3],
[runner_sub_group_2, runner_sub_group_1, runner_group]]
end
where(:page, :index) do
1 | 0
2 | 1
3 | 2
4 | 3
end
before do
stub_const('Ci::RunnersFinder::NUMBER_OF_RUNNERS_PER_PAGE', 3)
group.add_owner(user)
end
with_them do
let(:params) { { page: page } }
it 'returns the runners for the specified page' do
expect(subject).to eq(runners[index])
end
end
end
context 'filter by search term' do
let(:params) { { search: 'runner_project_search' } }
......
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