Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-02-07 06:08:59 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2020-02-07 06:08:59 +0300
commitddd268b03b6f35c68e5a89606dbfd516f72846fd (patch)
treef2d7df84d421bc6deff26daa502687b0164b59be /spec/services/spam
parent6168721025dd8e98caeb2bf6844273e6690eaf69 (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/services/spam')
-rw-r--r--spec/services/spam/ham_service_spec.rb56
1 files changed, 56 insertions, 0 deletions
diff --git a/spec/services/spam/ham_service_spec.rb b/spec/services/spam/ham_service_spec.rb
new file mode 100644
index 00000000000..9e60078edfe
--- /dev/null
+++ b/spec/services/spam/ham_service_spec.rb
@@ -0,0 +1,56 @@
+# 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