summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBob Van Landuyt <bob@vanlanduyt.co>2017-10-03 15:32:32 +0200
committerBob Van Landuyt <bob@vanlanduyt.co>2017-10-04 22:49:42 +0200
commit67815272dceb971c03bea3490ec26529b48a52b4 (patch)
tree455f30ba7fa73b94844e5ed36041d61c43f6e92b
parent167fd71348d145c6fee953004bf77ceebf6efb1e (diff)
downloadgitlab-ce-67815272dceb971c03bea3490ec26529b48a52b4.tar.gz
Return an empty array when no matches are found
-rw-r--r--app/models/concerns/group_descendant.rb2
-rw-r--r--spec/controllers/groups_controller_spec.rb10
2 files changed, 11 insertions, 1 deletions
diff --git a/app/models/concerns/group_descendant.rb b/app/models/concerns/group_descendant.rb
index f37d23e615e..11f092db2ae 100644
--- a/app/models/concerns/group_descendant.rb
+++ b/app/models/concerns/group_descendant.rb
@@ -6,7 +6,7 @@ module GroupDescendant
def self.build_hierarchy(descendants, hierarchy_top = nil)
descendants = Array.wrap(descendants)
- return if descendants.empty?
+ return [] if descendants.empty?
unless descendants.all? { |hierarchy| hierarchy.is_a?(GroupDescendant) }
raise ArgumentError.new('element is not a hierarchy')
diff --git a/spec/controllers/groups_controller_spec.rb b/spec/controllers/groups_controller_spec.rb
index 00a6fa885bf..8582f31f059 100644
--- a/spec/controllers/groups_controller_spec.rb
+++ b/spec/controllers/groups_controller_spec.rb
@@ -331,6 +331,16 @@ describe GroupsController do
expect(response).to have_http_status(200)
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)
+ create(:project, :public, namespace: l2_subgroup, name: 'no-match')
+
+ get :children, id: subgroup.to_param, filter: 'test', format: :json
+
+ expect(json_response).to eq([])
+ end
+
it 'includes pagination headers' do
2.times { |i| create(:group, :public, parent: public_subgroup, name: "filterme#{i}") }