Commit 9783ae9a authored by Sean Arnold's avatar Sean Arnold

Add with_deployment_in_environment to Cluster

parent c2f58421
......@@ -136,6 +136,7 @@ module Clusters
conditions = { projects: { alerts_service: [:data] } }
includes(conditions).joins(conditions).where(projects: { id: project_ids })
end
scope :with_deployment_in_environment, -> (environment) { joins(:deployments).merge(Deployment.for_environment(environment)) }
def self.ancestor_clusters_for_clusterable(clusterable, hierarchy_order: :asc)
return [] if clusterable.is_a?(Instance)
......
......@@ -207,6 +207,24 @@ describe Clusters::Cluster, :use_clean_rails_memory_store_caching do
end
end
describe '.with_project_alert_service_data' do
subject { described_class.with_deployment_in_environment(environment) }
let(:project) { create(:project, :repository) }
let!(:cluster) { create(:cluster, projects: [project]) }
let!(:environment) { create(:environment) }
context 'deployment in environment' do
let!(:deployment) { create(:deployment, cluster: cluster, environment: environment, sha: cluster.project.commit.id) }
it { is_expected.to include(cluster) }
end
context 'no deployment in environment' do
it { is_expected.not_to include(cluster) }
end
end
describe '.for_project_namespace' do
subject { described_class.for_project_namespace(namespace_id) }
......
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