sinatra-contrib 2.0.0.rc1 → 2.0.0.rc2

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.
Files changed (69) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE +2 -1
  3. data/lib/sinatra/decompile.rb +5 -0
  4. data/lib/sinatra/runner.rb +155 -0
  5. data/lib/sinatra/webdav.rb +93 -0
  6. data/sinatra-contrib.gemspec +5 -199
  7. metadata +13 -175
  8. data/spec/capture_spec.rb +0 -100
  9. data/spec/config_file/key_value.yml +0 -7
  10. data/spec/config_file/key_value.yml.erb +0 -6
  11. data/spec/config_file/key_value_override.yml +0 -2
  12. data/spec/config_file/missing_env.yml +0 -4
  13. data/spec/config_file/with_envs.yml +0 -7
  14. data/spec/config_file/with_nested_envs.yml +0 -11
  15. data/spec/config_file_spec.rb +0 -76
  16. data/spec/content_for/different_key.erb +0 -1
  17. data/spec/content_for/different_key.erubis +0 -1
  18. data/spec/content_for/different_key.haml +0 -2
  19. data/spec/content_for/different_key.slim +0 -2
  20. data/spec/content_for/footer.erb +0 -3
  21. data/spec/content_for/footer.erubis +0 -3
  22. data/spec/content_for/footer.haml +0 -2
  23. data/spec/content_for/footer.slim +0 -2
  24. data/spec/content_for/layout.erb +0 -1
  25. data/spec/content_for/layout.erubis +0 -1
  26. data/spec/content_for/layout.haml +0 -1
  27. data/spec/content_for/layout.slim +0 -1
  28. data/spec/content_for/multiple_blocks.erb +0 -4
  29. data/spec/content_for/multiple_blocks.erubis +0 -4
  30. data/spec/content_for/multiple_blocks.haml +0 -8
  31. data/spec/content_for/multiple_blocks.slim +0 -8
  32. data/spec/content_for/multiple_yields.erb +0 -3
  33. data/spec/content_for/multiple_yields.erubis +0 -3
  34. data/spec/content_for/multiple_yields.haml +0 -3
  35. data/spec/content_for/multiple_yields.slim +0 -3
  36. data/spec/content_for/passes_values.erb +0 -1
  37. data/spec/content_for/passes_values.erubis +0 -1
  38. data/spec/content_for/passes_values.haml +0 -1
  39. data/spec/content_for/passes_values.slim +0 -1
  40. data/spec/content_for/same_key.erb +0 -1
  41. data/spec/content_for/same_key.erubis +0 -1
  42. data/spec/content_for/same_key.haml +0 -2
  43. data/spec/content_for/same_key.slim +0 -2
  44. data/spec/content_for/takes_values.erb +0 -1
  45. data/spec/content_for/takes_values.erubis +0 -1
  46. data/spec/content_for/takes_values.haml +0 -3
  47. data/spec/content_for/takes_values.slim +0 -3
  48. data/spec/content_for_spec.rb +0 -241
  49. data/spec/cookies_spec.rb +0 -826
  50. data/spec/custom_logger_spec.rb +0 -43
  51. data/spec/extension_spec.rb +0 -32
  52. data/spec/json_spec.rb +0 -115
  53. data/spec/link_header_spec.rb +0 -99
  54. data/spec/multi_route_spec.rb +0 -59
  55. data/spec/namespace/foo.erb +0 -1
  56. data/spec/namespace/nested/foo.erb +0 -1
  57. data/spec/namespace_spec.rb +0 -791
  58. data/spec/okjson.rb +0 -581
  59. data/spec/reloader/app.rb.erb +0 -40
  60. data/spec/reloader_spec.rb +0 -465
  61. data/spec/required_params_spec.rb +0 -68
  62. data/spec/respond_with/bar.erb +0 -1
  63. data/spec/respond_with/bar.json.erb +0 -1
  64. data/spec/respond_with/baz.yajl +0 -1
  65. data/spec/respond_with/foo.html.erb +0 -1
  66. data/spec/respond_with/not_html.sass +0 -2
  67. data/spec/respond_with_spec.rb +0 -317
  68. data/spec/spec_helper.rb +0 -7
  69. data/spec/streaming_spec.rb +0 -415
@@ -1,40 +0,0 @@
1
- class <%= name %> < <%= parent %>
2
- <% if enable_reloader %>
3
- register Sinatra::Reloader
4
- enable :reloader
5
- <% end %>
6
- <% unless inline_templates.nil? %>
7
- enable :inline_templates
8
- <% end %>
9
-
10
- <% extensions.each do |extension| %>
11
- register <%= extension %>
12
- <% end %>
13
-
14
- <% middlewares.each do |middleware| %>
15
- use <%= middleware %>
16
- <% end %>
17
-
18
- <% filters.each do |filter| %>
19
- <%= filter %>
20
- <% end %>
21
-
22
- <% errors.each do |number, code| %>
23
- error <%= number %> do
24
- <%= code %>
25
- end
26
- <% end %>
27
-
28
- <% routes.each do |route| %>
29
- <%= route %>
30
- <% end %>
31
- end
32
-
33
- <% unless inline_templates.nil? %>
34
- __END__
35
-
36
- <% inline_templates.each_pair do |name, content| %>
37
- @@<%= name %>
38
- <%= content %>
39
- <% end %>
40
- <% end %>
@@ -1,465 +0,0 @@
1
- require 'spec_helper'
2
- require 'fileutils'
3
-
4
- describe Sinatra::Reloader do
5
- # Returns the temporary directory.
6
- def tmp_dir
7
- File.expand_path('../../tmp', __FILE__)
8
- end
9
-
10
- # Returns the path of the Sinatra application file created by
11
- # +setup_example_app+.
12
- def app_file_path
13
- File.join(tmp_dir, "example_app_#{$example_app_counter}.rb")
14
- end
15
-
16
- # Returns the name of the Sinatra application created by
17
- # +setup_example_app+: 'ExampleApp1' for the first application,
18
- # 'ExampleApp2' fo the second one, and so on...
19
- def app_name
20
- "ExampleApp#{$example_app_counter}"
21
- end
22
-
23
- # Returns the (constant of the) Sinatra application created by
24
- # +setup_example_app+.
25
- def app_const
26
- Module.const_get(app_name)
27
- end
28
-
29
- # Writes a file with a Sinatra application using the template
30
- # located at <tt>specs/reloader/app.rb.erb</tt>. It expects an
31
- # +options+ hash, with an array of strings containing the
32
- # application's routes (+:routes+ key), a hash with the inline
33
- # template's names as keys and the bodys as values
34
- # (+:inline_templates+ key) and an optional application name
35
- # (+:name+) otherwise +app_name+ is used.
36
- #
37
- # It ensures to change the written file's mtime when it already
38
- # exists.
39
- def write_app_file(options={})
40
- options[:routes] ||= ['get("/foo") { erb :foo }']
41
- options[:inline_templates] ||= nil
42
- options[:extensions] ||= []
43
- options[:middlewares] ||= []
44
- options[:filters] ||= []
45
- options[:errors] ||= {}
46
- options[:name] ||= app_name
47
- options[:enable_reloader] = true unless options[:enable_reloader] === false
48
- options[:parent] ||= 'Sinatra::Base'
49
-
50
- update_file(app_file_path) do |f|
51
- template_path = File.expand_path('../reloader/app.rb.erb', __FILE__)
52
- template = Tilt.new(template_path, nil, :trim => '<>')
53
- f.write template.render(Object.new, options)
54
- end
55
- end
56
-
57
- alias update_app_file write_app_file
58
-
59
- # It calls <tt>File.open(path, 'w', &block)</tt> all the times
60
- # needed to change the file's mtime.
61
- def update_file(path, &block)
62
- original_mtime = File.exist?(path) ? File.mtime(path) : Time.at(0)
63
- new_time = original_mtime + 1
64
- File.open(path, 'w', &block)
65
- File.utime(new_time, new_time, path)
66
- end
67
-
68
- # Writes a Sinatra application to a file, requires the file, sets
69
- # the new application as the one being tested and enables the
70
- # reloader.
71
- def setup_example_app(options={})
72
- $example_app_counter ||= 0
73
- $example_app_counter += 1
74
-
75
- FileUtils.mkdir_p(tmp_dir)
76
- write_app_file(options)
77
- $LOADED_FEATURES.delete app_file_path
78
- require app_file_path
79
- self.app = app_const
80
- app_const.enable :reloader
81
- end
82
-
83
- after(:all) { FileUtils.rm_rf(tmp_dir) }
84
-
85
- describe "default route reloading mechanism" do
86
- before(:each) do
87
- setup_example_app(:routes => ['get("/foo") { "foo" }'])
88
- end
89
-
90
- it "doesn't mess up the application" do
91
- expect(get('/foo').body).to eq('foo')
92
- end
93
-
94
- it "knows when a route has been modified" do
95
- update_app_file(:routes => ['get("/foo") { "bar" }'])
96
- expect(get('/foo').body).to eq('bar')
97
- end
98
-
99
- it "knows when a route has been added" do
100
- update_app_file(
101
- :routes => ['get("/foo") { "foo" }', 'get("/bar") { "bar" }']
102
- )
103
- expect(get('/foo').body).to eq('foo')
104
- expect(get('/bar').body).to eq('bar')
105
- end
106
-
107
- it "knows when a route has been removed" do
108
- update_app_file(:routes => ['get("/bar") { "bar" }'])
109
- expect(get('/foo').status).to eq(404)
110
- end
111
-
112
- it "doesn't try to reload a removed file" do
113
- update_app_file(:routes => ['get("/foo") { "i shall not be reloaded" }'])
114
- FileUtils.rm app_file_path
115
- expect(get('/foo').body.strip).to eq('foo')
116
- end
117
- end
118
-
119
- describe "default inline templates reloading mechanism" do
120
- before(:each) do
121
- setup_example_app(
122
- :routes => ['get("/foo") { erb :foo }'],
123
- :inline_templates => { :foo => 'foo' }
124
- )
125
- end
126
-
127
- it "doesn't mess up the application" do
128
- expect(get('/foo').body.strip).to eq('foo')
129
- end
130
-
131
- it "reloads inline templates in the app file" do
132
- update_app_file(
133
- :routes => ['get("/foo") { erb :foo }'],
134
- :inline_templates => { :foo => 'bar' }
135
- )
136
- expect(get('/foo').body.strip).to eq('bar')
137
- end
138
-
139
- it "reloads inline templates in other file" do
140
- setup_example_app(:routes => ['get("/foo") { erb :foo }'])
141
- template_file_path = File.join(tmp_dir, 'templates.rb')
142
- File.open(template_file_path, 'w') do |f|
143
- f.write "__END__\n\n@@foo\nfoo"
144
- end
145
- require template_file_path
146
- app_const.inline_templates= template_file_path
147
- expect(get('/foo').body.strip).to eq('foo')
148
- update_file(template_file_path) do |f|
149
- f.write "__END__\n\n@@foo\nbar"
150
- end
151
- expect(get('/foo').body.strip).to eq('bar')
152
- end
153
- end
154
-
155
- describe "default middleware reloading mechanism" do
156
- it "knows when a middleware has been added" do
157
- setup_example_app(:routes => ['get("/foo") { "foo" }'])
158
- update_app_file(
159
- :routes => ['get("/foo") { "foo" }'],
160
- :middlewares => [Rack::Head]
161
- )
162
- get('/foo') # ...to perform the reload
163
- expect(app_const.middleware).not_to be_empty
164
- end
165
-
166
- it "knows when a middleware has been removed" do
167
- setup_example_app(
168
- :routes => ['get("/foo") { "foo" }'],
169
- :middlewares => [Rack::Head]
170
- )
171
- update_app_file(:routes => ['get("/foo") { "foo" }'])
172
- get('/foo') # ...to perform the reload
173
- expect(app_const.middleware).to be_empty
174
- end
175
- end
176
-
177
- describe "default filter reloading mechanism" do
178
- it "knows when a before filter has been added" do
179
- setup_example_app(:routes => ['get("/foo") { "foo" }'])
180
- expect {
181
- update_app_file(
182
- :routes => ['get("/foo") { "foo" }'],
183
- :filters => ['before { @hi = "hi" }']
184
- )
185
- get('/foo') # ...to perform the reload
186
- }.to change { app_const.filters[:before].size }.by(1)
187
- end
188
-
189
- it "knows when an after filter has been added" do
190
- setup_example_app(:routes => ['get("/foo") { "foo" }'])
191
- expect {
192
- update_app_file(
193
- :routes => ['get("/foo") { "foo" }'],
194
- :filters => ['after { @bye = "bye" }']
195
- )
196
- get('/foo') # ...to perform the reload
197
- }.to change { app_const.filters[:after].size }.by(1)
198
- end
199
-
200
- it "knows when a before filter has been removed" do
201
- setup_example_app(
202
- :routes => ['get("/foo") { "foo" }'],
203
- :filters => ['before { @hi = "hi" }']
204
- )
205
- expect {
206
- update_app_file(:routes => ['get("/foo") { "foo" }'])
207
- get('/foo') # ...to perform the reload
208
- }.to change { app_const.filters[:before].size }.by(-1)
209
- end
210
-
211
- it "knows when an after filter has been removed" do
212
- setup_example_app(
213
- :routes => ['get("/foo") { "foo" }'],
214
- :filters => ['after { @bye = "bye" }']
215
- )
216
- expect {
217
- update_app_file(:routes => ['get("/foo") { "foo" }'])
218
- get('/foo') # ...to perform the reload
219
- }.to change { app_const.filters[:after].size }.by(-1)
220
- end
221
- end
222
-
223
- describe "error reloading" do
224
- before do
225
- setup_example_app(
226
- :routes => ['get("/secret") { 403 }'],
227
- :errors => { 403 => "'Access forbiden'" }
228
- )
229
- end
230
-
231
- it "doesn't mess up the application" do
232
- expect(get('/secret')).to be_client_error
233
- expect(get('/secret').body.strip).to eq('Access forbiden')
234
- end
235
-
236
- it "knows when a error has been added" do
237
- update_app_file(:errors => { 404 => "'Nowhere'" })
238
- expect(get('/nowhere')).to be_not_found
239
- expect(get('/nowhere').body).to eq('Nowhere')
240
- end
241
-
242
- it "knows when a error has been removed" do
243
- update_app_file(:routes => ['get("/secret") { 403 }'])
244
- expect(get('/secret')).to be_client_error
245
- expect(get('/secret').body).not_to eq('Access forbiden')
246
- end
247
-
248
- it "knows when a error has been modified" do
249
- update_app_file(
250
- :routes => ['get("/secret") { 403 }'],
251
- :errors => { 403 => "'What are you doing here?'" }
252
- )
253
- expect(get('/secret')).to be_client_error
254
- expect(get('/secret').body).to eq('What are you doing here?')
255
- end
256
- end
257
-
258
- describe "extension reloading" do
259
- it "doesn't duplicate routes with every reload" do
260
- module ::RouteExtension
261
- def self.registered(klass)
262
- klass.get('/bar') { 'bar' }
263
- end
264
- end
265
-
266
- setup_example_app(
267
- :routes => ['get("/foo") { "foo" }'],
268
- :extensions => ['RouteExtension']
269
- )
270
-
271
- expect {
272
- update_app_file(
273
- :routes => ['get("/foo") { "foo" }'],
274
- :extensions => ['RouteExtension']
275
- )
276
- get('/foo') # ...to perform the reload
277
- }.to_not change { app_const.routes['GET'].size }
278
- end
279
-
280
- it "doesn't duplicate middleware with every reload" do
281
- module ::MiddlewareExtension
282
- def self.registered(klass)
283
- klass.use Rack::Head
284
- end
285
- end
286
-
287
- setup_example_app(
288
- :routes => ['get("/foo") { "foo" }'],
289
- :extensions => ['MiddlewareExtension']
290
- )
291
-
292
- expect {
293
- update_app_file(
294
- :routes => ['get("/foo") { "foo" }'],
295
- :extensions => ['MiddlewareExtension']
296
- )
297
- get('/foo') # ...to perform the reload
298
- }.to_not change { app_const.middleware.size }
299
- end
300
-
301
- it "doesn't duplicate before filters with every reload" do
302
- module ::BeforeFilterExtension
303
- def self.registered(klass)
304
- klass.before { @hi = 'hi' }
305
- end
306
- end
307
-
308
- setup_example_app(
309
- :routes => ['get("/foo") { "foo" }'],
310
- :extensions => ['BeforeFilterExtension']
311
- )
312
-
313
- expect {
314
- update_app_file(
315
- :routes => ['get("/foo") { "foo" }'],
316
- :extensions => ['BeforeFilterExtension']
317
- )
318
- get('/foo') # ...to perform the reload
319
- }.to_not change { app_const.filters[:before].size }
320
- end
321
-
322
- it "doesn't duplicate after filters with every reload" do
323
- module ::AfterFilterExtension
324
- def self.registered(klass)
325
- klass.after { @bye = 'bye' }
326
- end
327
- end
328
-
329
- setup_example_app(
330
- :routes => ['get("/foo") { "foo" }'],
331
- :extensions => ['AfterFilterExtension']
332
- )
333
-
334
- expect {
335
- update_app_file(
336
- :routes => ['get("/foo") { "foo" }'],
337
- :extensions => ['AfterFilterExtension']
338
- )
339
- get('/foo') # ...to perform the reload
340
- }.to_not change { app_const.filters[:after].size }
341
- end
342
- end
343
-
344
- describe ".dont_reload" do
345
- before(:each) do
346
- setup_example_app(
347
- :routes => ['get("/foo") { erb :foo }'],
348
- :inline_templates => { :foo => 'foo' }
349
- )
350
- end
351
-
352
- it "allows to specify a file to stop from being reloaded" do
353
- app_const.dont_reload app_file_path
354
- update_app_file(:routes => ['get("/foo") { "bar" }'])
355
- expect(get('/foo').body.strip).to eq('foo')
356
- end
357
-
358
- it "allows to specify a glob to stop matching files from being reloaded" do
359
- app_const.dont_reload '**/*.rb'
360
- update_app_file(:routes => ['get("/foo") { "bar" }'])
361
- expect(get('/foo').body.strip).to eq('foo')
362
- end
363
-
364
- it "doesn't interfere with other application's reloading policy" do
365
- app_const.dont_reload '**/*.rb'
366
- setup_example_app(:routes => ['get("/foo") { "foo" }'])
367
- update_app_file(:routes => ['get("/foo") { "bar" }'])
368
- expect(get('/foo').body.strip).to eq('bar')
369
- end
370
- end
371
-
372
- describe ".also_reload" do
373
- before(:each) do
374
- setup_example_app(:routes => ['get("/foo") { Foo.foo }'])
375
- @foo_path = File.join(tmp_dir, 'foo.rb')
376
- update_file(@foo_path) do |f|
377
- f.write 'class Foo; def self.foo() "foo" end end'
378
- end
379
- $LOADED_FEATURES.delete @foo_path
380
- require @foo_path
381
- app_const.also_reload @foo_path
382
- end
383
-
384
- it "allows to specify a file to be reloaded" do
385
- expect(get('/foo').body.strip).to eq('foo')
386
- update_file(@foo_path) do |f|
387
- f.write 'class Foo; def self.foo() "bar" end end'
388
- end
389
- expect(get('/foo').body.strip).to eq('bar')
390
- end
391
-
392
- it "allows to specify glob to reaload matching files" do
393
- expect(get('/foo').body.strip).to eq('foo')
394
- update_file(@foo_path) do |f|
395
- f.write 'class Foo; def self.foo() "bar" end end'
396
- end
397
- expect(get('/foo').body.strip).to eq('bar')
398
- end
399
-
400
- it "doesn't try to reload a removed file" do
401
- update_file(@foo_path) do |f|
402
- f.write 'class Foo; def self.foo() "bar" end end'
403
- end
404
- FileUtils.rm @foo_path
405
- expect(get('/foo').body.strip).to eq('foo')
406
- end
407
-
408
- it "doesn't interfere with other application's reloading policy" do
409
- app_const.also_reload '**/*.rb'
410
- setup_example_app(:routes => ['get("/foo") { Foo.foo }'])
411
- expect(get('/foo').body.strip).to eq('foo')
412
- update_file(@foo_path) do |f|
413
- f.write 'class Foo; def self.foo() "bar" end end'
414
- end
415
- expect(get('/foo').body.strip).to eq('foo')
416
- end
417
- end
418
-
419
- describe ".after_reload" do
420
- before(:each) do
421
- setup_example_app(:routes => ['get("/foo") { Foo.foo }'])
422
- @foo_path = File.join(tmp_dir, 'foo.rb')
423
- update_file(@foo_path) do |f|
424
- f.write 'class Foo; def self.foo() "foo" end end'
425
- end
426
- $LOADED_FEATURES.delete @foo_path
427
- require @foo_path
428
- app_const.also_reload @foo_path
429
- end
430
-
431
- it "allows block execution after reloading files" do
432
- app_const.after_reload do
433
- $reloaded = true
434
- end
435
- expect($reloaded).to eq(nil)
436
- expect(get('/foo').body.strip).to eq('foo')
437
- update_file(@foo_path) do |f|
438
- f.write 'class Foo; def self.foo() "bar" end end'
439
- end
440
- expect($reloaded).to eq(true)
441
- end
442
- end
443
-
444
- it "automatically registers the reloader in the subclasses" do
445
- class ::Parent < Sinatra::Base
446
- register Sinatra::Reloader
447
- enable :reloader
448
- end
449
-
450
- setup_example_app(
451
- :routes => ['get("/foo") { "foo" }'],
452
- :enable_reloader => false,
453
- :parent => 'Parent'
454
- )
455
-
456
- update_app_file(
457
- :routes => ['get("/foo") { "bar" }'],
458
- :enable_reloader => false,
459
- :parent => 'Parent'
460
- )
461
-
462
- expect(get('/foo').body).to eq('bar')
463
- end
464
-
465
- end