Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
李少辉-开发者
gitlab-foss
提交
071ad636
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,发现更多精彩内容 >>
提交
071ad636
编写于
5月 31, 2016
作者:
S
Sean McGivern
提交者:
Alfredo Sumaran
6月 03, 2016
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Spec label add / delete in UpdateService
上级
165d799f
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
54 addition
and
9 deletion
+54
-9
app/services/issuable_base_service.rb
app/services/issuable_base_service.rb
+8
-9
spec/services/issues/update_service_spec.rb
spec/services/issues/update_service_spec.rb
+46
-0
未找到文件。
app/services/issuable_base_service.rb
浏览文件 @
071ad636
...
@@ -72,18 +72,17 @@ class IssuableBaseService < BaseService
...
@@ -72,18 +72,17 @@ class IssuableBaseService < BaseService
if
params
[
:add_label_ids
].
present?
||
params
[
:remove_label_ids
].
present?
if
params
[
:add_label_ids
].
present?
||
params
[
:remove_label_ids
].
present?
params
.
delete
(
:label_ids
)
params
.
delete
(
:label_ids
)
filter_labels_by_name
([
:add_label_ids
,
:remove_label_ids
])
filter_labels_in_param
(
:add_label_ids
)
filter_labels_in_param
(
:remove_label_ids
)
else
else
filter_labels_
by_name
([
:label_ids
]
)
filter_labels_
in_param
(
:label_ids
)
end
end
end
end
def
filter_labels_by_name
(
keys
)
def
filter_labels_in_param
(
key
)
keys
.
each
do
|
key
|
return
if
params
[
key
].
to_a
.
empty?
next
if
params
[
key
].
to_a
.
empty?
params
[
key
]
=
project
.
labels
.
where
(
id:
params
[
key
]).
pluck
(
:id
)
params
[
key
]
=
project
.
labels
.
where
(
id:
params
[
key
]).
pluck
(
:id
)
end
end
end
def
update_issuable
(
issuable
,
attributes
)
def
update_issuable
(
issuable
,
attributes
)
...
@@ -94,7 +93,7 @@ class IssuableBaseService < BaseService
...
@@ -94,7 +93,7 @@ class IssuableBaseService < BaseService
issuable
.
label_ids
|=
add_label_ids
if
add_label_ids
issuable
.
label_ids
|=
add_label_ids
if
add_label_ids
issuable
.
label_ids
-=
remove_label_ids
if
remove_label_ids
issuable
.
label_ids
-=
remove_label_ids
if
remove_label_ids
issuable
.
assign_attributes
(
attributes
)
issuable
.
assign_attributes
(
attributes
.
merge
(
updated_by:
current_user
)
)
issuable
.
save
issuable
.
save
end
end
...
@@ -105,7 +104,7 @@ class IssuableBaseService < BaseService
...
@@ -105,7 +104,7 @@ class IssuableBaseService < BaseService
filter_params
filter_params
old_labels
=
issuable
.
labels
.
to_a
old_labels
=
issuable
.
labels
.
to_a
if
params
.
present?
&&
update_issuable
(
issuable
,
params
.
merge
(
updated_by:
current_user
)
)
if
params
.
present?
&&
update_issuable
(
issuable
,
params
)
issuable
.
reset_events_cache
issuable
.
reset_events_cache
handle_common_system_notes
(
issuable
,
old_labels:
old_labels
)
handle_common_system_notes
(
issuable
,
old_labels:
old_labels
)
handle_changes
(
issuable
,
old_labels:
old_labels
)
handle_changes
(
issuable
,
old_labels:
old_labels
)
...
...
spec/services/issues/update_service_spec.rb
浏览文件 @
071ad636
# coding: utf-8
require
'spec_helper'
require
'spec_helper'
describe
Issues
::
UpdateService
,
services:
true
do
describe
Issues
::
UpdateService
,
services:
true
do
...
@@ -273,5 +274,50 @@ describe Issues::UpdateService, services: true do
...
@@ -273,5 +274,50 @@ describe Issues::UpdateService, services: true do
end
end
end
end
end
end
context
'updating labels'
do
let
(
:label3
)
{
create
(
:label
,
project:
project
)
}
let
(
:result
)
{
Issues
::
UpdateService
.
new
(
project
,
user
,
params
).
execute
(
issue
).
reload
}
context
'when add_label_ids and label_ids are passed'
do
let
(
:params
)
{
{
label_ids:
[
label
.
id
],
add_label_ids:
[
label3
.
id
]
}
}
it
'ignores the label_ids parameter'
do
expect
(
result
.
label_ids
).
not_to
include
(
label
.
id
)
end
it
'adds the passed labels'
do
expect
(
result
.
label_ids
).
to
include
(
label3
.
id
)
end
end
context
'when remove_label_ids and label_ids are passed'
do
let
(
:params
)
{
{
label_ids:
[],
remove_label_ids:
[
label
.
id
]
}
}
before
{
issue
.
update_attributes
(
labels:
[
label
,
label3
])
}
it
'ignores the label_ids parameter'
do
expect
(
result
.
label_ids
).
not_to
be_empty
end
it
'removes the passed labels'
do
expect
(
result
.
label_ids
).
not_to
include
(
label
.
id
)
end
end
context
'when add_label_ids and remove_label_ids are passed'
do
let
(
:params
)
{
{
add_label_ids:
[
label3
.
id
],
remove_label_ids:
[
label
.
id
]
}
}
before
{
issue
.
update_attributes
(
labels:
[
label
])
}
it
'adds the passed labels'
do
expect
(
result
.
label_ids
).
to
include
(
label3
.
id
)
end
it
'removes the passed labels'
do
expect
(
result
.
label_ids
).
not_to
include
(
label
.
id
)
end
end
end
end
end
end
end
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录