Commit 4d75901c authored by Matija Čupić's avatar Matija Čupić

Use ClustersFinder for setting counts

parent f81503a0
...@@ -9,10 +9,9 @@ class Projects::ClustersController < Projects::ApplicationController ...@@ -9,10 +9,9 @@ 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.page(params[:page])
@clusters = clusters.page(params[:page]) @active_count = ClustersFinder.new(project, current_user, :active).execute.count
@active_count = project.clusters.enabled.count @inactive_count = ClustersFinder.new(project, current_user, :inactive).execute.count
@inactive_count = project.clusters.disabled.count
@all_count = @active_count + @inactive_count @all_count = @active_count + @inactive_count
end end
......
...@@ -17,9 +17,8 @@ describe Projects::ClustersController do ...@@ -17,9 +17,8 @@ describe Projects::ClustersController do
context 'when project has one or more clusters' do context 'when project has one or more clusters' do
let(:project) { create(:project) } let(:project) { create(:project) }
let(:enabled_cluster) { create(:cluster, :provided_by_gcp, projects: [project]) } let!(:enabled_cluster) { create(:cluster, :provided_by_gcp, projects: [project]) }
let(:disabled_cluster) { create(:cluster, :disabled, :provided_by_gcp, projects: [project]) } let!(:disabled_cluster) { create(:cluster, :disabled, :provided_by_gcp, projects: [project]) }
it 'lists available clusters' do it 'lists available clusters' do
go go
...@@ -31,8 +30,8 @@ describe Projects::ClustersController do ...@@ -31,8 +30,8 @@ describe Projects::ClustersController do
it 'assigns counters to correct values' do it 'assigns counters to correct values' do
go go
expect(assigns(:active_count)).to eq(project.clusters.enabled.count) expect(assigns(:active_count)).to eq(1)
expect(assigns(:inactive_count)).to eq(project.clusters.disabled.count) expect(assigns(:inactive_count)).to eq(1)
end end
context 'when page is specified' do context 'when page is specified' do
......
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