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
96a817e8
Commit
96a817e8
authored
Feb 24, 2020
by
charlieablett
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Rename 'check_for_spam' to 'invalidate_if_spam'
parent
9338931a
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
42 additions
and
2 deletions
+42
-2
app/models/concerns/spammable.rb
app/models/concerns/spammable.rb
+2
-2
spec/models/concerns/spammable_spec.rb
spec/models/concerns/spammable_spec.rb
+40
-0
No files found.
app/models/concerns/spammable.rb
View file @
96a817e8
...
...
@@ -16,7 +16,7 @@ module Spammable
attr_accessor
:spam_log
alias_method
:spam?
,
:spam
after_validation
:
check_for
_spam
,
on:
[
:create
,
:update
]
after_validation
:
invalidate_if
_spam
,
on:
[
:create
,
:update
]
cattr_accessor
:spammable_attrs
,
instance_accessor:
false
do
[]
...
...
@@ -37,7 +37,7 @@ module Spammable
end
end
def
check_for
_spam
def
invalidate_if
_spam
error_msg
=
if
Gitlab
::
Recaptcha
.
enabled?
"Your
#{
spammable_entity_type
}
has been recognized as spam. "
\
"Please, change the content or solve the reCAPTCHA to proceed."
...
...
spec/models/concerns/spammable_spec.rb
View file @
96a817e8
...
...
@@ -36,6 +36,46 @@ describe Spammable do
end
end
describe
'#invalidate_if_spam'
do
using
RSpec
::
Parameterized
::
TableSyntax
context
'when the model is spam'
do
where
(
:recaptcha_enabled
,
:error
)
do
true
|
/solve the reCAPTCHA to proceed/
false
|
/has been discarded/
end
with_them
do
subject
{
invalidate_if_spam
(
true
,
recaptcha_enabled
)
}
it
'has an error related to spam on the model'
do
expect
(
subject
.
errors
.
messages
[
:base
]).
to
match_array
error
end
end
end
context
'when the model is not spam'
do
[
true
,
false
].
each
do
|
enabled
|
let
(
:recaptcha_enabled
)
{
enabled
}
subject
{
invalidate_if_spam
(
false
,
recaptcha_enabled
)
}
it
'returns no error'
do
expect
(
subject
.
errors
.
messages
[
:base
]).
to
be_empty
end
end
end
def
invalidate_if_spam
(
is_spam
,
recaptcha_enabled
)
stub_application_setting
(
recaptcha_enabled:
recaptcha_enabled
)
issue
.
tap
do
|
i
|
i
.
spam
=
is_spam
i
.
invalidate_if_spam
end
end
end
describe
'#submittable_as_spam_by?'
do
let
(
:admin
)
{
build
(
:admin
)
}
let
(
:user
)
{
build
(
:user
)
}
...
...
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