BigW Consortium Gitlab

Commit 4d791599 by Bob Van Landuyt

Make sure we always return an array of hierarchies

Even when we pass an array of only a single object
parent a1bfdf76
......@@ -28,7 +28,9 @@ class GroupChildSerializer < BaseSerializer
represent_hierarchy(children.hierarchy(hierarchy_root), opts).first
else
hierarchies = GroupDescendant.build_hierarchy(children, hierarchy_root)
represent_hierarchy(hierarchies, opts)
# When an array was passed, we always want to represent an array.
# Even if the hierarchy only contains one element
represent_hierarchy(Array.wrap(hierarchies), opts)
end
end
......
......@@ -141,6 +141,15 @@ describe Groups::ChildrenController do
expect(response).to have_http_status(200)
end
it 'returns an array with one element when only one result is matched' do
create(:project, :public, namespace: group, name: 'match')
get :index, group_id: group.to_param, filter: 'match', format: :json
expect(json_response).to be_kind_of(Array)
expect(json_response.size).to eq(1)
end
it 'returns an empty array when there are no search results' do
subgroup = create(:group, :public, parent: group)
l2_subgroup = create(:group, :public, parent: subgroup)
......
......@@ -95,6 +95,15 @@ describe GroupChildSerializer do
expect(project1_json[:id]).to eq(project1.id)
expect(project2_json[:id]).to eq(project2.id)
end
it 'returns an array when an array of a single instance was given' do
project = create(:project, namespace: parent)
json = serializer.represent([project])
expect(json).to be_kind_of(Array)
expect(json.size).to eq(1)
end
end
end
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