Commit dd72c5da authored by Jarka Košanová's avatar Jarka Košanová

Merge branch 'cablett-rename-spam-method' into 'master'

Rename 'check_for_spam' to 'invalidate_if_spam'

See merge request gitlab-org/gitlab!25789
parents 2e58867e 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."
......
......@@ -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) }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment