Skip to content

Commit 019e922

Browse files
idyllTim Vandecasteele
authored andcommitted
Added tests for params helper
1 parent 8183d19 commit 019e922

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

spec/grape-swagger-helper_spec.rb

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
require 'spec_helper'
2+
describe "helpers" do
3+
4+
before(:all) do
5+
class HelperTestAPI < Grape::API
6+
add_swagger_documentation
7+
end
8+
9+
@api = Object.new
10+
# after injecting grape-swagger into the Test API we get the helper methods
11+
# back from the first endpoint's class (the API mounted by grape-swagger
12+
# to serve the swagger_doc
13+
@api.extend HelperTestAPI.endpoints.first.options[:app].helpers
14+
15+
end
16+
17+
it "should parse params as query strings for a GET" do
18+
params = {
19+
name: {type: 'String', :desc =>"A name", required: true },
20+
level: 'max'
21+
}
22+
path = "/coolness"
23+
method = "GET"
24+
@api.parse_params(params, path, method).should ==
25+
[
26+
{paramType: "query", name: :name, description:"A name", dataType: "String", required: true},
27+
{paramType: "query", name: :level, description:"", dataType: "String", required: false}
28+
]
29+
end
30+
31+
it "should parse params as body for a POST" do
32+
params = {
33+
name: {type: 'String', :desc =>"A name", required: true },
34+
level: 'max'
35+
}
36+
path = "/coolness"
37+
method = "POST"
38+
@api.parse_params(params, path, method).should ==
39+
[
40+
{paramType: "body", name: :name, description:"A name", dataType: "String", required: true},
41+
{paramType: "body", name: :level, description:"", dataType: "String", required: false}
42+
]
43+
end
44+
45+
end

0 commit comments

Comments
 (0)