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

spam_params_spec.rb « spam « services « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 7e74641c0fa6f6029d9d58d21a66bb3a41ff52cc (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
48
49
50
51
52
53
54
55
56
57
58
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Spam::SpamParams do
  shared_examples 'constructs from a request' do
    it 'constructs from a request' do
      expected = ::Spam::SpamParams.new(
        captcha_response: captcha_response,
        spam_log_id: spam_log_id,
        ip_address: ip_address,
        user_agent: user_agent,
        referer: referer
      )
      expect(described_class.new_from_request(request: request)).to eq(expected)
    end
  end

  describe '.new_from_request' do
    let(:captcha_response) { 'abc123' }
    let(:spam_log_id) { 42 }
    let(:ip_address) { '0.0.0.0' }
    let(:user_agent) { 'Lynx' }
    let(:referer) { 'http://localhost' }

    let(:env) do
      {
        'action_dispatch.remote_ip' => ip_address,
        'HTTP_USER_AGENT' => user_agent,
        'HTTP_REFERER' => referer
      }
    end

    let(:request) { double(:request, headers: headers, env: env) }

    context 'with a normal Rails request' do
      let(:headers) do
        {
          'X-GitLab-Captcha-Response' => captcha_response,
          'X-GitLab-Spam-Log-Id' => spam_log_id
        }
      end

      it_behaves_like 'constructs from a request'
    end

    context 'with a grape request' do
      let(:headers) do
        {
          'X-Gitlab-Captcha-Response' => captcha_response,
          'X-Gitlab-Spam-Log-Id' => spam_log_id
        }
      end

      it_behaves_like 'constructs from a request'
    end
  end
end