Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
m0_70890014
gitlabhq
提交
46a220ae
G
gitlabhq
项目概览
m0_70890014
/
gitlabhq
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
gitlabhq
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
46a220ae
编写于
1月 04, 2016
作者:
R
Robert Speicher
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add `AbuseReport#notify`
Tell, Don't Ask.
上级
01248d20
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
49 addition
and
58 deletion
+49
-58
app/controllers/abuse_reports_controller.rb
app/controllers/abuse_reports_controller.rb
+1
-3
app/models/abuse_report.rb
app/models/abuse_report.rb
+6
-0
spec/controllers/abuse_reports_controller_spec.rb
spec/controllers/abuse_reports_controller_spec.rb
+25
-55
spec/models/abuse_report_spec.rb
spec/models/abuse_report_spec.rb
+17
-0
未找到文件。
app/controllers/abuse_reports_controller.rb
浏览文件 @
46a220ae
...
...
@@ -9,9 +9,7 @@ class AbuseReportsController < ApplicationController
@abuse_report
.
reporter
=
current_user
if
@abuse_report
.
save
if
current_application_settings
.
admin_notification_email
.
present?
AbuseReportMailer
.
notify
(
@abuse_report
.
id
).
deliver_later
end
@abuse_report
.
notify
message
=
"Thank you for your report. A GitLab administrator will look into it shortly."
redirect_to
@abuse_report
.
user
,
notice:
message
...
...
app/models/abuse_report.rb
浏览文件 @
46a220ae
...
...
@@ -18,4 +18,10 @@ class AbuseReport < ActiveRecord::Base
validates
:user
,
presence:
true
validates
:message
,
presence:
true
validates
:user_id
,
uniqueness:
true
def
notify
return
unless
self
.
persisted?
AbuseReportMailer
.
notify
(
self
.
id
).
deliver_later
end
end
spec/controllers/abuse_reports_controller_spec.rb
浏览文件 @
46a220ae
require
'spec_helper'
describe
AbuseReportsController
do
let
(
:reporter
)
{
create
(
:user
)
}
let
(
:user
)
{
create
(
:user
)
}
let
(
:message
)
{
"This user is a spammer"
}
let
(
:reporter
)
{
create
(
:user
)
}
let
(
:user
)
{
create
(
:user
)
}
let
(
:attrs
)
do
attributes_for
(
:abuse_report
)
do
|
hash
|
hash
[
:user_id
]
=
user
.
id
end
end
before
do
sign_in
(
reporter
)
end
describe
"POST create"
do
context
"with admin notification email set"
do
let
(
:admin_email
)
{
"admin@example.com"
}
before
(
:each
)
do
stub_application_setting
(
admin_notification_email:
admin_email
)
describe
'POST create'
do
context
'with valid attributes'
do
it
'saves the abuse report'
do
expect
do
post
:create
,
abuse_report:
attrs
end
.
to
change
{
AbuseReport
.
count
}.
by
(
1
)
end
it
"sends a notification email"
do
perform_enqueued_jobs
do
post
:create
,
abuse_report:
{
user_id:
user
.
id
,
message:
message
}
email
=
ActionMailer
::
Base
.
deliveries
.
last
it
'calls notify'
do
expect_any_instance_of
(
AbuseReport
).
to
receive
(
:notify
)
expect
(
email
.
to
).
to
eq
([
admin_email
])
expect
(
email
.
subject
).
to
include
(
user
.
username
)
expect
(
email
.
text_part
.
body
).
to
include
(
message
)
end
post
:create
,
abuse_report:
attrs
end
it
"saves the abuse report"
do
perform_enqueued_jobs
do
expect
do
post
:create
,
abuse_report:
{
user_id:
user
.
id
,
message:
message
}
end
.
to
change
{
AbuseReport
.
count
}.
by
(
1
)
end
end
end
it
'redirects back to the reported user'
do
post
:create
,
abuse_report:
attrs
context
"without admin notification email set"
do
before
(
:each
)
do
stub_application_setting
(
admin_notification_email:
nil
)
expect
(
response
).
to
redirect_to
user
end
end
it
"does not send a notification email"
do
expect
do
post
:create
,
abuse_report:
{
user_id:
user
.
id
,
message:
message
}
end
.
not_to
change
{
ActionMailer
::
Base
.
deliveries
.
count
}
end
context
'with invalid attributes'
do
it
'renders new'
do
attrs
.
delete
(
:user_id
)
post
:create
,
abuse_report:
attrs
it
"saves the abuse report"
do
expect
do
post
:create
,
abuse_report:
{
user_id:
user
.
id
,
message:
message
}
end
.
to
change
{
AbuseReport
.
count
}.
by
(
1
)
expect
(
response
).
to
render_template
(
:new
)
end
end
end
end
spec/models/abuse_report_spec.rb
浏览文件 @
46a220ae
...
...
@@ -28,4 +28,21 @@ RSpec.describe AbuseReport, type: :model do
it
{
is_expected
.
to
validate_presence_of
(
:message
)
}
it
{
is_expected
.
to
validate_uniqueness_of
(
:user_id
)
}
end
describe
'#notify'
do
it
'delivers'
do
expect
(
AbuseReportMailer
).
to
receive
(
:notify
).
with
(
subject
.
id
).
and_return
(
spy
)
subject
.
notify
end
it
'returns early when not persisted'
do
report
=
build
(
:abuse_report
)
expect
(
AbuseReportMailer
).
not_to
receive
(
:notify
)
report
.
notify
end
end
end
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录