-
Notifications
You must be signed in to change notification settings - Fork 463
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Support headers in responses * Reorder methods ---------
- Loading branch information
1 parent
1ea8d7a
commit 41a6c5a
Showing
7 changed files
with
209 additions
and
10 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
62 changes: 62 additions & 0 deletions
62
spec/lib/apipie/generator/swagger/method_description/response_service_spec.rb
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,62 @@ | ||
require 'spec_helper' | ||
|
||
describe Apipie::Generator::Swagger::MethodDescription::ResponseService do | ||
let(:http_method) { nil } | ||
let(:language) { :en } | ||
let(:dsl_data) { ActionController::Base.send(:_apipie_dsl_data_init) } | ||
|
||
let(:method_description) do | ||
Apipie::Generator::Swagger::MethodDescription::Decorator.new( | ||
Apipie::MethodDescription.new( | ||
'create', | ||
Apipie::ResourceDescription.new(ApplicationController, 'pets'), | ||
dsl_data | ||
) | ||
) | ||
end | ||
|
||
let(:returns) { [] } | ||
|
||
let(:service) do | ||
described_class.new( | ||
method_description, | ||
http_method: http_method, | ||
language: language | ||
) | ||
end | ||
|
||
describe '#call' do | ||
describe 'headers' do | ||
subject(:headers) { service.call[status_code][:headers] } | ||
|
||
let(:status_code) { 200 } | ||
|
||
it { is_expected.to be_blank } | ||
|
||
context 'when headers exists' do | ||
let(:dsl_data) { super().merge({ returns: returns }) } | ||
let(:returns) { { status_code => [{}, nil, returns_dsl, nil] } } | ||
|
||
let(:returns_dsl) do | ||
proc do | ||
header 'link', String, 'Relative links' | ||
header 'Current-Page', Integer, 'The current page' | ||
end | ||
end | ||
|
||
it 'returns the correct format headers' do | ||
expect(headers).to eq({ | ||
'link' => { | ||
description: 'Relative links', | ||
type: 'string' | ||
}, | ||
'Current-Page' => { | ||
description: 'The current page', | ||
type: 'integer' | ||
} | ||
}) | ||
end | ||
end | ||
end | ||
end | ||
end |
22 changes: 22 additions & 0 deletions
22
spec/lib/apipie/response_description/response_object_spec.rb
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,22 @@ | ||
require 'spec_helper' | ||
|
||
describe Apipie::ResponseDescription::ResponseObject do | ||
describe '#header' do | ||
let(:response_object) { described_class.new(nil, nil, nil, nil) } | ||
let(:name) { 'Current-Page' } | ||
let(:description) { 'The current page in the pagination' } | ||
|
||
before { response_object.header(name, String, description) } | ||
|
||
it 'adds it to the headers' do | ||
expect(response_object.headers).to( | ||
contain_exactly({ | ||
name: name, | ||
description: description, | ||
validator: 'string', | ||
options: {} | ||
}) | ||
) | ||
end | ||
end | ||
end |
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,56 @@ | ||
require 'spec_helper' | ||
|
||
describe Apipie::ResponseDescription do | ||
let(:resource_description) do | ||
Apipie::ResourceDescription.new(PetsController, 'pets') | ||
end | ||
|
||
let(:method_description) do | ||
Apipie::MethodDescription.new( | ||
'create', | ||
resource_description, | ||
ActionController::Base.send(:_apipie_dsl_data_init) | ||
) | ||
end | ||
|
||
let(:response_description_dsl) { proc {} } | ||
let(:options) { {} } | ||
|
||
let(:response_description) do | ||
described_class.new( | ||
method_description, | ||
204, | ||
options, | ||
PetsController, | ||
response_description_dsl, | ||
nil | ||
) | ||
end | ||
|
||
describe '#to_json' do | ||
let(:to_json) { response_description.to_json } | ||
|
||
describe 'headers' do | ||
subject(:headers) { to_json[:headers] } | ||
|
||
it { is_expected.to be_blank } | ||
|
||
context 'when response has headers' do | ||
let(:response_description_dsl) do | ||
proc do | ||
header 'Current-Page', Integer, 'The current page in the pagination', required: true | ||
end | ||
end | ||
|
||
it 'returns the header' do | ||
expect(headers).to contain_exactly({ | ||
name: 'Current-Page', | ||
description: 'The current page in the pagination', | ||
validator: 'integer', | ||
options: { required: true } | ||
}) | ||
end | ||
end | ||
end | ||
end | ||
end |