Skip to content

Commit

Permalink
add spec for request_headers (aserafin#42)
Browse files Browse the repository at this point in the history
* log for request headers

* add specification

* fix spec

* optimize readme

* add spec for request_headers
  • Loading branch information
liukgg authored and aserafin committed Oct 13, 2017
1 parent 54f3fa8 commit 83117bc
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
1 change: 0 additions & 1 deletion lib/grape_logging/loggers/request_headers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ def parameters(request, _)
{ headers: headers }
end


end
end
end
26 changes: 26 additions & 0 deletions spec/lib/grape_logging/loggers/request_headers_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,35 @@
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

0 comments on commit 83117bc

Please sign in to comment.