Commit 8419b7dd authored by Thong Kuah's avatar Thong Kuah

Teach Cluster about #all_projects

For project level, it's the project directly associated. For group
level, it's the projects under that group.
parent 9c5977c8
......@@ -133,6 +133,16 @@ module Clusters
!user?
end
def all_projects
if project_type?
projects
elsif group_type?
first_group.all_projects
else
Project.none
end
end
def first_project
strong_memoize(:first_project) do
projects.first
......
......@@ -312,6 +312,31 @@ describe Clusters::Cluster do
end
end
describe '#all_projects' do
let(:project) { create(:project) }
let(:cluster) { create(:cluster, projects: [project]) }
subject { cluster.all_projects }
context 'project cluster' do
it 'returns project' do
is_expected.to eq([project])
end
end
context 'group cluster' do
let(:cluster) { create(:cluster, :group) }
let(:group) { cluster.group }
let(:project) { create(:project, group: group) }
let(:subgroup) { create(:group, parent: group) }
let(:subproject) { create(:project, group: subgroup) }
it 'returns all projects for group' do
is_expected.to contain_exactly(project, subproject)
end
end
end
describe '#first_project' do
subject { cluster.first_project }
......
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