diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-01-29 00:09:17 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-01-29 00:09:17 +0000 |
commit | 5fe1957d2bd0c3f969f357b17f4b46f1968d8810 (patch) | |
tree | c3819660f860c4fc87d9ac9f22ad08894bb143fb /spec/models/concerns/spammable_spec.rb | |
parent | c6c346e8c7f0865f0016a458511e9fabfc8b9c1a (diff) | |
download | gitlab-ce-5fe1957d2bd0c3f969f357b17f4b46f1968d8810.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/models/concerns/spammable_spec.rb')
-rw-r--r-- | spec/models/concerns/spammable_spec.rb | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/spec/models/concerns/spammable_spec.rb b/spec/models/concerns/spammable_spec.rb index d4fcb2e99eb..3c5f3b2d2ad 100644 --- a/spec/models/concerns/spammable_spec.rb +++ b/spec/models/concerns/spammable_spec.rb @@ -120,6 +120,61 @@ RSpec.describe Spammable do end end + describe '#render_recaptcha?' do + before do + allow(Gitlab::Recaptcha).to receive(:enabled?) { recaptcha_enabled } + end + + context 'when recaptcha is not enabled' do + let(:recaptcha_enabled) { false } + + it 'returns false' do + expect(issue.render_recaptcha?).to eq(false) + end + end + + context 'when recaptcha is enabled' do + let(:recaptcha_enabled) { true } + + context 'when there are two or more errors' do + before do + issue.errors.add(:base, 'a spam error') + issue.errors.add(:base, 'some other error') + end + + it 'returns false' do + expect(issue.render_recaptcha?).to eq(false) + end + end + + context 'when there are less than two errors' do + before do + issue.errors.add(:base, 'a spam error') + end + + context 'when spammable does not need recaptcha' do + before do + issue.needs_recaptcha = false + end + + it 'returns false' do + expect(issue.render_recaptcha?).to eq(false) + end + end + + context 'when spammable needs recaptcha' do + before do + issue.needs_recaptcha! + end + + it 'returns false' do + expect(issue.render_recaptcha?).to eq(true) + end + end + end + end + end + describe '#clear_spam_flags!' do it 'clears spam and recaptcha flags' do issue.spam = true |