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
Léo-Paul Géneau
gitlab-ce
Commits
82f9957d
Commit
82f9957d
authored
Dec 13, 2016
by
Dmitriy Zaporozhets
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor Namespace#parents method
Signed-off-by:
Dmitriy Zaporozhets
<
dmitriy.zaporozhets@gmail.com
>
parent
f8a17a38
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
8 additions
and
12 deletions
+8
-12
app/models/namespace.rb
app/models/namespace.rb
+1
-11
spec/models/namespace_spec.rb
spec/models/namespace_spec.rb
+7
-1
No files found.
app/models/namespace.rb
View file @
82f9957d
...
@@ -172,17 +172,7 @@ class Namespace < ActiveRecord::Base
...
@@ -172,17 +172,7 @@ class Namespace < ActiveRecord::Base
end
end
def
parents
def
parents
@parents
||=
@parents
||=
parent
?
parent
.
parents
+
[
parent
]
:
[]
begin
parents
=
[]
if
parent
parents
<<
parent
parents
+=
parent
.
parents
end
parents
end
end
end
private
private
...
...
spec/models/namespace_spec.rb
View file @
82f9957d
...
@@ -145,7 +145,13 @@ describe Namespace, models: true do
...
@@ -145,7 +145,13 @@ describe Namespace, models: true do
let
(
:group
)
{
create
(
:group
)
}
let
(
:group
)
{
create
(
:group
)
}
let
(
:nested_group
)
{
create
(
:group
,
parent:
group
)
}
let
(
:nested_group
)
{
create
(
:group
,
parent:
group
)
}
let
(
:deep_nested_group
)
{
create
(
:group
,
parent:
nested_group
)
}
let
(
:deep_nested_group
)
{
create
(
:group
,
parent:
nested_group
)
}
let
(
:very_deep_nested_group
)
{
create
(
:group
,
parent:
deep_nested_group
)
}
it
{
expect
(
deep_nested_group
.
parents
).
to
eq
([
nested_group
,
group
])
}
it
'returns the correct parents'
do
expect
(
very_deep_nested_group
.
parents
).
to
eq
([
group
,
nested_group
,
deep_nested_group
])
expect
(
deep_nested_group
.
parents
).
to
eq
([
group
,
nested_group
])
expect
(
nested_group
.
parents
).
to
eq
([
group
])
expect
(
group
.
parents
).
to
eq
([])
end
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