sinatra-rabbit 1.1.2 → 1.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/sinatra/docs/collection.haml +3 -3
- data/lib/sinatra/rabbit/base.rb +9 -7
- data/sinatra-rabbit.gemspec +1 -1
- data/tests/app_test.rb +13 -0
- data/tests/docs_test.rb +5 -10
- metadata +8 -8
@@ -20,10 +20,10 @@
|
|
20
20
|
%th Name
|
21
21
|
%th Constraints
|
22
22
|
%th Description
|
23
|
-
%tbody
|
23
|
+
%tbody.features
|
24
24
|
- collection.features.each do |f|
|
25
25
|
%tr
|
26
|
-
%td
|
26
|
+
%td.feature
|
27
27
|
%em=f.name
|
28
28
|
%td
|
29
29
|
- f.constraints.each do |c, v|
|
@@ -50,7 +50,7 @@
|
|
50
50
|
%th HTTP method
|
51
51
|
%th URL
|
52
52
|
%th Description
|
53
|
-
%tbody
|
53
|
+
%tbody.operations
|
54
54
|
- collection.operations.each do |o|
|
55
55
|
%tr
|
56
56
|
%td
|
data/lib/sinatra/rabbit/base.rb
CHANGED
@@ -14,6 +14,7 @@
|
|
14
14
|
# License for the specific language governing permissions and limitations
|
15
15
|
# under the License.
|
16
16
|
|
17
|
+
require 'haml'
|
17
18
|
require_relative './dsl'
|
18
19
|
require_relative './param'
|
19
20
|
require_relative './base_collection'
|
@@ -94,7 +95,7 @@ module Sinatra
|
|
94
95
|
base.get '/docs' do
|
95
96
|
css_file = File.read(File.join(File.dirname(__FILE__), '..', 'docs', 'bootstrap.min.css'))
|
96
97
|
index_file = File.read(File.join(File.dirname(__FILE__), '..', 'docs', 'api.haml'))
|
97
|
-
haml index_file, :locals => { :base => base.documentation_class, :css => css_file }
|
98
|
+
haml index_file, :locals => { :base => base.respond_to?(:documentation_class) ? base.documentation_class : base, :css => css_file }
|
98
99
|
end
|
99
100
|
end
|
100
101
|
|
@@ -107,14 +108,15 @@ module Sinatra
|
|
107
108
|
@parent_collection = parent_collection
|
108
109
|
class_eval(&block)
|
109
110
|
generate_head_route unless Rabbit.disabled? :head_routes
|
110
|
-
|
111
|
+
generate_options_route unless Rabbit.disabled? :options_routes
|
111
112
|
generate_docs_route unless Rabbit.disabled? :docs
|
112
113
|
self
|
113
114
|
end
|
114
115
|
|
115
|
-
def self.
|
116
|
-
|
117
|
-
|
116
|
+
def self.generate_options_route
|
117
|
+
methods = (['OPTIONS'] + operations.map { |o| o.http_method.to_s.upcase }).uniq.join(',')
|
118
|
+
base_class.options full_path do
|
119
|
+
headers 'Allow' => methods
|
118
120
|
status 200
|
119
121
|
end
|
120
122
|
end
|
@@ -257,7 +259,7 @@ module Sinatra
|
|
257
259
|
# Define Sinatra route and generate OPTIONS route if enabled
|
258
260
|
base_class.send(new_operation.http_method || http_method_for(operation_name), new_operation.full_path, route_options, &new_operation.control)
|
259
261
|
|
260
|
-
new_operation.
|
262
|
+
new_operation.generate_options_route(root_path + route_for(path, operation_name, :no_id_and_member)) unless Rabbit.disabled?(:options_routes)
|
261
263
|
new_operation.generate_head_route(root_path + route_for(path, operation_name, :member)) unless Rabbit.disabled?(:head_routes)
|
262
264
|
new_operation.generate_docs_route(new_operation.docs_url) unless Rabbit.disabled?(:doc_routes)
|
263
265
|
self
|
@@ -314,7 +316,7 @@ module Sinatra
|
|
314
316
|
end
|
315
317
|
end
|
316
318
|
|
317
|
-
def self.
|
319
|
+
def self.generate_options_route(path)
|
318
320
|
operation_params = params.map { |p| p.to_s }.join(',')
|
319
321
|
@collection.base_class.options path do
|
320
322
|
headers 'Allow' => operation_params
|
data/sinatra-rabbit.gemspec
CHANGED
data/tests/app_test.rb
CHANGED
@@ -27,6 +27,19 @@ describe Sample do
|
|
27
27
|
status.must_equal 200
|
28
28
|
end
|
29
29
|
|
30
|
+
it "should respond to OPTIONS request for sample collection" do
|
31
|
+
options '/sample'
|
32
|
+
status.must_equal 200
|
33
|
+
allow_header = last_response.headers['Allow'].split(',')
|
34
|
+
allow_header.wont_be_empty
|
35
|
+
allow_header.must_include 'OPTIONS'
|
36
|
+
allow_header.must_include 'GET'
|
37
|
+
allow_header.must_include 'POST'
|
38
|
+
allow_header.must_include 'DELETE'
|
39
|
+
last_response.headers['Content-Length'].must_equal '0'
|
40
|
+
last_response.body.must_be_empty
|
41
|
+
end
|
42
|
+
|
30
43
|
it "should respond 200 to HEAD request for index operation in sample collection" do
|
31
44
|
head '/sample/index'
|
32
45
|
status.must_equal 200
|
data/tests/docs_test.rb
CHANGED
@@ -24,34 +24,29 @@ describe 'Documentation' do
|
|
24
24
|
|
25
25
|
it "should return list of collections in entrypoint" do
|
26
26
|
get '/docs'
|
27
|
-
html.css('html body
|
27
|
+
html.css('html body h1').text.must_equal 'Sample'
|
28
28
|
html.css('html body ul li').wont_be_empty
|
29
29
|
html.css('html body ul li a').wont_be_empty
|
30
30
|
end
|
31
31
|
|
32
32
|
it "should return valid collection name when query collection documentation" do
|
33
33
|
get '/docs/sample'
|
34
|
-
html.css('html body
|
34
|
+
html.css('html body h1').text.must_equal 'Sample'
|
35
35
|
end
|
36
36
|
|
37
37
|
it "should return valid collection description when query collection documentation" do
|
38
38
|
get '/docs/sample'
|
39
|
-
html.css('html body
|
40
|
-
end
|
41
|
-
|
42
|
-
it "should return valid collection url when query collection documentation" do
|
43
|
-
get '/docs/sample'
|
44
|
-
html.css('html body > .url').text.must_equal '/sample'
|
39
|
+
html.css('html body blockquote p').text.strip.must_equal 'Test'
|
45
40
|
end
|
46
41
|
|
47
42
|
it "should return list of features when query collection documentation" do
|
48
43
|
get '/docs/sample'
|
49
|
-
html.css('html body .features .feature').map { |f| f.text}.must_include 'user_data', 'user_name'
|
44
|
+
html.css('html body .features .feature').map { |f| f.text.strip}.must_include 'user_data', 'user_name'
|
50
45
|
end
|
51
46
|
|
52
47
|
it "should return complete list of operations when query collection documentation" do
|
53
48
|
get '/docs/sample'
|
54
|
-
html.css('html body .operations tr').size.must_equal
|
49
|
+
html.css('html body .operations tr').size.must_equal 6
|
55
50
|
end
|
56
51
|
|
57
52
|
it "should provide valid links from entrypoint to collection" do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sinatra-rabbit
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-11-24 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: sinatra
|
@@ -37,20 +37,20 @@ extra_rdoc_files:
|
|
37
37
|
files:
|
38
38
|
- lib/sinatra/rabbit.rb
|
39
39
|
- lib/sinatra/docs/api.haml
|
40
|
-
- lib/sinatra/docs/collection.haml
|
41
40
|
- lib/sinatra/docs/operation.haml
|
41
|
+
- lib/sinatra/docs/collection.haml
|
42
42
|
- lib/sinatra/docs/bootstrap.min.css
|
43
43
|
- lib/sinatra/rabbit/base.rb
|
44
|
-
- lib/sinatra/rabbit/base_collection.rb
|
45
|
-
- lib/sinatra/rabbit/dsl.rb
|
46
44
|
- lib/sinatra/rabbit/features.rb
|
47
|
-
- lib/sinatra/rabbit/param.rb
|
48
45
|
- lib/sinatra/rabbit/validator.rb
|
46
|
+
- lib/sinatra/rabbit/dsl.rb
|
47
|
+
- lib/sinatra/rabbit/param.rb
|
48
|
+
- lib/sinatra/rabbit/base_collection.rb
|
49
49
|
- tests/app_test.rb
|
50
|
+
- tests/params_test.rb
|
51
|
+
- tests/fixtures.rb
|
50
52
|
- tests/docs_test.rb
|
51
53
|
- tests/dsl_test.rb
|
52
|
-
- tests/fixtures.rb
|
53
|
-
- tests/params_test.rb
|
54
54
|
- LICENSE
|
55
55
|
- README.md
|
56
56
|
- sinatra-rabbit.gemspec
|