|
2 | 2 |
|
3 | 3 | describe "helpers" do
|
4 | 4 |
|
5 |
| - before(:all) do |
6 |
| - class HelperTestAPI < Grape::API |
7 |
| - add_swagger_documentation |
8 |
| - end |
| 5 | + before(:all) do |
| 6 | + class HelperTestAPI < Grape::API |
| 7 | + add_swagger_documentation |
| 8 | + end |
9 | 9 |
|
10 |
| - @api = Object.new |
11 |
| - # after injecting grape-swagger into the Test API we get the helper methods |
12 |
| - # back from the first endpoint's class (the API mounted by grape-swagger |
13 |
| - # to serve the swagger_doc |
14 |
| - @api.extend HelperTestAPI.endpoints.first.options[:app].helpers |
| 10 | + @api = Object.new |
| 11 | + # after injecting grape-swagger into the Test API we get the helper methods |
| 12 | + # back from the first endpoint's class (the API mounted by grape-swagger |
| 13 | + # to serve the swagger_doc |
| 14 | + @api.extend HelperTestAPI.endpoints.first.options[:app].helpers |
15 | 15 |
|
16 |
| - end |
| 16 | + end |
17 | 17 |
|
18 |
| - context "parsing parameters" do |
19 |
| - it "should parse params as query strings for a GET" do |
20 |
| - params = { |
21 |
| - name: {type: 'String', :desc => "A name", required: true }, |
22 |
| - level: 'max' |
23 |
| - } |
24 |
| - path = "/coolness" |
25 |
| - method = "GET" |
26 |
| - @api.parse_params(params, path, method).should == |
27 |
| - [ |
28 |
| - {paramType: "query", name: :name, description:"A name", dataType: "String", required: true}, |
29 |
| - {paramType: "query", name: :level, description:"", dataType: "String", required: false} |
30 |
| - ] |
31 |
| - end |
| 18 | + context "parsing parameters" do |
| 19 | + it "should parse params as query strings for a GET" do |
| 20 | + params = { |
| 21 | + name: {type: 'String', :desc => "A name", required: true }, |
| 22 | + level: 'max' |
| 23 | + } |
| 24 | + path = "/coolness" |
| 25 | + method = "GET" |
| 26 | + @api.parse_params(params, path, method).should == |
| 27 | + [ |
| 28 | + {paramType: "query", name: :name, description:"A name", dataType: "String", required: true}, |
| 29 | + {paramType: "query", name: :level, description:"", dataType: "String", required: false} |
| 30 | + ] |
| 31 | + end |
32 | 32 |
|
33 |
| - it "should parse params as body for a POST" do |
34 |
| - params = { |
35 |
| - name: {type: 'String', :desc =>"A name", required: true }, |
36 |
| - level: 'max' |
37 |
| - } |
38 |
| - path = "/coolness" |
39 |
| - method = "POST" |
40 |
| - @api.parse_params(params, path, method).should == |
41 |
| - [ |
42 |
| - {paramType: "body", name: :name, description:"A name", dataType: "String", required: true}, |
43 |
| - {paramType: "body", name: :level, description:"", dataType: "String", required: false} |
44 |
| - ] |
45 |
| - end |
46 |
| - end |
| 33 | + it "should parse params as body for a POST" do |
| 34 | + params = { |
| 35 | + name: {type: 'String', :desc =>"A name", required: true }, |
| 36 | + level: 'max' |
| 37 | + } |
| 38 | + path = "/coolness" |
| 39 | + method = "POST" |
| 40 | + @api.parse_params(params, path, method).should == |
| 41 | + [ |
| 42 | + {paramType: "body", name: :name, description:"A name", dataType: "String", required: true}, |
| 43 | + {paramType: "body", name: :level, description:"", dataType: "String", required: false} |
| 44 | + ] |
| 45 | + end |
| 46 | + end |
47 | 47 |
|
48 |
| - context "parsing the path" do |
49 |
| - it "should parse the path" do |
50 |
| - path = ":abc/def(.:format)" |
51 |
| - @api.parse_path(path, nil).should == "{abc}/def.{format}" |
52 |
| - end |
| 48 | + context "parsing the path" do |
| 49 | + it "should parse the path" do |
| 50 | + path = ":abc/def(.:format)" |
| 51 | + @api.parse_path(path, nil).should == "{abc}/def.{format}" |
| 52 | + end |
53 | 53 |
|
54 | 54 | it "should parse a path that has vars with underscores in the name" do
|
55 | 55 | path = "abc/:def_g(.:format)"
|
56 |
| - @api.parse_path(path, nil).should == "abc/{def_g}.{format}" |
57 |
| - |
| 56 | + @api.parse_path(path, nil).should == "abc/{def_g}.{format}" |
| 57 | + |
58 | 58 | end
|
59 | 59 |
|
60 | 60 | it "should parse a path that has vars with numbers in the name" do
|
61 | 61 | path = "abc/:sha1(.:format)"
|
62 |
| - @api.parse_path(path, nil).should == "abc/{sha1}.{format}" |
| 62 | + @api.parse_path(path, nil).should == "abc/{sha1}.{format}" |
63 | 63 | end
|
64 | 64 |
|
65 | 65 | it "should parse a path that has multiple variables" do
|
66 | 66 | path1 = "abc/:def/:geh(.:format)"
|
67 | 67 | path2 = "abc/:def:geh(.:format)"
|
68 |
| - @api.parse_path(path1, nil).should == "abc/{def}/{geh}.{format}" |
69 |
| - @api.parse_path(path2, nil).should == "abc/{def}{geh}.{format}" |
| 68 | + @api.parse_path(path1, nil).should == "abc/{def}/{geh}.{format}" |
| 69 | + @api.parse_path(path2, nil).should == "abc/{def}{geh}.{format}" |
70 | 70 | end
|
71 | 71 |
|
72 |
| - it "should parse the path with a specified version" do |
73 |
| - path = ":abc/{version}/def(.:format)" |
74 |
| - @api.parse_path(path, 'v1').should == "{abc}/v1/def.{format}" |
75 |
| - end |
76 |
| - end |
| 72 | + it "should parse the path with a specified version" do |
| 73 | + path = ":abc/{version}/def(.:format)" |
| 74 | + @api.parse_path(path, 'v1').should == "{abc}/v1/def.{format}" |
| 75 | + end |
| 76 | + end |
77 | 77 |
|
78 |
| - context "parsing header parameters" do |
79 |
| - it "should parse params for the header" do |
80 |
| - params = {"XAuthToken" => { description: "A required header.", required: true}} |
81 |
| - @api.parse_header_params(params).should == |
82 |
| - [ |
83 |
| - {paramType: "header", name: "XAuthToken", description:"A required header.", dataType: "String", required: true} |
84 |
| - ] |
85 |
| - end |
86 |
| - end |
| 78 | + context "parsing header parameters" do |
| 79 | + it "should parse params for the header" do |
| 80 | + params = {"XAuthToken" => { description: "A required header.", required: true}} |
| 81 | + @api.parse_header_params(params).should == |
| 82 | + [ |
| 83 | + {paramType: "header", name: "XAuthToken", description:"A required header.", dataType: "String", required: true} |
| 84 | + ] |
| 85 | + end |
| 86 | + end |
87 | 87 |
|
88 | 88 | end
|
0 commit comments