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
a48ef4a2
Commit
a48ef4a2
authored
Oct 02, 2016
by
andrew morton
Committed by
GitHub
Oct 02, 2016
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #19 from drewish/little-fixes
Little fixes
parents
315e948a
fcd9706f
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
77 additions
and
13 deletions
+77
-13
formatter.rb
lib/rspec/rails/swagger/formatter.rb
+2
-2
helpers.rb
lib/rspec/rails/swagger/helpers.rb
+4
-0
request_builder.rb
lib/rspec/rails/swagger/request_builder.rb
+3
-3
helpers_spec.rb
spec/rspec/rails/swagger/helpers_spec.rb
+30
-0
request_builder_spec.rb
spec/rspec/rails/swagger/request_builder_spec.rb
+38
-8
No files found.
lib/rspec/rails/swagger/formatter.rb
View file @
a48ef4a2
...
...
@@ -62,7 +62,7 @@ module RSpec
when
:path_item
[
"
\n
"
,
metadata
[
:swagger_path_item
][
:path
]]
when
:operation
[
"
\n
"
,
metadata
[
:swagger_operation
][
:method
].
to_s
,
"
\t
"
]
[
"
\n
"
,
"%-8s"
%
metadata
[
:swagger_operation
][
:method
]
]
end
end
...
...
@@ -107,7 +107,7 @@ module RSpec
operation
[
:parameters
]
=
prepare_parameters
(
swagger_operation
[
:parameters
])
end
operation
.
merge!
(
swagger_operation
.
slice
(
:summary
,
:description
,
:externalDocs
,
:operationId
,
:
tags
,
:
summary
,
:description
,
:externalDocs
,
:operationId
,
:consumes
,
:produces
,
:schemes
,
:deprecated
,
:security
))
end
...
...
lib/rspec/rails/swagger/helpers.rb
View file @
a48ef4a2
...
...
@@ -174,6 +174,10 @@ module RSpec
metadata
[
:swagger_operation
][
:produces
]
=
mime_types
end
def
tags
*
tags
metadata
[
:swagger_operation
][
:tags
]
=
tags
end
def
response
status_code
,
attributes
=
{},
&
block
attributes
.
symbolize_keys!
...
...
lib/rspec/rails/swagger/request_builder.rb
View file @
a48ef4a2
...
...
@@ -20,11 +20,11 @@ module RSpec
end
def
produces
metadata
[
:swagger_operation
][
:produces
]
||
document
[
:produces
]
Array
(
metadata
[
:swagger_operation
][
:produces
]).
presence
||
Array
(
document
[
:produces
])
end
def
consumes
metadata
[
:swagger_operation
][
:consumes
]
||
document
[
:consumes
]
Array
(
metadata
[
:swagger_operation
][
:consumes
]).
presence
||
Array
(
document
[
:consumes
])
end
def
parameters
location
=
nil
...
...
@@ -52,7 +52,7 @@ module RSpec
headers
=
{}
# 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?
# TODO: do we need to do some capitalization to match the rack
...
...
spec/rspec/rails/swagger/helpers_spec.rb
View file @
a48ef4a2
...
...
@@ -186,6 +186,36 @@ RSpec.describe RSpec::Rails::Swagger::Helpers::Operation do
end
subject
{
klass
.
new
}
describe
'#consumes'
do
before
{
subject
.
metadata
=
{
swagger_operation:
{}}
}
it
'accepts an array'
do
subject
.
consumes
(
'foo'
,
'bar'
)
expect
(
subject
.
metadata
[
:swagger_operation
][
:consumes
]).
to
eq
[
'foo'
,
'bar'
]
end
end
describe
'#produces'
do
before
{
subject
.
metadata
=
{
swagger_operation:
{}}
}
it
'accepts an array'
do
subject
.
produces
(
'foo'
,
'bar'
)
expect
(
subject
.
metadata
[
:swagger_operation
][
:produces
]).
to
eq
[
'foo'
,
'bar'
]
end
end
describe
'#tags'
do
before
{
subject
.
metadata
=
{
swagger_operation:
{}}
}
it
'accepts an array'
do
subject
.
tags
(
'foo'
,
'bar'
)
expect
(
subject
.
metadata
[
:swagger_operation
][
:tags
]).
to
eq
[
'foo'
,
'bar'
]
end
end
describe
'#response'
do
before
{
subject
.
metadata
=
{
swagger_object: :operation
}
}
...
...
spec/rspec/rails/swagger/request_builder_spec.rb
View file @
a48ef4a2
...
...
@@ -37,11 +37,19 @@ RSpec.describe RSpec::Rails::Swagger::RequestBuilder do
let
(
:document
)
{
double
}
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'
}
}
}
it
'uses that value'
do
expect
(
subject
.
produces
).
to
eq
'something'
expect
(
subject
.
produces
).
to
eq
[
'something'
]
end
end
...
...
@@ -51,7 +59,7 @@ RSpec.describe RSpec::Rails::Swagger::RequestBuilder do
it
'uses the value from the document'
do
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
...
...
@@ -61,11 +69,19 @@ RSpec.describe RSpec::Rails::Swagger::RequestBuilder do
let
(
:document
)
{
double
}
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'
}
}
}
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
expect
(
subject
.
consumes
).
to
eq
'something'
expect
(
subject
.
consumes
).
to
eq
[
'something'
]
end
end
...
...
@@ -75,7 +91,7 @@ RSpec.describe RSpec::Rails::Swagger::RequestBuilder do
it
'uses the value from the document'
do
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
...
...
@@ -111,26 +127,40 @@ RSpec.describe RSpec::Rails::Swagger::RequestBuilder do
allow
(
subject
).
to
receive
(
:parameters
).
with
(
:header
)
{
{}
}
end
context
'when produces
is present
'
do
context
'when produces
has a single value
'
do
let
(
:produces
)
{
[
'foo/bar'
]
}
it
'sets the Accept header'
do
expect
(
subject
.
headers
).
to
include
(
'HTTP_ACCEPT'
=>
'foo/bar'
)
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
it
'does not set the Accept header'
do
expect
(
subject
.
headers
.
keys
).
not_to
include
(
'HTTP_ACCEPT'
)
end
end
context
'when consumes
is present
'
do
context
'when consumes
has a single value
'
do
let
(
:consumes
)
{
[
'bar/baz'
]
}
it
'sets the Content-Type header'
do
expect
(
subject
.
headers
).
to
include
(
'CONTENT_TYPE'
=>
'bar/baz'
)
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
it
'does not set the Content-Type header'
do
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