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
Tatuya Kamada
gitlab-ce
Commits
63e61cfd
Commit
63e61cfd
authored
Mar 15, 2017
by
Alexis Reigel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
use more explicit and explanatory sql statement
parent
1735ed61
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
26 additions
and
8 deletions
+26
-8
app/models/concerns/routable.rb
app/models/concerns/routable.rb
+3
-1
spec/models/concerns/routable_spec.rb
spec/models/concerns/routable_spec.rb
+23
-7
No files found.
app/models/concerns/routable.rb
View file @
63e61cfd
...
...
@@ -144,7 +144,9 @@ module Routable
return
none
if
paths
.
empty?
wheres
=
paths
.
map
do
|
path
|
"
#{
connection
.
quote
(
path
)
}
LIKE CONCAT(routes.path, '%')"
"
#{
connection
.
quote
(
path
)
}
= routes.path
OR
#{
connection
.
quote
(
path
)
}
LIKE CONCAT(routes.path, '/%')"
end
joins
(
:route
).
where
(
wheres
.
join
(
' OR '
))
...
...
spec/models/concerns/routable_spec.rb
View file @
63e61cfd
require
'spec_helper'
describe
Group
,
'Routable'
do
let!
(
:group
)
{
create
(
:group
,
name:
'
group 1
'
)
}
let!
(
:group
)
{
create
(
:group
,
name:
'
foo
'
)
}
describe
'Validations'
do
it
{
is_expected
.
to
validate_presence_of
(
:route
)
}
...
...
@@ -92,20 +92,24 @@ describe Group, 'Routable' do
end
describe
'.member_hierarchy'
do
# foo/bar would also match foo/barbaz instead of just foo/bar and foo/bar/baz
let!
(
:user
)
{
create
(
:user
)
}
# _______ group _______
# group
# _______ (foo) _______
# | |
# | |
# nested_group_1 nested_group_2
# (bar) (barbaz)
# | |
# | |
# nested_group_1_1 nested_group_2_1
# (baz) (baz)
#
let!
(
:nested_group_1
)
{
create
:group
,
parent:
group
,
name:
'
group 1-1
'
}
let!
(
:nested_group_1_1
)
{
create
:group
,
parent:
nested_group_1
,
name:
'
group 1-1-1
'
}
let!
(
:nested_group_2
)
{
create
:group
,
parent:
group
,
name:
'
group 1-2
'
}
let!
(
:nested_group_2_1
)
{
create
:group
,
parent:
nested_group_2
,
name:
'
group 1-2-1
'
}
let!
(
:nested_group_1
)
{
create
:group
,
parent:
group
,
name:
'
bar
'
}
let!
(
:nested_group_1_1
)
{
create
:group
,
parent:
nested_group_1
,
name:
'
baz
'
}
let!
(
:nested_group_2
)
{
create
:group
,
parent:
group
,
name:
'
barbaz
'
}
let!
(
:nested_group_2_1
)
{
create
:group
,
parent:
nested_group_2
,
name:
'
baz
'
}
context
'user is not a member of any group'
do
subject
{
described_class
.
member_hierarchy
(
user
.
id
)
}
...
...
@@ -147,7 +151,7 @@ describe Group, 'Routable' do
end
end
context
'user is member of the first child (internal node)'
do
context
'user is member of the first child (internal node)
, branch 1
'
do
before
{
nested_group_1
.
add_owner
(
user
)
}
subject
{
described_class
.
member_hierarchy
(
user
.
id
)
}
...
...
@@ -159,6 +163,18 @@ describe Group, 'Routable' do
end
end
context
'user is member of the first child (internal node), branch 2'
do
before
{
nested_group_2
.
add_owner
(
user
)
}
subject
{
described_class
.
member_hierarchy
(
user
.
id
)
}
it
'returns the groups in the hierarchy'
do
is_expected
.
to
match_array
[
group
,
nested_group_2
,
nested_group_2_1
]
end
end
context
'user is member of the last child (leaf node)'
do
before
{
nested_group_1_1
.
add_owner
(
user
)
}
subject
{
described_class
.
member_hierarchy
(
user
.
id
)
}
...
...
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