jellyfish 1.0.2 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +1 -0
- data/CHANGES.md +14 -0
- data/README.md +194 -119
- data/bench/bench_builder.rb +44 -0
- data/config.ru +5 -39
- data/jellyfish.gemspec +12 -18
- data/lib/jellyfish.rb +1 -3
- data/lib/jellyfish/builder.rb +52 -0
- data/lib/jellyfish/test.rb +8 -8
- data/lib/jellyfish/urlmap.rb +26 -0
- data/lib/jellyfish/version.rb +1 -1
- data/task/gemgem.rb +11 -2
- data/test/rack/test_builder.rb +154 -0
- data/test/rack/test_urlmap.rb +180 -0
- data/test/sinatra/test_base.rb +1 -1
- data/test/sinatra/test_routing.rb +0 -60
- data/test/test_from_readme.rb +31 -20
- metadata +15 -17
- data/lib/jellyfish/multi_actions.rb +0 -31
- data/lib/jellyfish/sinatra.rb +0 -13
- data/lib/jellyfish/swagger.rb +0 -166
- data/public/css/screen.css +0 -1070
- data/public/index.html +0 -45
- data/public/js/shred.bundle.js +0 -2765
- data/public/js/shred/content.js +0 -193
- data/public/js/swagger-ui.js +0 -2116
- data/public/js/swagger.js +0 -1400
- data/test/sinatra/test_multi_actions.rb +0 -217
- data/test/test_swagger.rb +0 -131
@@ -1,217 +0,0 @@
|
|
1
|
-
|
2
|
-
require 'jellyfish/test'
|
3
|
-
|
4
|
-
# stolen from sinatra
|
5
|
-
describe 'Sinatra filter_test.rb' do
|
6
|
-
paste :jellyfish
|
7
|
-
|
8
|
-
def new_app base=Object, &block
|
9
|
-
Class.new(base){
|
10
|
-
include Jellyfish
|
11
|
-
controller_include(Jellyfish::MultiActions)
|
12
|
-
instance_eval(&block)
|
13
|
-
}.new
|
14
|
-
end
|
15
|
-
|
16
|
-
would 'executes filters in the order defined' do
|
17
|
-
count = 0
|
18
|
-
app = new_app{
|
19
|
-
get { count.should.eq 0; count = 1 }
|
20
|
-
get { count.should.eq 1; count = 2 }
|
21
|
-
get('/'){ 'Hello World' }
|
22
|
-
}
|
23
|
-
|
24
|
-
status, _, body = get('/', app)
|
25
|
-
status.should.eq 200
|
26
|
-
count .should.eq 2
|
27
|
-
body .should.eq ['Hello World']
|
28
|
-
end
|
29
|
-
|
30
|
-
would 'modify env' do
|
31
|
-
app = new_app{
|
32
|
-
get{ env['BOO'] = 'MOO' }
|
33
|
-
get('/foo'){ env['BOO'] }
|
34
|
-
}
|
35
|
-
|
36
|
-
status, _, body = get('/foo', app)
|
37
|
-
status.should.eq 200
|
38
|
-
body .should.eq ['MOO']
|
39
|
-
end
|
40
|
-
|
41
|
-
would 'modify instance variables available to routes' do
|
42
|
-
app = new_app{
|
43
|
-
get{ @foo = 'bar' }
|
44
|
-
get('/foo') { @foo }
|
45
|
-
}
|
46
|
-
|
47
|
-
status, _, body = get('/foo', app)
|
48
|
-
status.should.eq 200
|
49
|
-
body .should.eq ['bar']
|
50
|
-
end
|
51
|
-
|
52
|
-
would 'allows redirects' do
|
53
|
-
app = new_app{
|
54
|
-
get{ found '/bar' }
|
55
|
-
get('/foo') do
|
56
|
-
fail 'before block should have halted processing'
|
57
|
-
'ORLY?!'
|
58
|
-
end
|
59
|
-
}
|
60
|
-
|
61
|
-
status, headers, body = get('/foo', app)
|
62
|
-
status .should.eq 302
|
63
|
-
headers['Location'].should.eq '/bar'
|
64
|
-
body.join .should =~ %r{<h1>Jellyfish found: /bar</h1>}
|
65
|
-
end
|
66
|
-
|
67
|
-
would 'not modify the response with its return value' do
|
68
|
-
app = new_app{
|
69
|
-
get{ 'Hello World!' }
|
70
|
-
get '/foo' do
|
71
|
-
body.should.eq nil
|
72
|
-
'cool'
|
73
|
-
end
|
74
|
-
}
|
75
|
-
|
76
|
-
status, _, body = get('/foo', app)
|
77
|
-
status.should.eq 200
|
78
|
-
body .should.eq ['cool']
|
79
|
-
end
|
80
|
-
|
81
|
-
would 'modify the response with halt' do
|
82
|
-
app = new_app{
|
83
|
-
get('/foo'){ halt [302, {}, ['Hi']] }
|
84
|
-
get('/foo'){ 'should not happen' }
|
85
|
-
get('/bar'){ status 402; body 'Ho'; halt }
|
86
|
-
get('/bar'){ 'should not happen' }
|
87
|
-
}
|
88
|
-
|
89
|
-
get('/foo', app).should.eq [302, {}, ['Hi']]
|
90
|
-
get('/bar', app).should.eq [402, {}, ['Ho']]
|
91
|
-
end
|
92
|
-
|
93
|
-
would 'give you access to params' do
|
94
|
-
app = new_app{
|
95
|
-
get{ @foo = Rack::Request.new(env).params['foo'] }
|
96
|
-
get('/foo'){ @foo.reverse }
|
97
|
-
}
|
98
|
-
|
99
|
-
status, _, body = get('/foo', app, 'QUERY_STRING' => 'foo=cool')
|
100
|
-
status.should.eq 200
|
101
|
-
body .should.eq ['looc']
|
102
|
-
end
|
103
|
-
|
104
|
-
would 'run filters defined in superclasses' do
|
105
|
-
sup = new_app{ get{ @foo = 'hello from superclass' } }.class
|
106
|
-
app = new_app(sup){ get('/foo'){ @foo } }
|
107
|
-
|
108
|
-
_, _, body = get('/foo', app)
|
109
|
-
body.should.eq ['hello from superclass']
|
110
|
-
|
111
|
-
sup .routes['get'].size.should.eq 1
|
112
|
-
app.class.routes['get'].size.should.eq 2
|
113
|
-
end
|
114
|
-
|
115
|
-
would 'take an optional route pattern' do
|
116
|
-
ran_filter = false
|
117
|
-
app = new_app{
|
118
|
-
get(%r{^/b}){ ran_filter = true }
|
119
|
-
get('/foo') {}
|
120
|
-
get('/bar') {}
|
121
|
-
}
|
122
|
-
get('/foo', app)
|
123
|
-
ran_filter.should.eq false
|
124
|
-
get('/bar', app)
|
125
|
-
ran_filter.should.eq true
|
126
|
-
end
|
127
|
-
|
128
|
-
would 'generate block arguments from route pattern' do
|
129
|
-
subpath = nil
|
130
|
-
app = new_app{
|
131
|
-
get(%r{^/foo/(\w+)}){ |m| subpath = m[1] }
|
132
|
-
}
|
133
|
-
get('/foo/bar', app)
|
134
|
-
subpath.should.eq 'bar'
|
135
|
-
end
|
136
|
-
|
137
|
-
would 'execute before and after filters in correct order' do
|
138
|
-
invoked = 0
|
139
|
-
app = new_app{
|
140
|
-
get { invoked = 2 }
|
141
|
-
get('/'){ invoked += 2; body 'hello' }
|
142
|
-
get { invoked *= 2 }
|
143
|
-
}
|
144
|
-
|
145
|
-
status, _, body = get('/', app)
|
146
|
-
status .should.eq 200
|
147
|
-
body .should.eq ['hello']
|
148
|
-
invoked.should.eq 8
|
149
|
-
end
|
150
|
-
|
151
|
-
would 'execute filters in the order defined' do
|
152
|
-
count = 0
|
153
|
-
app = new_app{
|
154
|
-
get('/'){ body 'Hello World' }
|
155
|
-
get{
|
156
|
-
count.should.eq 0
|
157
|
-
count = 1
|
158
|
-
}
|
159
|
-
get{
|
160
|
-
count.should.eq 1
|
161
|
-
count = 2
|
162
|
-
}
|
163
|
-
}
|
164
|
-
|
165
|
-
status, _, body = get('/', app)
|
166
|
-
status.should.eq 200
|
167
|
-
count .should.eq 2
|
168
|
-
body .should.eq ['Hello World']
|
169
|
-
end
|
170
|
-
|
171
|
-
would 'allow redirects' do
|
172
|
-
app = new_app{
|
173
|
-
get('/foo'){ 'ORLY' }
|
174
|
-
get { found '/bar' }
|
175
|
-
}
|
176
|
-
|
177
|
-
status, headers, body = get('/foo', app)
|
178
|
-
status .should.eq 302
|
179
|
-
headers['Location'].should.eq '/bar'
|
180
|
-
body.join .should =~ %r{<h1>Jellyfish found: /bar</h1>}
|
181
|
-
end
|
182
|
-
|
183
|
-
would 'not modify the response with its return value' do
|
184
|
-
app = new_app{
|
185
|
-
get('/foo'){ body 'cool' }
|
186
|
-
get { 'Hello World!' }
|
187
|
-
}
|
188
|
-
|
189
|
-
status, _, body = get('/foo', app)
|
190
|
-
status.should.eq 200
|
191
|
-
body .should.eq ['cool']
|
192
|
-
end
|
193
|
-
|
194
|
-
would 'modify the response with halt' do
|
195
|
-
app = new_app{
|
196
|
-
get('/foo'){ 'should not be returned' }
|
197
|
-
get{ halt [302, {}, ['Hi']] }
|
198
|
-
}
|
199
|
-
|
200
|
-
status, _, body = get('/foo', app)
|
201
|
-
status.should.eq 302
|
202
|
-
body .should.eq ['Hi']
|
203
|
-
end
|
204
|
-
|
205
|
-
would 'take an optional route pattern' do
|
206
|
-
ran_filter = false
|
207
|
-
app = new_app{
|
208
|
-
get('/foo') {}
|
209
|
-
get('/bar') {}
|
210
|
-
get(%r{^/b}){ ran_filter = true }
|
211
|
-
}
|
212
|
-
get('/foo', app)
|
213
|
-
ran_filter.should.eq false
|
214
|
-
get('/bar', app)
|
215
|
-
ran_filter.should.eq true
|
216
|
-
end
|
217
|
-
end
|
data/test/test_swagger.rb
DELETED
@@ -1,131 +0,0 @@
|
|
1
|
-
|
2
|
-
require 'jellyfish/test'
|
3
|
-
|
4
|
-
describe Jellyfish do
|
5
|
-
paste :jellyfish
|
6
|
-
|
7
|
-
app = Rack::Builder.app do
|
8
|
-
eval File.read("#{File.dirname(__FILE__)}/../config.ru")
|
9
|
-
end
|
10
|
-
|
11
|
-
def string_keys hash
|
12
|
-
hash.inject({}){ |r, (k, v)| r[k.to_s] = v; r }
|
13
|
-
end
|
14
|
-
|
15
|
-
would '/swagger' do
|
16
|
-
status, headers, body = get('/swagger', app)
|
17
|
-
status .should.eq 200
|
18
|
-
headers['Content-Type'].should.eq 'application/json; charset=utf-8'
|
19
|
-
res = Jellyfish::Json.decode(body.to_a.join)
|
20
|
-
res['swaggerVersion'].should.eq '1.2'
|
21
|
-
res['info'] .should.eq string_keys(Jelly.info)
|
22
|
-
res['apiVersion'] .should.eq Jelly.swagger_apiVersion
|
23
|
-
res['apis'] .should.eq \
|
24
|
-
[{'path' => '/users'}, {'path' => '/posts'}]
|
25
|
-
end
|
26
|
-
|
27
|
-
would '/swagger/users' do
|
28
|
-
status, _, body = get('/swagger/users', app)
|
29
|
-
status .should.eq 200
|
30
|
-
res = Jellyfish::Json.decode(body.to_a.join)
|
31
|
-
res['basePath'] .should.eq 'https://localhost:8080'
|
32
|
-
res['resourcePath'].should.eq '/users'
|
33
|
-
res['apis'] .should.eq \
|
34
|
-
[{"path"=>"/users",
|
35
|
-
"operations"=>[{"summary"=>"List users",
|
36
|
-
"notes"=>"List users<br>Note that we do not really" \
|
37
|
-
" have users.",
|
38
|
-
"path"=>"/users",
|
39
|
-
"method"=>"GET",
|
40
|
-
"nickname"=>"/users",
|
41
|
-
"parameters"=>[]},
|
42
|
-
{"summary"=>"Create a user",
|
43
|
-
"notes"=>"Create a user<br>Here we demonstrate how" \
|
44
|
-
" to write the swagger doc.",
|
45
|
-
"parameters"=>[{"type"=>"string",
|
46
|
-
"required"=>true,
|
47
|
-
"description"=>"The name of the user",
|
48
|
-
"name"=>"name",
|
49
|
-
"paramType"=>"query"},
|
50
|
-
{"type"=>"boolean",
|
51
|
-
"description"=>"If the user is sane",
|
52
|
-
"name"=>"sane",
|
53
|
-
"required"=>false,
|
54
|
-
"paramType"=>"query"},
|
55
|
-
{"type"=>"string",
|
56
|
-
"description"=>"What kind of user",
|
57
|
-
"enum"=>["good", "neutral", "evil"],
|
58
|
-
"name"=>"type",
|
59
|
-
"required"=>false,
|
60
|
-
"paramType"=>"query"}],
|
61
|
-
"responseMessages"=>[{"code"=>400,
|
62
|
-
"message"=>"Invalid name"}],
|
63
|
-
"path"=>"/users",
|
64
|
-
"method"=>"POST",
|
65
|
-
"nickname"=>"/users"}]},
|
66
|
-
{"path"=>"/users/{id}",
|
67
|
-
"operations"=>[{"summary"=>"Update a user",
|
68
|
-
"parameters"=>[{"type"=>"integer",
|
69
|
-
"description"=>"The id of the user",
|
70
|
-
"name"=>"id",
|
71
|
-
"required"=>true,
|
72
|
-
"paramType"=>"path"}],
|
73
|
-
"path"=>"/users",
|
74
|
-
"method"=>"PUT",
|
75
|
-
"nickname"=>"/users/{id}",
|
76
|
-
"notes"=>"Update a user"},
|
77
|
-
{"path"=>"/users",
|
78
|
-
"method"=>"DELETE",
|
79
|
-
"nickname"=>"/users/{id}",
|
80
|
-
"summary"=>nil,
|
81
|
-
"notes"=>nil,
|
82
|
-
"parameters"=>[{"name"=>"id",
|
83
|
-
"type"=>"integer",
|
84
|
-
"required"=>true,
|
85
|
-
"paramType"=>"path"}]}]}]
|
86
|
-
end
|
87
|
-
|
88
|
-
swagger = Jellyfish::Swagger.new(Class.new{include Jellyfish})
|
89
|
-
|
90
|
-
would 'swagger_path' do
|
91
|
-
swagger.send(:swagger_path, '/') .should.eq '/'
|
92
|
-
swagger.send(:swagger_path, '/users/{id}').should.eq '/users'
|
93
|
-
end
|
94
|
-
|
95
|
-
would 'nickname' do
|
96
|
-
swagger.send(:nickname, '/') .should.eq '/'
|
97
|
-
swagger.send(:nickname, '/users/{id}') .should.eq '/users/{id}'
|
98
|
-
swagger.send(:nickname, %r{\A/users/(?<id>\d+)}).should.eq '/users/{id}'
|
99
|
-
swagger.send(:nickname, %r{^/users/(?<id>\d+)$}).should.eq '/users/{id}'
|
100
|
-
swagger.send(:nickname, %r{/(?<a>\d)/(?<b>\w)$}).should.eq '/{a}/{b}'
|
101
|
-
end
|
102
|
-
|
103
|
-
would 'notes' do
|
104
|
-
swagger.send(:notes, :summary => 'summary', :notes => 'notes').
|
105
|
-
should.eq 'summary<br>notes'
|
106
|
-
swagger.send(:notes, :summary => 'summary').
|
107
|
-
should.eq 'summary'
|
108
|
-
end
|
109
|
-
|
110
|
-
would 'path_parameters' do
|
111
|
-
swagger.send(:path_parameters, %r{/(?<a>\d)/(?<b>\w)/(?<c>\d)$},
|
112
|
-
:parameters => {:c => {:type => 'hash'}}).
|
113
|
-
should.eq([{:name => 'a', :type => 'integer',
|
114
|
-
:required => true, :paramType => 'path'},
|
115
|
-
{:name => 'b', :type => 'string',
|
116
|
-
:required => true, :paramType => 'path'},
|
117
|
-
{:name => 'c', :type => 'hash',
|
118
|
-
:required => true, :paramType => 'path'}])
|
119
|
-
end
|
120
|
-
|
121
|
-
would 'query_parameters' do
|
122
|
-
swagger.send(:query_parameters,
|
123
|
-
:parameters => {:c => {:type => 'hash'}}).
|
124
|
-
should.eq([:name => 'c', :type => 'hash',
|
125
|
-
:required => false, :paramType => 'query'])
|
126
|
-
swagger.send(:query_parameters,
|
127
|
-
:parameters => {:c => {:required => true}}).
|
128
|
-
should.eq([:name => 'c', :type => 'string',
|
129
|
-
:required => true, :paramType => 'query'])
|
130
|
-
end
|
131
|
-
end
|