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:
-rw-r--r--app/serializers/group_child_serializer.rb4
-rw-r--r--spec/controllers/groups/children_controller_spec.rb9
-rw-r--r--spec/serializers/group_child_serializer_spec.rb9
3 files changed, 21 insertions, 1 deletions
diff --git a/app/serializers/group_child_serializer.rb b/app/serializers/group_child_serializer.rb
index 6d0e67a37cd..2baef0a5703 100644
--- a/app/serializers/group_child_serializer.rb
+++ b/app/serializers/group_child_serializer.rb
@@ -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
diff --git a/spec/controllers/groups/children_controller_spec.rb b/spec/controllers/groups/children_controller_spec.rb
index f15a12ef7fd..4262d474e59 100644
--- a/spec/controllers/groups/children_controller_spec.rb
+++ b/spec/controllers/groups/children_controller_spec.rb
@@ -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)
diff --git a/spec/serializers/group_child_serializer_spec.rb b/spec/serializers/group_child_serializer_spec.rb
index 566b235769e..5541ada3750 100644
--- a/spec/serializers/group_child_serializer_spec.rb
+++ b/spec/serializers/group_child_serializer_spec.rb
@@ -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