debian-mirror-gitlab/spec/services/spam/spam_params_spec.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

59 lines
1.4 KiB
Ruby
Raw Normal View History

2021-09-30 23:02:18 +05:30
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Spam::SpamParams do
2022-05-07 20:08:51 +05:30
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
2021-09-30 23:02:18 +05:30
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
2022-05-07 20:08:51 +05:30
let(:request) { double(:request, headers: headers, env: env) }
2021-09-30 23:02:18 +05:30
2022-05-07 20:08:51 +05:30
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'
2021-09-30 23:02:18 +05:30
end
end
end