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

spam_service_spec.rb « services « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 271c17dd8c039b08cdfe4be9bf52edf7255116c9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
require 'spec_helper'

describe SpamService, services: true do
  describe '#check' do
    let(:project) { create(:project, :public) }
    let(:issue)   { create(:issue, project: project) }
    let(:request) { double(:request, env: {}) }

    def check_spam(issue, request)
      described_class.new(issue, request).check
    end

    context 'when indicated as spam by akismet' do
      before { allow(AkismetService).to receive(:new).and_return(double(is_spam?: true)) }

      it 'returns false when request is missing' do
        expect(check_spam(issue, nil)).to be_falsey
      end

      it 'returns false when issue is not public' do
        issue = create(:issue, project: create(:project, :private))

        expect(check_spam(issue, request)).to be_falsey
      end

      it 'returns true' do
        expect(check_spam(issue, request)).to be_truthy
      end

      it 'creates a spam log' do
        expect { check_spam(issue, request) }.to change { SpamLog.count }.from(0).to(1)
      end
    end

    context 'when not indicated as spam by akismet' do
      before { allow(AkismetService).to receive(:new).and_return(double(is_spam?: false)) }

      it 'returns false' do
        expect(check_spam(issue, request)).to be_falsey
      end

      it 'does not create a spam log' do
        expect { check_spam(issue, request) }.not_to change { SpamLog.count }
      end
    end
  end
end