Commit 24aadbdf authored by Filipa Lacerda's avatar Filipa Lacerda

Merge branch 'list-multiple-clusters' of...

Merge branch 'list-multiple-clusters' of https://gitlab.com/gitlab-org/gitlab-ce into list-multiple-clusters

* 'list-multiple-clusters' of https://gitlab.com/gitlab-org/gitlab-ce:
  Fix symbolization error in #clusters
  Add specs for scoping in ClustersController
  Add pagination specs for ClustersController
  Add specs for cluster counters
  Use current_user in ClustersController#clusters
  Add specs for ClustersFinder
parents 074fcb56 061b4963
......@@ -102,7 +102,7 @@ class Projects::ClustersController < Projects::ApplicationController
end
def clusters
scope = params[:scope] || :all
scope = params[:scope]&.to_sym || :all
@clusters = ClustersFinder.new(project, current_user, scope).execute
end
......
......@@ -14,6 +14,6 @@
%li{ class: ('active' if @scope.nil? || @scope == 'all') }>
= link_to project_clusters_path(@project, scope: :all), class: "js-all-tab #{'active' if @scope == 'all' || @scope.nil?}" do
= s_("ClusterIntegration|All")
%span.badge= @inactive_count
%span.badge= @all_count
.pull-right.nav-bar-right
= link_to s_("ClusterIntegration|Add cluster"), new_project_cluster_path(@project), class: "btn btn-success disabled has-tooltip js-add-cluster", title: s_("ClusterIntegration|Multiple clusters are available in GitLab Entreprise Edition Premium and Ultimate")
......@@ -14,15 +14,52 @@ describe Projects::ClustersController do
end
context 'when project has one or more clusters' do
let(:cluster) { create(:cluster, :project, :provided_by_gcp) }
let(:project) { cluster.project }
let(:project) { create(:project) }
let(:clusters) { create_list(:cluster, 2, :provided_by_gcp, projects: [project]) }
before do
clusters.last.enabled = false
end
it 'lists available clusters' do
go
expect(response).to have_gitlab_http_status(:ok)
expect(response).to render_template(:index)
expect(assigns(:clusters)).to eq([cluster])
expect(assigns(:clusters)).to eq(clusters)
end
it 'assigns counters to correct values' do
go
expect(assigns(:active_count)).to eq(project.clusters.enabled.count)
expect(assigns(:inactive_count)).to eq(project.clusters.disabled.count)
end
it 'properly paginates' do
PAGE_LIMIT = 20
project.clusters = create_list(:cluster, PAGE_LIMIT + 1, :provided_by_gcp, projects: [project])
go
expect(assigns(:clusters).count).to eq(20)
get :index, namespace_id: project.namespace.to_param, project_id: project, page: 2
expect(assigns(:clusters).count).to eq(1)
end
context 'when only enabled clusters are requested' do
it 'returns only enabled clusters' do
get :index, namespace_id: project.namespace.to_param, project_id: project, scope: 'enabled'
clusters = assigns(:clusters)
expect(clusters.all? { |cluster| cluster.enabled == true }).to eq(true)
end
end
context 'when only disabled clusters are requested' do
it 'returns only disabled clusters' do
get :index, namespace_id: project.namespace.to_param, project_id: project, scope: 'disabled'
clusters = assigns(:clusters)
expect(clusters.all? { |cluster| cluster.enabled == false }).to eq(true)
end
end
end
......@@ -36,6 +73,13 @@ describe Projects::ClustersController do
expect(response).to render_template(:index)
expect(assigns(:clusters)).to eq([])
end
it 'assigns counters to zero' do
go
expect(assigns(:active_count)).to eq(0)
expect(assigns(:inactive_count)).to eq(0)
end
end
end
......
require 'spec_helper'
describe ClustersFinder do
let(:project) { create(:project) }
set(:user) { create(:user) }
describe '#execute' do
before do
create_list(:cluster, 2, :provided_by_gcp, projects: [project])
project.clusters.last.enabled = false
end
subject { described_class.new(project, user, scope).execute }
context 'when scope is all' do
let(:scope) { :all }
it { is_expected.to eq(project.clusters.to_a) }
end
context 'when scope is enabled' do
let(:scope) { :enabled }
it { is_expected.to eq(project.clusters.enabled.to_a) }
end
context 'when scope is disabled' do
let(:scope) { :disabled }
it { is_expected.to eq(project.clusters.disabled.to_a) }
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