Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add spec for request_headers #42

Merged
merged 6 commits into from
Oct 13, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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