Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
李少辉-开发者
gitlab-foss
提交
ed954eba
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,发现更多精彩内容 >>
提交
ed954eba
编写于
8月 31, 2012
作者:
D
Dmitriy Zaporozhets
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #1326 from AlexDenisov/issue_status_changed_notifications
Issue status changed notifications
上级
65abd8b2
2703fe3e
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
119 addition
and
9 deletion
+119
-9
app/mailers/notify.rb
app/mailers/notify.rb
+8
-0
app/observers/issue_observer.rb
app/observers/issue_observer.rb
+10
-2
app/views/notify/issue_status_changed_email.html.haml
app/views/notify/issue_status_changed_email.html.haml
+16
-0
spec/mailers/notify_spec.rb
spec/mailers/notify_spec.rb
+23
-0
spec/observers/issue_observer_spec.rb
spec/observers/issue_observer_spec.rb
+62
-7
未找到文件。
app/mailers/notify.rb
浏览文件 @
ed954eba
...
...
@@ -83,6 +83,14 @@ class Notify < ActionMailer::Base
subject:
subject
(
"access to project was granted"
))
end
def
issue_status_changed_email
(
recipient_id
,
issue_id
,
status
,
updated_by_user_id
)
@issue
=
Issue
.
find
issue_id
@issue_status
=
status
@updated_by
=
User
.
find
updated_by_user_id
mail
(
to:
recipient
(
recipient_id
),
subject:
subject
(
"changed issue #
#{
@issue
.
id
}
"
,
@issue
.
title
))
end
private
# Look up a User by their ID and return their email address
...
...
app/observers/issue_observer.rb
浏览文件 @
ed954eba
...
...
@@ -9,8 +9,16 @@ class IssueObserver < ActiveRecord::Observer
def
after_update
(
issue
)
send_reassigned_email
(
issue
)
if
issue
.
is_being_reassigned?
Note
.
create_status_change_note
(
issue
,
current_user
,
'closed'
)
if
issue
.
is_being_closed?
Note
.
create_status_change_note
(
issue
,
current_user
,
'reopened'
)
if
issue
.
is_being_reopened?
status
=
nil
status
=
'closed'
if
issue
.
is_being_closed?
status
=
'reopened'
if
issue
.
is_being_reopened?
if
status
Note
.
create_status_change_note
(
issue
,
current_user
,
status
)
[
issue
.
author
,
issue
.
assignee
].
compact
.
each
do
|
recipient
|
Notify
.
issue_status_changed_email
(
recipient
.
id
,
issue
.
id
,
status
,
current_user
)
end
end
end
protected
...
...
app/views/notify/issue_status_changed_email.html.haml
0 → 100644
浏览文件 @
ed954eba
%td
.content
{
align:
"left"
,
style:
"font-family: Helvetica, Arial, sans-serif; padding: 20px 0 0;"
,
valign:
"top"
,
width:
"600"
}
%table
{
border:
"0"
,
cellpadding:
"0"
,
cellspacing:
"0"
,
style:
"color: #717171; font: normal 11px Helvetica, Arial, sans-serif; margin: 0; padding: 0;"
,
width:
"600"
}
%tr
%td
{
style:
"font-size: 1px; line-height: 1px;"
,
width:
"21"
}
%td
{
align:
"left"
,
style:
"padding: 20px 0 0;"
}
%h2
{
style:
"color:#646464; font-weight: bold; margin: 0; padding: 0; line-height: 26px; font-size: 18px; font-family: Helvetica, Arial, sans-serif; "
}
=
"Issue was
#{
@issue_status
}
by
#{
@updated_by
.
name
}
"
%td
{
style:
"font-size: 1px; line-height: 1px;"
,
width:
"21"
}
%tr
%td
{
style:
"font-size: 1px; line-height: 1px;"
,
width:
"21"
}
%td
{
align:
"left"
,
style:
"padding: 20px 0 0;"
}
%h2
{
style:
"color:#646464 !important; font-weight: bold; margin: 0; padding: 0; line-height: 26px; font-size: 18px; font-family: Helvetica, Arial, sans-serif; "
}
=
"Issue #
#{
@issue
.
id
}
"
=
link_to_gfm
truncate
(
@issue
.
title
,
length:
45
),
project_issue_url
(
@issue
.
project
,
@issue
),
title:
@issue
.
title
%br
spec/mailers/notify_spec.rb
浏览文件 @
ed954eba
...
...
@@ -91,6 +91,29 @@ describe Notify do
should
have_body_text
/
#{
project_issue_path
project
,
issue
}
/
end
end
describe
'status changed'
do
let
(
:current_user
)
{
Factory
.
create
:user
,
email:
"current@email.com"
}
let
(
:status
)
{
'closed'
}
subject
{
Notify
.
issue_status_changed_email
(
recipient
.
id
,
issue
.
id
,
status
,
current_user
)
}
it
'has the correct subject'
do
should
have_subject
/changed issue #
#{
issue
.
id
}
\|
#{
issue
.
title
}
/i
end
it
'contains the new status'
do
should
have_body_text
/
#{
status
}
/i
end
it
'contains the user name'
do
should
have_body_text
/
#{
current_user
.
name
}
/i
end
it
'contains a link to the issue'
do
should
have_body_text
/
#{
project_issue_path
project
,
issue
}
/
end
end
end
context
'for merge requests'
do
...
...
spec/observers/issue_observer_spec.rb
浏览文件 @
ed954eba
...
...
@@ -3,7 +3,8 @@ require 'spec_helper'
describe
IssueObserver
do
let
(
:some_user
)
{
double
(
:user
,
id:
1
)
}
let
(
:assignee
)
{
double
(
:user
,
id:
2
)
}
let
(
:issue
)
{
double
(
:issue
,
id:
42
,
assignee:
assignee
)
}
let
(
:author
)
{
double
(
:user
,
id:
3
)
}
let
(
:issue
)
{
double
(
:issue
,
id:
42
,
assignee:
assignee
,
author:
author
)
}
before
(
:each
)
{
subject
.
stub
(
:current_user
).
and_return
(
some_user
)
}
...
...
@@ -67,36 +68,90 @@ describe IssueObserver do
end
end
context
'a status "closed"
note
'
do
it
'is created if the issue is being closed'
do
context
'a status "closed"'
do
it
'
note
is created if the issue is being closed'
do
issue
.
should_receive
(
:is_being_closed?
).
and_return
(
true
)
Note
.
should_receive
(
:create_status_change_note
).
with
(
issue
,
some_user
,
'closed'
)
subject
.
after_update
(
issue
)
end
it
'is not created if the issue is not being closed'
do
it
'
note
is not created if the issue is not being closed'
do
issue
.
should_receive
(
:is_being_closed?
).
and_return
(
false
)
Note
.
should_not_receive
(
:create_status_change_note
).
with
(
issue
,
some_user
,
'closed'
)
subject
.
after_update
(
issue
)
end
it
'notification is delivered if the issue being closed'
do
issue
.
stub
(
:is_being_closed?
).
and_return
(
true
)
Notify
.
should_receive
(
:issue_status_changed_email
).
twice
Note
.
should_receive
(
:create_status_change_note
).
with
(
issue
,
some_user
,
'closed'
)
subject
.
after_update
(
issue
)
end
it
'notification is not delivered if the issue not being closed'
do
issue
.
stub
(
:is_being_closed?
).
and_return
(
false
)
Notify
.
should_not_receive
(
:issue_status_changed_email
)
Note
.
should_not_receive
(
:create_status_change_note
).
with
(
issue
,
some_user
,
'closed'
)
subject
.
after_update
(
issue
)
end
it
'notification is delivered only to author if the issue being closed'
do
issue_without_assignee
=
double
(
:issue
,
id:
42
,
author:
author
,
assignee:
nil
)
issue_without_assignee
.
stub
(
:is_being_reassigned?
).
and_return
(
false
)
issue_without_assignee
.
stub
(
:is_being_closed?
).
and_return
(
true
)
issue_without_assignee
.
stub
(
:is_being_reopened?
).
and_return
(
false
)
Notify
.
should_receive
(
:issue_status_changed_email
).
once
Note
.
should_receive
(
:create_status_change_note
).
with
(
issue_without_assignee
,
some_user
,
'closed'
)
subject
.
after_update
(
issue_without_assignee
)
end
end
context
'a status "reopened"
note
'
do
it
'is created if the issue is being reopened'
do
context
'a status "reopened"'
do
it
'
note
is created if the issue is being reopened'
do
issue
.
should_receive
(
:is_being_reopened?
).
and_return
(
true
)
Note
.
should_receive
(
:create_status_change_note
).
with
(
issue
,
some_user
,
'reopened'
)
subject
.
after_update
(
issue
)
end
it
'is not created if the issue is not being reopened'
do
it
'
note
is not created if the issue is not being reopened'
do
issue
.
should_receive
(
:is_being_reopened?
).
and_return
(
false
)
Note
.
should_not_receive
(
:create_status_change_note
).
with
(
issue
,
some_user
,
'reopened'
)
subject
.
after_update
(
issue
)
end
it
'notification is delivered if the issue being reopened'
do
issue
.
stub
(
:is_being_reopened?
).
and_return
(
true
)
Notify
.
should_receive
(
:issue_status_changed_email
).
twice
Note
.
should_receive
(
:create_status_change_note
).
with
(
issue
,
some_user
,
'reopened'
)
subject
.
after_update
(
issue
)
end
it
'notification is not delivered if the issue not being reopened'
do
issue
.
stub
(
:is_being_reopened?
).
and_return
(
false
)
Notify
.
should_not_receive
(
:issue_status_changed_email
)
Note
.
should_not_receive
(
:create_status_change_note
).
with
(
issue
,
some_user
,
'reopened'
)
subject
.
after_update
(
issue
)
end
it
'notification is delivered only to author if the issue being reopened'
do
issue_without_assignee
=
double
(
:issue
,
id:
42
,
author:
author
,
assignee:
nil
)
issue_without_assignee
.
stub
(
:is_being_reassigned?
).
and_return
(
false
)
issue_without_assignee
.
stub
(
:is_being_closed?
).
and_return
(
false
)
issue_without_assignee
.
stub
(
:is_being_reopened?
).
and_return
(
true
)
Notify
.
should_receive
(
:issue_status_changed_email
).
once
Note
.
should_receive
(
:create_status_change_note
).
with
(
issue_without_assignee
,
some_user
,
'reopened'
)
subject
.
after_update
(
issue_without_assignee
)
end
end
end
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录