Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Boxiang Sun
gitlab-ce
Commits
4d791599
Commit
4d791599
authored
Oct 13, 2017
by
Bob Van Landuyt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make sure we always return an array of hierarchies
Even when we pass an array of only a single object
parent
a1bfdf76
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
21 additions
and
1 deletion
+21
-1
app/serializers/group_child_serializer.rb
app/serializers/group_child_serializer.rb
+3
-1
spec/controllers/groups/children_controller_spec.rb
spec/controllers/groups/children_controller_spec.rb
+9
-0
spec/serializers/group_child_serializer_spec.rb
spec/serializers/group_child_serializer_spec.rb
+9
-0
No files found.
app/serializers/group_child_serializer.rb
View file @
4d791599
...
...
@@ -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
...
...
spec/controllers/groups/children_controller_spec.rb
View file @
4d791599
...
...
@@ -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
)
...
...
spec/serializers/group_child_serializer_spec.rb
View file @
4d791599
...
...
@@ -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
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment