Commit cdbca3a8 by andrew morton

Use root consumes/produces if not specified in operation

parent d2c108e3
...@@ -204,11 +204,13 @@ module RSpec ...@@ -204,11 +204,13 @@ module RSpec
end end
def resolve_produces metadata def resolve_produces metadata
metadata[:swagger_operation][:produces] document = resolve_document metadata
metadata[:swagger_operation][:produces] || document[:produces]
end end
def resolve_consumes metadata def resolve_consumes metadata
metadata[:swagger_operation][:consumes] document = resolve_document metadata
metadata[:swagger_operation][:consumes] || document[:consumes]
end end
def resolve_headers metadata def resolve_headers metadata
......
...@@ -235,19 +235,38 @@ RSpec.describe RSpec::Swagger::Helpers::Resolver do ...@@ -235,19 +235,38 @@ RSpec.describe RSpec::Swagger::Helpers::Resolver do
end end
describe "#resolve_headers", :swagger_object do describe "#resolve_headers", :swagger_object do
context "with consumes set" do context "with consumes/produces in the operation" do
let(:metadata) { {swagger_operation: {consumes: ['application/json']}} } let(:metadata) do
{swagger_operation: {consumes: ['application/json'], produces: ['application/xml']}}
end
before do
allow(self).to receive(:resolve_document) { {} }
end
it "sets the Content-Type header" do it "sets the Content-Type header" do
expect(resolve_headers(metadata)).to include('CONTENT_TYPE' => 'application/json') expect(resolve_headers(metadata)).to include('CONTENT_TYPE' => 'application/json')
end end
it "sets the Accepts header" do
expect(resolve_headers(metadata)).to include('HTTP_ACCEPT' => 'application/xml')
end
end end
context "with produces set" do context "with consumes/produces in the document" do
let(:metadata) { {swagger_operation: {produces: ['application/xml']}} } let(:metadata) { {swagger_document: 'test.json', swagger_operation: {}} }
before do
allow(self).to receive(:resolve_document) do
{ consumes: ['text/plain; charset=utf-8'],
produces: ['application/vnd.github.v3.raw+json']}
end
end
it "sets the Content-Type header" do
expect(resolve_headers(metadata)).to include('CONTENT_TYPE' => 'text/plain; charset=utf-8')
end
it "sets the Accepts header" do it "sets the Accepts header" do
expect(resolve_headers(metadata)).to include('HTTP_ACCEPT' => 'application/xml') expect(resolve_headers(metadata)).to include('HTTP_ACCEPT' => 'application/vnd.github.v3.raw+json')
end end
end end
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment