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
Kazuhiko Shiozaki
gitlab-ce
Commits
46a220ae
Commit
46a220ae
authored
Jan 04, 2016
by
Robert Speicher
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add `AbuseReport#notify`
Tell, Don't Ask.
parent
01248d20
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
49 additions
and
58 deletions
+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
No files found.
app/controllers/abuse_reports_controller.rb
View file @
46a220ae
...
@@ -9,9 +9,7 @@ class AbuseReportsController < ApplicationController
...
@@ -9,9 +9,7 @@ class AbuseReportsController < ApplicationController
@abuse_report
.
reporter
=
current_user
@abuse_report
.
reporter
=
current_user
if
@abuse_report
.
save
if
@abuse_report
.
save
if
current_application_settings
.
admin_notification_email
.
present?
@abuse_report
.
notify
AbuseReportMailer
.
notify
(
@abuse_report
.
id
).
deliver_later
end
message
=
"Thank you for your report. A GitLab administrator will look into it shortly."
message
=
"Thank you for your report. A GitLab administrator will look into it shortly."
redirect_to
@abuse_report
.
user
,
notice:
message
redirect_to
@abuse_report
.
user
,
notice:
message
...
...
app/models/abuse_report.rb
View file @
46a220ae
...
@@ -18,4 +18,10 @@ class AbuseReport < ActiveRecord::Base
...
@@ -18,4 +18,10 @@ class AbuseReport < ActiveRecord::Base
validates
:user
,
presence:
true
validates
:user
,
presence:
true
validates
:message
,
presence:
true
validates
:message
,
presence:
true
validates
:user_id
,
uniqueness:
true
validates
:user_id
,
uniqueness:
true
def
notify
return
unless
self
.
persisted?
AbuseReportMailer
.
notify
(
self
.
id
).
deliver_later
end
end
end
spec/controllers/abuse_reports_controller_spec.rb
View file @
46a220ae
...
@@ -3,74 +3,44 @@ require 'spec_helper'
...
@@ -3,74 +3,44 @@ require 'spec_helper'
describe
AbuseReportsController
do
describe
AbuseReportsController
do
let
(
:reporter
)
{
create
(
:user
)
}
let
(
:reporter
)
{
create
(
:user
)
}
let
(
:user
)
{
create
(
:user
)
}
let
(
:user
)
{
create
(
:user
)
}
let
(
:message
)
{
"This user is a spammer"
}
let
(
:attrs
)
do
attributes_for
(
:abuse_report
)
do
|
hash
|
hash
[
:user_id
]
=
user
.
id
end
end
before
do
before
do
sign_in
(
reporter
)
sign_in
(
reporter
)
end
end
describe
"POST create"
do
describe
'POST create'
do
context
"with admin notification email set"
do
context
'with valid attributes'
do
let
(
:admin_email
)
{
"admin@example.com"
}
it
'saves the abuse report'
do
expect
do
before
(
:each
)
do
post
:create
,
abuse_report:
attrs
stub_application_setting
(
admin_notification_email:
admin_email
)
end
.
to
change
{
AbuseReport
.
count
}.
by
(
1
)
end
end
it
"sends a notification email"
do
it
'calls notify'
do
perform_enqueued_jobs
do
expect_any_instance_of
(
AbuseReport
).
to
receive
(
:notify
)
post
:create
,
abuse_report:
{
user_id:
user
.
id
,
message:
message
}
email
=
ActionMailer
::
Base
.
deliveries
.
last
post
:create
,
abuse_report:
attrs
expect
(
email
.
to
).
to
eq
([
admin_email
])
expect
(
email
.
subject
).
to
include
(
user
.
username
)
expect
(
email
.
text_part
.
body
).
to
include
(
message
)
end
end
end
it
"saves the abuse report"
do
it
'redirects back to the reported user'
do
perform_enqueued_jobs
do
post
:create
,
abuse_report:
attrs
expect
do
post
:create
,
abuse_report:
{
user_id:
user
.
id
,
message:
message
}
end
.
to
change
{
AbuseReport
.
count
}.
by
(
1
)
end
end
end
context
"without admin notification email set"
do
expect
(
response
).
to
redirect_to
user
before
(
:each
)
do
stub_application_setting
(
admin_notification_email:
nil
)
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
end
it
"saves the abuse report"
do
context
'with invalid attributes'
do
expect
do
it
'renders new'
do
post
:create
,
attrs
.
delete
(
:user_id
)
abuse_report:
{
post
:create
,
abuse_report:
attrs
user_id:
user
.
id
,
message:
message
expect
(
response
).
to
render_template
(
:new
)
}
end
.
to
change
{
AbuseReport
.
count
}.
by
(
1
)
end
end
end
end
end
end
end
end
spec/models/abuse_report_spec.rb
View file @
46a220ae
...
@@ -28,4 +28,21 @@ RSpec.describe AbuseReport, type: :model do
...
@@ -28,4 +28,21 @@ RSpec.describe AbuseReport, type: :model do
it
{
is_expected
.
to
validate_presence_of
(
:message
)
}
it
{
is_expected
.
to
validate_presence_of
(
:message
)
}
it
{
is_expected
.
to
validate_uniqueness_of
(
:user_id
)
}
it
{
is_expected
.
to
validate_uniqueness_of
(
:user_id
)
}
end
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
end
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