Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBob Van Landuyt <bob@vanlanduyt.co>2017-09-07 20:08:56 +0300
committerBob Van Landuyt <bob@vanlanduyt.co>2017-10-04 23:49:41 +0300
commit518216c0627cb6c4b3db62f10877b44d0e912ddb (patch)
tree68a4aa0a3301728097e73c6e09c48780a1b52757 /spec/models/concerns
parent530cf2a2669ea1ee3c41d48a15919f875babefa4 (diff)
Merge group hierarchies when parents are shared
Diffstat (limited to 'spec/models/concerns')
-rw-r--r--spec/models/concerns/group_hierarchy_spec.rb68
1 files changed, 68 insertions, 0 deletions
diff --git a/spec/models/concerns/group_hierarchy_spec.rb b/spec/models/concerns/group_hierarchy_spec.rb
index 14ac910c90d..1f4fab88781 100644
--- a/spec/models/concerns/group_hierarchy_spec.rb
+++ b/spec/models/concerns/group_hierarchy_spec.rb
@@ -29,6 +29,40 @@ describe GroupHierarchy, :nested_groups do
expect(subsub_group.parent).to eq(subgroup)
end
end
+
+ describe '#merge_hierarchy' do
+ it 'combines hierarchies' do
+ other_subgroup = create(:group, parent: parent)
+
+ expected_hierarchy = { parent => [{ subgroup => subsub_group }, other_subgroup] }
+
+ expect(subsub_group.merge_hierarchy(other_subgroup)).to eq(expected_hierarchy)
+ end
+ end
+
+ describe '.merge_hierarchies' do
+ it 'combines hierarchies until the top' do
+ other_subgroup = create(:group, parent: parent)
+ other_subsub_group = create(:group, parent: subgroup)
+
+ groups = [other_subgroup, subsub_group, other_subsub_group]
+
+ expected_hierarchy = { parent => [other_subgroup, { subgroup => [subsub_group, other_subsub_group] }] }
+
+ expect(described_class.merge_hierarchies(groups)).to eq(expected_hierarchy)
+ end
+
+ it 'combines upto a given parent' do
+ other_subgroup = create(:group, parent: parent)
+ other_subsub_group = create(:group, parent: subgroup)
+
+ groups = [other_subgroup, subsub_group, other_subsub_group]
+
+ expected_hierarchy = [other_subgroup, { subgroup => [subsub_group, other_subsub_group] }]
+
+ expect(described_class.merge_hierarchies(groups, parent)).to eq(expected_hierarchy)
+ end
+ end
end
context 'for a project' do
@@ -57,5 +91,39 @@ describe GroupHierarchy, :nested_groups do
expect(project.parent).to eq(subsub_group)
end
end
+
+ describe '#merge_hierarchy' do
+ it 'combines hierarchies' do
+ project = create(:project, namespace: parent)
+
+ expected_hierarchy = { parent => [{ subgroup => subsub_group }, project] }
+
+ expect(subsub_group.merge_hierarchy(project)).to eq(expected_hierarchy)
+ end
+ end
+
+ describe '.merge_hierarchies' do
+ it 'combines hierarchies until the top' do
+ other_project = create(:project, namespace: parent)
+ other_subgroup_project = create(:project, namespace: subgroup)
+
+ elements = [other_project, subsub_group, other_subgroup_project]
+
+ expected_hierarchy = { parent => [other_project, { subgroup => [subsub_group, other_subgroup_project] }] }
+
+ expect(described_class.merge_hierarchies(elements)).to eq(expected_hierarchy)
+ end
+
+ it 'combines upto a given parent' do
+ other_project = create(:project, namespace: parent)
+ other_subgroup_project = create(:project, namespace: subgroup)
+
+ elements = [other_project, subsub_group, other_subgroup_project]
+
+ expected_hierarchy = [other_project, { subgroup => [subsub_group, other_subgroup_project] }]
+
+ expect(described_class.merge_hierarchies(elements, parent)).to eq(expected_hierarchy)
+ end
+ end
end
end