Read about our upcoming Code of Conduct on this issue

Commit e81af3d4 authored by Thong Kuah's avatar Thong Kuah
Browse files

Teach Project about #all_clusters

This returns a union of the project level clusters and group level
clusters associated with this project.
parent 821e0912c729
......@@ -4,6 +4,7 @@ module Clusters
class Cluster < ActiveRecord::Base
include Presentable
include Gitlab::Utils::StrongMemoize
include FromUnion
self.table_name = 'clusters'
......
......@@ -1061,6 +1061,12 @@ def code
path
end
def all_clusters
group_clusters = Clusters::Cluster.joins(:groups).where(cluster_groups: { group_id: ancestors_upto } )
Clusters::Cluster.from_union([clusters, group_clusters])
end
def items_for(entity)
case entity
when 'issue' then
......
......@@ -3984,6 +3984,27 @@ def domain_variable
end
end
describe '#all_clusters' do
let(:project) { create(:project) }
let(:cluster) { create(:cluster, cluster_type: :project_type, projects: [project]) }
subject { project.all_clusters }
it 'returns project level cluster' do
expect(subject).to eq([cluster])
end
context 'project belongs to a group' do
let(:group_cluster) { create(:cluster, :group) }
let(:group) { group_cluster.group }
let(:project) { create(:project, group: group) }
it 'returns clusters for groups of this project' do
expect(subject).to contain_exactly(cluster, group_cluster)
end
end
end
def rugged_config
rugged_repo(project.repository).config
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