-
Notifications
You must be signed in to change notification settings - Fork 365
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Removes utf-8 from JSON requests because it's redundant
JSON requests should use UTF-8 by default according to http://www.ietf.org/rfc/rfc4627.txt, so we will remove `charset=utf-8` when we find it to avoid redundancy. In the process, I moved code that was only used by APIB into the APIB classes, such as exposing `content_type` to the templates. If I changed the `content-type` for all templates it would break unrelated things. Connects to #235.
- Loading branch information
Showing
4 changed files
with
166 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
# -*- coding: utf-8 -*- | ||
require 'spec_helper' | ||
|
||
describe RspecApiDocumentation::Views::ApiBlueprintExample do | ||
let(:metadata) { { :resource_name => "Orders" } } | ||
let(:group) { RSpec::Core::ExampleGroup.describe("Orders", metadata) } | ||
let(:rspec_example) { group.example("Ordering a cup of coffee") {} } | ||
let(:rad_example) do | ||
RspecApiDocumentation::Example.new(rspec_example, configuration) | ||
end | ||
let(:configuration) { RspecApiDocumentation::Configuration.new } | ||
let(:html_example) { described_class.new(rad_example, configuration) } | ||
|
||
let(:content_type) { "application/json; charset=utf-8" } | ||
let(:requests) do | ||
[{ | ||
request_body: "{}", | ||
request_headers: { | ||
"Content-Type" => content_type, | ||
"Another" => "header; charset=utf-8" | ||
}, | ||
request_content_type: "", | ||
response_body: "{}", | ||
response_headers: { | ||
"Content-Type" => content_type, | ||
"Another" => "header; charset=utf-8" | ||
}, | ||
response_content_type: "" | ||
}] | ||
end | ||
|
||
before do | ||
rspec_example.metadata[:requests] = requests | ||
end | ||
|
||
subject(:view) { described_class.new(rad_example, configuration) } | ||
|
||
describe '#requests' do | ||
describe 'request_content_type' do | ||
subject { view.requests[0][:request_content_type] } | ||
|
||
context 'when charset=utf-8 is present' do | ||
it "just strips that because it's the default for json" do | ||
expect(subject).to eq "application/json" | ||
end | ||
end | ||
|
||
context 'when charset=utf-16 is present' do | ||
let(:content_type) { "application/json; charset=utf-16" } | ||
|
||
it "keeps that because it's NOT the default for json" do | ||
expect(subject).to eq "application/json; charset=utf-16" | ||
end | ||
end | ||
end | ||
|
||
describe 'request_headers_text' do | ||
subject { view.requests[0][:request_headers_text] } | ||
|
||
context 'when charset=utf-8 is present' do | ||
it "just strips that because it's the default for json" do | ||
expect(subject).to eq "Content-Type: application/json\n Another: header; charset=utf-8" | ||
end | ||
end | ||
|
||
context 'when charset=utf-16 is present' do | ||
let(:content_type) { "application/json; charset=utf-16" } | ||
|
||
it "keeps that because it's NOT the default for json" do | ||
expect(subject).to eq "Content-Type: application/json; charset=utf-16\n Another: header; charset=utf-8" | ||
end | ||
end | ||
end | ||
|
||
describe 'response_content_type' do | ||
subject { view.requests[0][:response_content_type] } | ||
|
||
context 'when charset=utf-8 is present' do | ||
it "just strips that because it's the default for json" do | ||
expect(subject).to eq "application/json" | ||
end | ||
end | ||
|
||
context 'when charset=utf-16 is present' do | ||
let(:content_type) { "application/json; charset=utf-16" } | ||
|
||
it "keeps that because it's NOT the default for json" do | ||
expect(subject).to eq "application/json; charset=utf-16" | ||
end | ||
end | ||
end | ||
|
||
describe 'response_headers_text' do | ||
subject { view.requests[0][:response_headers_text] } | ||
|
||
context 'when charset=utf-8 is present' do | ||
it "just strips that because it's the default for json" do | ||
expect(subject).to eq "Content-Type: application/json\n Another: header; charset=utf-8" | ||
end | ||
end | ||
|
||
context 'when charset=utf-16 is present' do | ||
let(:content_type) { "application/json; charset=utf-16" } | ||
|
||
it "keeps that because it's NOT the default for json" do | ||
expect(subject).to eq "Content-Type: application/json; charset=utf-16\n Another: header; charset=utf-8" | ||
end | ||
end | ||
end | ||
end | ||
end |