Commit b92e7103 authored by Bob Van Landuyt's avatar Bob Van Landuyt

Fix nesting bug when rendering children of a shared subgroup

parent ac0b104a
......@@ -64,7 +64,7 @@ class GroupDescendantsFinder
subgroups_with_counts = ancestors_for_project_search.with_route.select(group_selects) | subgroups_with_counts
end
@children = subgroups_with_counts + projects.preload(:route)
@children = subgroups_with_counts + projects.with_route
end
def direct_child_groups
......
......@@ -41,7 +41,7 @@ class GroupChildSerializer < BaseSerializer
.merge(children: Array.wrap(serializer.represent_hierarchy(children, opts)))
end
elsif hierarchy.is_a?(Array)
hierarchy.map { |child| serializer.represent_hierarchy(child, opts) }
hierarchy.map { |child| serializer.represent_hierarchy(child, opts) }.flatten
else
serializer.represent(hierarchy, opts)
end
......
......@@ -293,6 +293,32 @@ describe GroupsController do
expect(matched_group_json['id']).to eq(matched_group.id)
end
it 'merges the trees correctly' do
shared_subgroup = create(:group, :public, parent: group, path: 'hardware')
matched_project_1 = create(:project, :public, namespace: shared_subgroup, name: 'mobile-soc')
l2_subgroup = create(:group, :public, parent: shared_subgroup, path: 'broadcom')
l3_subgroup = create(:group, :public, parent: l2_subgroup, path: 'wifi-group')
matched_project_2 = create(:project, :public, namespace: l3_subgroup, name: 'mobile')
get :children, id: group.to_param, filter: 'mobile', format: :json
shared_group_json = json_response.first
expect(shared_group_json['id']).to eq(shared_subgroup.id)
matched_project_1_json = shared_group_json['children'].detect { |child| child['type'] == 'project' }
expect(matched_project_1_json['id']).to eq(matched_project_1.id)
l2_subgroup_json = shared_group_json['children'].detect { |child| child['type'] == 'group' }
expect(l2_subgroup_json['id']).to eq(l2_subgroup.id)
l3_subgroup_json = l2_subgroup_json['children'].first
expect(l3_subgroup_json['id']).to eq(l3_subgroup.id)
matched_project_2_json = l3_subgroup_json['children'].first
expect(matched_project_2_json['id']).to eq(matched_project_2.id)
end
it 'includes pagination headers' do
2.times { |i| create(:group, :public, parent: public_subgroup, name: "filterme#{i}") }
......
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