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

Extract cluster installed query to scope

parent f6fa8429
......@@ -53,6 +53,8 @@ module Clusters
scope :disabled, -> { where(enabled: false) }
scope :user_provided, -> { where(provider_type: ::Clusters::Cluster.provider_types[:user]) }
scope :gcp_provided, -> { where(provider_type: ::Clusters::Cluster.provider_types[:gcp]) }
scope :gcp_installed, -> { gcp_provided.includes(:provider_gcp).where(cluster_providers_gcp: { status: ::Clusters::Providers::Gcp.state_machines[:status].states[:created].value }) }
scope :default_environment, -> { where(environment_scope: DEFAULT_ENVIRONMENT) }
def status_name
......
......@@ -51,7 +51,7 @@ module Gitlab
clusters: ::Clusters::Cluster.count,
clusters_enabled: ::Clusters::Cluster.enabled.count,
clusters_disabled: ::Clusters::Cluster.disabled.count,
clusters_platforms_gke: ::Clusters::Cluster.gcp_provided.includes(:provider_gcp).where(cluster_providers_gcp: { status: ::Clusters::Providers::Gcp.state_machines[:status].states[:created].value }).enabled.count,
clusters_platforms_gke: ::Clusters::Cluster.gcp_installed.enabled.count,
clusters_platforms_user: ::Clusters::Cluster.user_provided.enabled.count,
clusters_applications_helm: ::Clusters::Applications::Helm.installed.count,
clusters_applications_ingress: ::Clusters::Applications::Ingress.installed.count,
......
......@@ -63,6 +63,18 @@ describe Clusters::Cluster do
it { is_expected.to contain_exactly(cluster) }
end
describe '.gcp_installed' do
subject { described_class.gcp_installed }
let!(:cluster) { create(:cluster, :provided_by_gcp) }
before do
create(:cluster, :providing_by_gcp)
end
it { is_expected.to contain_exactly(cluster) }
end
describe 'validation' do
subject { cluster.valid? }
......
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