Skip to content

Commit 8021c09

Browse files
committed
Merge pull request #240 from jeffutter/fix-content-type-header
Fix Content-Type Header
2 parents b3b0eba + bc101e5 commit 8021c09

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

Diff for: lib/rspec_api_documentation/headers.rb

+1-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ def env_to_headers(env)
77
env.each do |key, value|
88
# HTTP_ACCEPT_CHARSET => Accept-Charset
99
if key =~ /^(HTTP_|CONTENT_TYPE)/
10-
header = key.gsub(/^HTTP_/, '').titleize.split.join("-")
11-
header.concat('-Id') if key.scan(/_ID\Z/).any?
10+
header = key.gsub(/^HTTP_/, '').split('_').map{|s| s.titleize}.join("-")
1211
headers[header] = value
1312
end
1413
end

Diff for: spec/headers_spec.rb

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
require 'spec_helper'
2+
3+
class FakeHeaderable
4+
include RspecApiDocumentation::Headers
5+
6+
def public_env_to_headers(env)
7+
env_to_headers(env)
8+
end
9+
end
10+
11+
describe RspecApiDocumentation::Headers do
12+
let(:example) { FakeHeaderable.new }
13+
14+
describe '#env_to_headers' do
15+
subject { example.public_env_to_headers(env) }
16+
17+
context 'When the env contains "CONTENT_TYPE"' do
18+
let(:env) { { "CONTENT_TYPE" => 'multipart/form-data' } }
19+
20+
it 'converts the header to "Content-Type"' do
21+
expect(subject['Content-Type']).to eq 'multipart/form-data'
22+
end
23+
end
24+
end
25+
26+
end

0 commit comments

Comments
 (0)