Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
R
rspec-rails-swagger
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
open-source
rspec-rails-swagger
Commits
c3f38ff9
Commit
c3f38ff9
authored
Oct 02, 2016
by
andrew morton
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Handle consumes/produces as strings or arrays
parent
80efa774
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
41 additions
and
11 deletions
+41
-11
request_builder.rb
lib/rspec/rails/swagger/request_builder.rb
+3
-3
request_builder_spec.rb
spec/rspec/rails/swagger/request_builder_spec.rb
+38
-8
No files found.
lib/rspec/rails/swagger/request_builder.rb
View file @
c3f38ff9
...
@@ -20,11 +20,11 @@ module RSpec
...
@@ -20,11 +20,11 @@ module RSpec
end
end
def
produces
def
produces
metadata
[
:swagger_operation
][
:produces
]
||
document
[
:produces
]
Array
(
metadata
[
:swagger_operation
][
:produces
]).
presence
||
Array
(
document
[
:produces
])
end
end
def
consumes
def
consumes
metadata
[
:swagger_operation
][
:consumes
]
||
document
[
:consumes
]
Array
(
metadata
[
:swagger_operation
][
:consumes
]).
presence
||
Array
(
document
[
:consumes
])
end
end
def
parameters
location
=
nil
def
parameters
location
=
nil
...
@@ -52,7 +52,7 @@ module RSpec
...
@@ -52,7 +52,7 @@ module RSpec
headers
=
{}
headers
=
{}
# Match the names that Rails uses internally
# Match the names that Rails uses internally
headers
[
'HTTP_ACCEPT'
]
=
produces
.
join
(
';'
)
if
produces
.
present?
headers
[
'HTTP_ACCEPT'
]
=
produces
.
first
if
produces
.
present?
headers
[
'CONTENT_TYPE'
]
=
consumes
.
first
if
consumes
.
present?
headers
[
'CONTENT_TYPE'
]
=
consumes
.
first
if
consumes
.
present?
# TODO: do we need to do some capitalization to match the rack
# TODO: do we need to do some capitalization to match the rack
...
...
spec/rspec/rails/swagger/request_builder_spec.rb
View file @
c3f38ff9
...
@@ -37,11 +37,19 @@ RSpec.describe RSpec::Rails::Swagger::RequestBuilder do
...
@@ -37,11 +37,19 @@ RSpec.describe RSpec::Rails::Swagger::RequestBuilder do
let
(
:document
)
{
double
}
let
(
:document
)
{
double
}
before
{
allow
(
subject
).
to
receive
(
:document
)
{
document
}
}
before
{
allow
(
subject
).
to
receive
(
:document
)
{
document
}
}
context
'with value in operation'
do
context
'with string in operation'
do
let
(
:metadata
)
{
{
swagger_operation:
{
produces:
'something'
}
}
}
it
'converts it to an array'
do
expect
(
subject
.
produces
).
to
eq
[
'something'
]
end
end
context
'with array in operation'
do
let
(
:metadata
)
{
{
swagger_operation:
{
produces:
'something'
}
}
}
let
(
:metadata
)
{
{
swagger_operation:
{
produces:
'something'
}
}
}
it
'uses that value'
do
it
'uses that value'
do
expect
(
subject
.
produces
).
to
eq
'something'
expect
(
subject
.
produces
).
to
eq
[
'something'
]
end
end
end
end
...
@@ -51,7 +59,7 @@ RSpec.describe RSpec::Rails::Swagger::RequestBuilder do
...
@@ -51,7 +59,7 @@ RSpec.describe RSpec::Rails::Swagger::RequestBuilder do
it
'uses the value from the document'
do
it
'uses the value from the document'
do
expect
(
document
).
to
receive
(
:[]
).
with
(
:produces
)
{
'or other'
}
expect
(
document
).
to
receive
(
:[]
).
with
(
:produces
)
{
'or other'
}
expect
(
subject
.
produces
).
to
eq
'or other'
expect
(
subject
.
produces
).
to
eq
[
'or other'
]
end
end
end
end
end
end
...
@@ -61,11 +69,19 @@ RSpec.describe RSpec::Rails::Swagger::RequestBuilder do
...
@@ -61,11 +69,19 @@ RSpec.describe RSpec::Rails::Swagger::RequestBuilder do
let
(
:document
)
{
double
}
let
(
:document
)
{
double
}
before
{
allow
(
subject
).
to
receive
(
:document
)
{
document
}
}
before
{
allow
(
subject
).
to
receive
(
:document
)
{
document
}
}
context
'with
value
in operation'
do
context
'with
string
in operation'
do
let
(
:metadata
)
{
{
swagger_operation:
{
consumes:
'something'
}
}
}
let
(
:metadata
)
{
{
swagger_operation:
{
consumes:
'something'
}
}
}
it
'converts it to an array'
do
expect
(
subject
.
consumes
).
to
eq
[
'something'
]
end
end
context
'with array in operation'
do
let
(
:metadata
)
{
{
swagger_operation:
{
consumes:
[
'something'
]
}
}
}
it
'uses that value'
do
it
'uses that value'
do
expect
(
subject
.
consumes
).
to
eq
'something'
expect
(
subject
.
consumes
).
to
eq
[
'something'
]
end
end
end
end
...
@@ -75,7 +91,7 @@ RSpec.describe RSpec::Rails::Swagger::RequestBuilder do
...
@@ -75,7 +91,7 @@ RSpec.describe RSpec::Rails::Swagger::RequestBuilder do
it
'uses the value from the document'
do
it
'uses the value from the document'
do
expect
(
document
).
to
receive
(
:[]
).
with
(
:consumes
)
{
'or other'
}
expect
(
document
).
to
receive
(
:[]
).
with
(
:consumes
)
{
'or other'
}
expect
(
subject
.
consumes
).
to
eq
'or other'
expect
(
subject
.
consumes
).
to
eq
[
'or other'
]
end
end
end
end
end
end
...
@@ -111,26 +127,40 @@ RSpec.describe RSpec::Rails::Swagger::RequestBuilder do
...
@@ -111,26 +127,40 @@ RSpec.describe RSpec::Rails::Swagger::RequestBuilder do
allow
(
subject
).
to
receive
(
:parameters
).
with
(
:header
)
{
{}
}
allow
(
subject
).
to
receive
(
:parameters
).
with
(
:header
)
{
{}
}
end
end
context
'when produces
is present
'
do
context
'when produces
has a single value
'
do
let
(
:produces
)
{
[
'foo/bar'
]
}
let
(
:produces
)
{
[
'foo/bar'
]
}
it
'sets the Accept header'
do
it
'sets the Accept header'
do
expect
(
subject
.
headers
).
to
include
(
'HTTP_ACCEPT'
=>
'foo/bar'
)
expect
(
subject
.
headers
).
to
include
(
'HTTP_ACCEPT'
=>
'foo/bar'
)
end
end
end
end
context
'when produces has multiple values'
do
let
(
:produces
)
{
[
'foo/bar'
,
'bar/baz'
]
}
it
'sets the Accept header to the first'
do
expect
(
subject
.
headers
).
to
include
(
'HTTP_ACCEPT'
=>
'foo/bar'
)
end
end
context
'when produces is blank'
do
context
'when produces is blank'
do
it
'does not set the Accept header'
do
it
'does not set the Accept header'
do
expect
(
subject
.
headers
.
keys
).
not_to
include
(
'HTTP_ACCEPT'
)
expect
(
subject
.
headers
.
keys
).
not_to
include
(
'HTTP_ACCEPT'
)
end
end
end
end
context
'when consumes
is present
'
do
context
'when consumes
has a single value
'
do
let
(
:consumes
)
{
[
'bar/baz'
]
}
let
(
:consumes
)
{
[
'bar/baz'
]
}
it
'sets the Content-Type header'
do
it
'sets the Content-Type header'
do
expect
(
subject
.
headers
).
to
include
(
'CONTENT_TYPE'
=>
'bar/baz'
)
expect
(
subject
.
headers
).
to
include
(
'CONTENT_TYPE'
=>
'bar/baz'
)
end
end
end
end
context
'when consumes has multiple values'
do
let
(
:consumes
)
{
[
'bar/baz'
,
'flooz/flop'
]
}
it
'sets the Content-Type header to the first'
do
expect
(
subject
.
headers
).
to
include
(
'CONTENT_TYPE'
=>
'bar/baz'
)
end
end
context
'when consumes is blank'
do
context
'when consumes is blank'
do
it
'does not set the Content-Type header'
do
it
'does not set the Content-Type header'
do
expect
(
subject
.
headers
.
keys
).
not_to
include
(
'CONTENT_TYPE'
)
expect
(
subject
.
headers
.
keys
).
not_to
include
(
'CONTENT_TYPE'
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment