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

akismet_helper_spec.rb « gitlab « lib « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 53f5d6c5c80dd697d024500fe115e3198800cbff (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
require 'spec_helper'

describe Gitlab::AkismetHelper, type: :helper do
  let(:project) { create(:project) }
  let(:user) { create(:user) }

  before do
    allow(Gitlab.config.gitlab).to receive(:url).and_return(Settings.send(:build_gitlab_url))
    current_application_settings.akismet_enabled = true
    current_application_settings.akismet_api_key = '12345'
  end

  describe '#check_for_spam?' do
    it 'returns true for non-member' do
      expect(helper.check_for_spam?(project, user)).to eq(true)
    end

    it 'returns false for member' do
      project.team << [user, :guest]
      expect(helper.check_for_spam?(project, user)).to eq(false)
    end
  end

  describe '#is_spam?' do
    it 'returns true for spam' do
      environment = {
        'action_dispatch.remote_ip' => '127.0.0.1',
        'HTTP_USER_AGENT' => 'Test User Agent'
      }

      allow_any_instance_of(::Akismet::Client).to receive(:check).and_return([true, true])
      expect(helper.is_spam?(environment, user, 'Is this spam?')).to eq(true)
    end
  end
end