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