Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
李少辉-开发者
gitlab-foss
提交
63e61cfd
G
gitlab-foss
项目概览
李少辉-开发者
/
gitlab-foss
通知
15
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
gitlab-foss
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
63e61cfd
编写于
3月 15, 2017
作者:
A
Alexis Reigel
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
use more explicit and explanatory sql statement
上级
1735ed61
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
26 addition
and
8 deletion
+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
未找到文件。
app/models/concerns/routable.rb
浏览文件 @
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
浏览文件 @
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
)
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录