|
7 | 7 | let(:post_group) { RSpec::Core::ExampleGroup.resource("Posts") }
|
8 | 8 | let(:comment_group) { RSpec::Core::ExampleGroup.resource("Comments") }
|
9 | 9 | let(:rspec_example_post_get) do
|
10 |
| - post_group.route "/posts/{id}", "Single Post" do |
| 10 | + post_group.route "/posts/:id{?option=:option}", "Single Post" do |
11 | 11 | parameter :id, "The id", required: true, type: "string", example: "1"
|
12 |
| - attribute :name, "Order name 1", required: true |
13 |
| - attribute :name, "Order name 2", required: true |
| 12 | + parameter :option |
14 | 13 |
|
15 | 14 | get("/posts/{id}") do
|
16 | 15 | example_request 'Gets a post' do
|
|
25 | 24 | end
|
26 | 25 |
|
27 | 26 | let(:rspec_example_post_delete) do
|
28 |
| - post_group.route "/posts/{id}", "Single Post" do |
29 |
| - get("/posts/{id}") do |
| 27 | + post_group.route "/posts/:id", "Single Post" do |
| 28 | + parameter :id, "The id", required: true, type: "string", example: "1" |
| 29 | + |
| 30 | + delete("/posts/:id") do |
30 | 31 | example_request 'Deletes a post' do
|
31 | 32 | do_request
|
32 | 33 | end
|
33 | 34 | end
|
34 | 35 | end
|
35 | 36 | end
|
36 | 37 |
|
| 38 | + let(:rspec_example_post_update) do |
| 39 | + post_group.route "/posts/:id", "Single Post" do |
| 40 | + parameter :id, "The id", required: true, type: "string", example: "1" |
| 41 | + attribute :name, "Order name 1", required: true |
| 42 | + attribute :name, "Order name 2", required: true |
| 43 | + |
| 44 | + put("/posts/:id") do |
| 45 | + example_request 'Updates a post' do |
| 46 | + do_request |
| 47 | + end |
| 48 | + end |
| 49 | + end |
| 50 | + end |
| 51 | + |
37 | 52 |
|
38 | 53 | let(:rspec_example_posts) do
|
39 | 54 | post_group.route "/posts", "Posts Collection" do
|
|
54 | 69 | end
|
55 | 70 | end
|
56 | 71 | end
|
57 |
| - let(:example1) { RspecApiDocumentation::Example.new(rspec_example_post_get, config) } |
58 |
| - let(:example2) { RspecApiDocumentation::Example.new(rspec_example_post_delete, config) } |
59 |
| - let(:example3) { RspecApiDocumentation::Example.new(rspec_example_posts, config) } |
60 |
| - let(:example4) { RspecApiDocumentation::Example.new(rspec_example_comments, config) } |
61 | 72 | let(:index) do
|
62 | 73 | RspecApiDocumentation::Index.new.tap do |index|
|
63 |
| - index.examples << example1 |
64 |
| - index.examples << example2 |
65 |
| - index.examples << example3 |
66 |
| - index.examples << example4 |
| 74 | + index.examples << RspecApiDocumentation::Example.new(rspec_example_post_get, config) |
| 75 | + index.examples << RspecApiDocumentation::Example.new(rspec_example_post_delete, config) |
| 76 | + index.examples << RspecApiDocumentation::Example.new(rspec_example_post_update, config) |
| 77 | + index.examples << RspecApiDocumentation::Example.new(rspec_example_posts, config) |
| 78 | + index.examples << RspecApiDocumentation::Example.new(rspec_example_comments, config) |
67 | 79 | end
|
68 | 80 | end
|
69 | 81 | let(:config) { RspecApiDocumentation::Configuration.new }
|
|
82 | 94 |
|
83 | 95 | it "returns routes grouped" do
|
84 | 96 | comments_route = sections[0][:routes][0]
|
85 |
| - posts_route = sections[1][:routes][0] |
86 |
| - post_route = sections[1][:routes][1] |
| 97 | + posts_route = sections[1][:routes][0] |
| 98 | + post_route = sections[1][:routes][1] |
| 99 | + post_route_with_optionals = sections[1][:routes][2] |
87 | 100 |
|
88 | 101 | comments_examples = comments_route[:http_methods].map { |http_method| http_method[:examples] }.flatten
|
89 | 102 | expect(comments_examples.size).to eq 1
|
90 |
| - expect(comments_route[:route_uri]).to eq "/comments" |
| 103 | + expect(comments_route[:route]).to eq "/comments" |
91 | 104 | expect(comments_route[:route_name]).to eq "Comments Collection"
|
92 | 105 | expect(comments_route[:has_parameters?]).to eq false
|
93 | 106 | expect(comments_route[:parameters]).to eq []
|
|
96 | 109 |
|
97 | 110 | post_examples = post_route[:http_methods].map { |http_method| http_method[:examples] }.flatten
|
98 | 111 | expect(post_examples.size).to eq 2
|
99 |
| - expect(post_route[:route_uri]).to eq "/posts/{id}" |
| 112 | + expect(post_route[:route]).to eq "/posts/:id" |
100 | 113 | expect(post_route[:route_name]).to eq "Single Post"
|
101 | 114 | expect(post_route[:has_parameters?]).to eq true
|
102 | 115 | expect(post_route[:parameters]).to eq [{
|
103 | 116 | required: true,
|
104 |
| - example: "1", |
105 | 117 | type: "string",
|
| 118 | + example: "1", |
106 | 119 | name: "id",
|
107 | 120 | description: "The id",
|
108 | 121 | properties_description: "required, string"
|
|
115 | 128 | properties_description: "required"
|
116 | 129 | }]
|
117 | 130 |
|
| 131 | + post_w_optionals_examples = post_route_with_optionals[:http_methods].map { |http_method| http_method[:examples] }.flatten |
| 132 | + expect(post_w_optionals_examples.size).to eq 1 |
| 133 | + expect(post_route_with_optionals[:route]).to eq "/posts/:id{?option=:option}" |
| 134 | + expect(post_route_with_optionals[:route_name]).to eq "Single Post" |
| 135 | + expect(post_route_with_optionals[:has_parameters?]).to eq true |
| 136 | + expect(post_route_with_optionals[:parameters]).to eq [{ |
| 137 | + required: true, |
| 138 | + type: "string", |
| 139 | + example: "1", |
| 140 | + name: "id", |
| 141 | + description: "The id", |
| 142 | + properties_description: "required, string" |
| 143 | + }, { |
| 144 | + name: "option", |
| 145 | + description: nil, |
| 146 | + properties_description: nil |
| 147 | + }] |
| 148 | + expect(post_route_with_optionals[:has_attributes?]).to eq false |
| 149 | + expect(post_route_with_optionals[:attributes]).to eq [] |
| 150 | + |
118 | 151 | posts_examples = posts_route[:http_methods].map { |http_method| http_method[:examples] }.flatten
|
119 | 152 | expect(posts_examples.size).to eq 1
|
120 |
| - expect(posts_route[:route_uri]).to eq "/posts" |
| 153 | + expect(posts_route[:route]).to eq "/posts" |
121 | 154 | expect(posts_route[:route_name]).to eq "Posts Collection"
|
122 | 155 | expect(posts_route[:has_parameters?]).to eq false
|
123 | 156 | expect(posts_route[:parameters]).to eq []
|
|
0 commit comments