Commit c2bf452c authored by Matija Čupić's avatar Matija Čupić

Refactor ClustersController pagination test

parent 9199d30a
......@@ -9,7 +9,7 @@ class Projects::ClustersController < Projects::ApplicationController
def index
@scope = params[:scope] || 'all'
clusters = ClustersFinder.new(project, current_user, @scope).execute
@clusters = clusters.page(params[:page]).per(20)
@clusters = clusters.page(params[:page])
@active_count = project.clusters.enabled.count
@inactive_count = project.clusters.disabled.count
@all_count = @active_count + @inactive_count
......
......@@ -33,20 +33,19 @@ describe Projects::ClustersController do
expect(assigns(:inactive_count)).to eq(project.clusters.disabled.count)
end
context 'properly paginates' do
before do
PAGE_LIMIT = 20
project.clusters = create_list(:cluster, PAGE_LIMIT + 1, :provided_by_gcp, projects: [project])
end
context 'when page is specified' do
let(:last_page) { project.clusters.page.total_pages }
it 'shows the first page' do
go
expect(assigns(:clusters).count).to eq(PAGE_LIMIT)
before do
Clusters::Cluster.paginates_per(1)
create_list(:cluster, 2, :provided_by_gcp, projects: [project])
get :index, namespace_id: project.namespace, project_id: project, page: last_page
end
it 'shows the second page' do
get :index, namespace_id: project.namespace, project_id: project, page: 2
expect(assigns(:clusters).count).to eq(1)
it 'redirects to the page' do
binding.pry
expect(response).to have_gitlab_http_status(:ok)
expect(assigns(:clusters).current_page).to eq(last_page)
end
end
......
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