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
1
Merge Requests
1
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
nexedi
gitlab-ce
Commits
fb368c29
Commit
fb368c29
authored
Feb 06, 2020
by
charlieablett
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add HamService unit tests
parent
9da4a6d5
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
56 additions
and
0 deletions
+56
-0
spec/services/spam/ham_service_spec.rb
spec/services/spam/ham_service_spec.rb
+56
-0
No files found.
spec/services/spam/ham_service_spec.rb
0 → 100644
View file @
fb368c29
# frozen_string_literal: true
require
'spec_helper'
describe
Spam
::
HamService
do
let_it_be
(
:user
)
{
create
(
:user
)
}
let!
(
:spam_log
)
{
create
(
:spam_log
,
user:
user
,
submitted_as_ham:
false
)
}
let
(
:fake_akismet_service
)
{
double
(
:akismet_service
)
}
subject
{
described_class
.
new
(
spam_log
)
}
before
do
allow
(
Spam
::
AkismetService
).
to
receive
(
:new
).
and_return
fake_akismet_service
end
describe
'#mark_as_ham!'
do
context
'AkismetService returns false (Akismet cannot be reached, etc)'
do
before
do
allow
(
fake_akismet_service
).
to
receive
(
:submit_ham
).
and_return
false
end
it
'returns false'
do
expect
(
subject
.
mark_as_ham!
).
to
be_falsey
end
it
'does not update the record'
do
expect
{
subject
.
mark_as_ham!
}.
not_to
change
{
spam_log
.
submitted_as_ham
}
end
context
'if spam log record has already been marked as spam'
do
before
do
spam_log
.
update_attribute
(
:submitted_as_ham
,
true
)
end
it
'does not update the record'
do
expect
{
subject
.
mark_as_ham!
}.
not_to
change
{
spam_log
.
submitted_as_ham
}
end
end
end
context
'Akismet ham submission is successful'
do
before
do
spam_log
.
update_attribute
(
:submitted_as_ham
,
false
)
allow
(
fake_akismet_service
).
to
receive
(
:submit_ham
).
and_return
true
end
it
'returns true'
do
expect
(
subject
.
mark_as_ham!
).
to
be_truthy
end
it
'updates the record'
do
expect
{
subject
.
mark_as_ham!
}.
to
change
{
spam_log
.
submitted_as_ham
}.
from
(
false
).
to
(
true
)
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