File: request_headers_spec.rb

package info (click to toggle)
ruby-grape-logging 1.8.4-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 244 kB
  • sloc: ruby: 845; makefile: 6; sh: 3
file content (40 lines) | stat: -rw-r--r-- 1,131 bytes parent folder | download | duplicates (2)
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
require 'spec_helper'
require 'ostruct'

describe GrapeLogging::Loggers::RequestHeaders do
  let(:mock_request) do
    OpenStruct.new(env: {HTTP_REFERER: 'http://example.com', HTTP_ACCEPT: 'text/plain'})
  end

  let(:mock_request_with_unhandle_headers) do
    OpenStruct.new(env: {
      HTTP_REFERER: 'http://example.com',
      "PATH_INFO"=>"/api/v1/users"
    })
  end

  let(:mock_request_with_long_headers) do
    OpenStruct.new(env: {
      HTTP_REFERER: 'http://example.com',
      HTTP_USER_AGENT: "Mozilla/5.0"
    })
  end

  it 'strips HTTP_ from the parameter' do
    expect(subject.parameters(mock_request, nil)).to eq({
      headers: {'Referer' => 'http://example.com', 'Accept' => 'text/plain'}
    })
  end

  it 'only handle things which start with HTTP_' do
    expect(subject.parameters(mock_request_with_unhandle_headers, nil)).to eq({
      headers: {'Referer' => 'http://example.com' }
    })
  end

  it 'substitutes _ with -' do
    expect(subject.parameters(mock_request_with_long_headers, nil)).to eq({
      headers: {'Referer' => 'http://example.com', 'User-Agent' => 'Mozilla/5.0' }
    })
  end
end