blob: c5d17e0232c2b7843c368d9a633a95cf527b77b9 (
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe SpammableActions::CaptchaCheck::HtmlFormatActionsSupport do
controller(ActionController::Base) do
include SpammableActions::CaptchaCheck::HtmlFormatActionsSupport
def create
with_captcha_check_html_format(spammable: spammable) { render :some_rendered_view }
end
end
let(:spammable) { double(:spammable) }
before do
allow(Gitlab::Recaptcha).to receive(:load_configurations!) { true }
routes.draw { get 'create' => 'anonymous#create' }
allow(controller).to receive(:spammable) { spammable }
expect(spammable).to receive(:render_recaptcha?).at_least(:once) { render_recaptcha }
end
describe '#convert_html_spam_params_to_headers' do
let(:render_recaptcha) { false }
let(:g_recaptcha_response) { 'abc123' }
let(:spam_log_id) { 42 }
let(:params) do
{
'g-recaptcha-response' => g_recaptcha_response,
spam_log_id: spam_log_id
}
end
# NOTE: `:update` has an identical `before_action` behavior to ``:create``, but `before_action` is
# declarative via the ``:only`` attribute, so there's little value in re-testing the behavior.
subject { post :create, params: params }
before do
allow(controller).to receive(:render).with(:some_rendered_view)
end
it 'converts params to headers' do
subject
expect(controller.request.headers['X-GitLab-Captcha-Response']).to eq(g_recaptcha_response)
expect(controller.request.headers['X-GitLab-Spam-Log-Id']).to eq(spam_log_id.to_s)
end
end
describe '#with_captcha_check_html_format' do
subject { post :create }
context 'when spammable.render_recaptcha? is true' do
let(:render_recaptcha) { true }
it 'renders :captcha_check' do
expect(controller).to receive(:render).with(:captcha_check)
subject
end
end
context 'when spammable.render_recaptcha? is false' do
let(:render_recaptcha) { false }
it 'yields to block' do
expect(controller).to receive(:render).with(:some_rendered_view)
subject
end
end
end
end
|