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

response_coercer_middleware_spec.rb « api_guard « api « requests « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 6f3f97fe846d28347e05c926267867df1d227f5b (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
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe API::APIGuard::ResponseCoercerMiddleware do
  using RSpec::Parameterized::TableSyntax

  it 'is loaded' do
    expect(API::API.middleware).to include([:use, described_class])
  end

  describe '#call' do
    let(:app) do
      Class.new(API::API)
    end

    [
      nil, 201, 10.5, "test"
    ].each do |val|
      it 'returns a String body' do
        app.get 'bodytest' do
          status 200
          env['api.format'] = :binary
          body val
        end

        unless val.is_a?(String)
          expect(Gitlab::ErrorTracking).to receive(:track_and_raise_for_dev_exception).with(instance_of(ArgumentError))
        end

        get api('/bodytest')

        expect(response).to have_gitlab_http_status(:ok)
        expect(response.body).to eq(val.to_s)
      end
    end

    [100, 204, 304].each do |status|
      it 'allows nil body' do
        app.get 'statustest' do
          status status
          env['api.format'] = :binary
          body nil
        end

        expect(Gitlab::ErrorTracking).not_to receive(:track_and_raise_for_dev_exception)

        get api('/statustest')

        expect(response.status).to eq(status)
        expect(response.body).to eq('')
      end
    end
  end
end