sinatra 1.3.6 → 1.4.0.a

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of sinatra might be problematic. Click here for more details.

Files changed (71) hide show
  1. data/CHANGES +96 -22
  2. data/Gemfile +11 -3
  3. data/README.de.md +2590 -0
  4. data/README.es.rdoc +66 -38
  5. data/README.fr.md +2630 -0
  6. data/README.hu.rdoc +3 -2
  7. data/README.jp.rdoc +16 -3
  8. data/README.ko.rdoc +11 -5
  9. data/README.md +2699 -0
  10. data/README.pt-br.rdoc +152 -21
  11. data/README.pt-pt.rdoc +3 -2
  12. data/README.ru.md +2724 -0
  13. data/README.zh.rdoc +3 -3
  14. data/Rakefile +3 -4
  15. data/examples/chat.rb +3 -3
  16. data/lib/sinatra/base.rb +433 -247
  17. data/lib/sinatra/main.rb +4 -2
  18. data/lib/sinatra/showexceptions.rb +6 -1
  19. data/lib/sinatra/version.rb +1 -1
  20. data/test/base_test.rb +21 -9
  21. data/test/builder_test.rb +15 -19
  22. data/test/coffee_test.rb +4 -6
  23. data/test/compile_test.rb +154 -0
  24. data/test/contest.rb +4 -6
  25. data/test/creole_test.rb +5 -5
  26. data/test/delegator_test.rb +1 -3
  27. data/test/erb_test.rb +32 -20
  28. data/test/extensions_test.rb +1 -3
  29. data/test/filter_test.rb +65 -56
  30. data/test/haml_test.rb +34 -26
  31. data/test/helpers_test.rb +331 -221
  32. data/test/integration_helper.rb +8 -0
  33. data/test/integration_test.rb +3 -1
  34. data/test/less_test.rb +10 -8
  35. data/test/liquid_test.rb +22 -4
  36. data/test/mapped_error_test.rb +122 -96
  37. data/test/markaby_test.rb +5 -5
  38. data/test/markdown_test.rb +5 -5
  39. data/test/middleware_test.rb +3 -3
  40. data/test/nokogiri_test.rb +4 -6
  41. data/test/rabl_test.rb +89 -0
  42. data/test/radius_test.rb +4 -4
  43. data/test/rdoc_test.rb +7 -7
  44. data/test/readme_test.rb +14 -30
  45. data/test/request_test.rb +15 -0
  46. data/test/response_test.rb +3 -4
  47. data/test/result_test.rb +11 -33
  48. data/test/route_added_hook_test.rb +10 -10
  49. data/test/routing_test.rb +123 -1
  50. data/test/sass_test.rb +26 -26
  51. data/test/scss_test.rb +16 -16
  52. data/test/server_test.rb +2 -2
  53. data/test/settings_test.rb +48 -4
  54. data/test/sinatra_test.rb +2 -7
  55. data/test/slim_test.rb +37 -23
  56. data/test/static_test.rb +56 -15
  57. data/test/streaming_test.rb +11 -2
  58. data/test/templates_test.rb +117 -45
  59. data/test/textile_test.rb +9 -9
  60. data/test/views/hello.rabl +2 -0
  61. data/test/views/hello.wlang +1 -0
  62. data/test/views/hello.yajl +1 -0
  63. data/test/views/layout2.rabl +3 -0
  64. data/test/views/layout2.wlang +2 -0
  65. data/test/wlang_test.rb +87 -0
  66. data/test/yajl_test.rb +86 -0
  67. metadata +27 -17
  68. data/README.de.rdoc +0 -2097
  69. data/README.fr.rdoc +0 -2036
  70. data/README.rdoc +0 -2017
  71. data/README.ru.rdoc +0 -1785
@@ -10,7 +10,7 @@ class HelpersTest < Test::Unit::TestCase
10
10
  code += 2 if [204, 205, 304].include? code
11
11
  block ||= proc { }
12
12
  mock_app do
13
- get '/' do
13
+ get('/') do
14
14
  status code
15
15
  instance_eval(&block).inspect
16
16
  end
@@ -119,36 +119,57 @@ class HelpersTest < Test::Unit::TestCase
119
119
 
120
120
  describe 'body' do
121
121
  it 'takes a block for defered body generation' do
122
- mock_app {
123
- get '/' do
124
- body { 'Hello World' }
125
- end
126
- }
122
+ mock_app do
123
+ get('/') { body { 'Hello World' } }
124
+ end
127
125
 
128
126
  get '/'
129
127
  assert_equal 'Hello World', body
130
128
  end
131
129
 
132
130
  it 'takes a String, Array, or other object responding to #each' do
133
- mock_app {
131
+ mock_app { get('/') { body 'Hello World' } }
132
+
133
+ get '/'
134
+ assert_equal 'Hello World', body
135
+ end
136
+
137
+ it 'can be used with other objects' do
138
+ mock_app do
134
139
  get '/' do
135
- body 'Hello World'
140
+ body :hello => 'from json'
136
141
  end
137
- }
142
+
143
+ after do
144
+ if Hash === response.body
145
+ body response.body[:hello]
146
+ end
147
+ end
148
+ end
138
149
 
139
150
  get '/'
140
- assert_equal 'Hello World', body
151
+ assert_body 'from json'
152
+ end
153
+
154
+ it 'can be set in after filter' do
155
+ mock_app do
156
+ get('/') { body 'route' }
157
+ after { body 'filter' }
158
+ end
159
+
160
+ get '/'
161
+ assert_body 'filter'
141
162
  end
142
163
  end
143
164
 
144
165
  describe 'redirect' do
145
166
  it 'uses a 302 when only a path is given' do
146
- mock_app {
147
- get '/' do
167
+ mock_app do
168
+ get('/') do
148
169
  redirect '/foo'
149
170
  fail 'redirect should halt'
150
171
  end
151
- }
172
+ end
152
173
 
153
174
  get '/'
154
175
  assert_equal 302, status
@@ -157,12 +178,12 @@ class HelpersTest < Test::Unit::TestCase
157
178
  end
158
179
 
159
180
  it 'uses the code given when specified' do
160
- mock_app {
161
- get '/' do
181
+ mock_app do
182
+ get('/') do
162
183
  redirect '/foo', 301
163
184
  fail 'redirect should halt'
164
185
  end
165
- }
186
+ end
166
187
 
167
188
  get '/'
168
189
  assert_equal 301, status
@@ -171,11 +192,7 @@ class HelpersTest < Test::Unit::TestCase
171
192
  end
172
193
 
173
194
  it 'redirects back to request.referer when passed back' do
174
- mock_app {
175
- get '/try_redirect' do
176
- redirect back
177
- end
178
- }
195
+ mock_app { get('/try_redirect') { redirect back } }
179
196
 
180
197
  request = Rack::MockRequest.new(@app)
181
198
  response = request.get('/try_redirect', 'HTTP_REFERER' => '/foo')
@@ -184,11 +201,7 @@ class HelpersTest < Test::Unit::TestCase
184
201
  end
185
202
 
186
203
  it 'redirects using a non-standard HTTP port' do
187
- mock_app {
188
- get '/' do
189
- redirect '/foo'
190
- end
191
- }
204
+ mock_app { get('/') { redirect '/foo' } }
192
205
 
193
206
  request = Rack::MockRequest.new(@app)
194
207
  response = request.get('/', 'SERVER_PORT' => '81')
@@ -196,11 +209,7 @@ class HelpersTest < Test::Unit::TestCase
196
209
  end
197
210
 
198
211
  it 'redirects using a non-standard HTTPS port' do
199
- mock_app {
200
- get '/' do
201
- redirect '/foo'
202
- end
203
- }
212
+ mock_app { get('/') { redirect '/foo' } }
204
213
 
205
214
  request = Rack::MockRequest.new(@app)
206
215
  response = request.get('/', 'SERVER_PORT' => '444')
@@ -209,7 +218,7 @@ class HelpersTest < Test::Unit::TestCase
209
218
 
210
219
  it 'uses 303 for post requests if request is HTTP 1.1' do
211
220
  mock_app { post('/') { redirect '/'} }
212
- post '/', {}, 'HTTP_VERSION' => 'HTTP/1.1'
221
+ post('/', {}, 'HTTP_VERSION' => 'HTTP/1.1')
213
222
  assert_equal 303, status
214
223
  assert_equal '', body
215
224
  assert_equal 'http://example.org/', response['Location']
@@ -217,18 +226,14 @@ class HelpersTest < Test::Unit::TestCase
217
226
 
218
227
  it 'uses 302 for post requests if request is HTTP 1.0' do
219
228
  mock_app { post('/') { redirect '/'} }
220
- post '/', {}, 'HTTP_VERSION' => 'HTTP/1.0'
229
+ post('/', {}, 'HTTP_VERSION' => 'HTTP/1.0')
221
230
  assert_equal 302, status
222
231
  assert_equal '', body
223
232
  assert_equal 'http://example.org/', response['Location']
224
233
  end
225
234
 
226
235
  it 'works behind a reverse proxy' do
227
- mock_app do
228
- get '/' do
229
- redirect '/foo'
230
- end
231
- end
236
+ mock_app { get('/') { redirect '/foo' } }
232
237
 
233
238
  request = Rack::MockRequest.new(@app)
234
239
  response = request.get('/', 'HTTP_X_FORWARDED_HOST' => 'example.com', 'SERVER_PORT' => '8080')
@@ -237,7 +242,7 @@ class HelpersTest < Test::Unit::TestCase
237
242
 
238
243
  it 'accepts absolute URIs' do
239
244
  mock_app do
240
- get '/' do
245
+ get('/') do
241
246
  redirect 'http://google.com'
242
247
  fail 'redirect should halt'
243
248
  end
@@ -251,7 +256,7 @@ class HelpersTest < Test::Unit::TestCase
251
256
 
252
257
  it 'accepts absolute URIs with a different schema' do
253
258
  mock_app do
254
- get '/' do
259
+ get('/') do
255
260
  redirect 'mailto:jsmith@example.com'
256
261
  fail 'redirect should halt'
257
262
  end
@@ -262,16 +267,27 @@ class HelpersTest < Test::Unit::TestCase
262
267
  assert_equal '', body
263
268
  assert_equal 'mailto:jsmith@example.com', response['Location']
264
269
  end
270
+
271
+ it 'accepts a URI object instead of a String' do
272
+ mock_app do
273
+ get('/') { redirect URI.parse('http://sinatrarb.com') }
274
+ end
275
+
276
+ get '/'
277
+ assert_equal 302, status
278
+ assert_equal '', body
279
+ assert_equal 'http://sinatrarb.com', response['Location']
280
+ end
265
281
  end
266
282
 
267
283
  describe 'error' do
268
284
  it 'sets a status code and halts' do
269
- mock_app {
270
- get '/' do
285
+ mock_app do
286
+ get('/') do
271
287
  error 501
272
288
  fail 'error should halt'
273
289
  end
274
- }
290
+ end
275
291
 
276
292
  get '/'
277
293
  assert_equal 501, status
@@ -279,25 +295,103 @@ class HelpersTest < Test::Unit::TestCase
279
295
  end
280
296
 
281
297
  it 'takes an optional body' do
282
- mock_app {
283
- get '/' do
298
+ mock_app do
299
+ get('/') do
284
300
  error 501, 'FAIL'
285
301
  fail 'error should halt'
286
302
  end
287
- }
303
+ end
288
304
 
289
305
  get '/'
290
306
  assert_equal 501, status
291
307
  assert_equal 'FAIL', body
292
308
  end
293
309
 
294
- it 'uses a 500 status code when first argument is a body' do
295
- mock_app {
310
+ it 'should not invoke error handler when setting status inside an error handler' do
311
+ mock_app do
312
+ disable :raise_errors
313
+ not_found do
314
+ body "not_found handler"
315
+ status 404
316
+ end
317
+
318
+ error do
319
+ body "error handler"
320
+ status 404
321
+ end
322
+
323
+ get '/' do
324
+ raise
325
+ end
326
+ end
327
+
328
+ get '/'
329
+ assert_equal 404, status
330
+ assert_equal 'error handler', body
331
+ end
332
+
333
+ it 'should not reset the content-type to html for error handlers' do
334
+ mock_app do
335
+ disable :raise_errors
336
+ before { content_type "application/json;charset=utf-8" }
337
+ not_found { JSON.dump("error" => "Not Found") }
338
+ end
339
+
340
+ get '/'
341
+ assert_equal 404, status
342
+ assert_equal 'application/json;charset=utf-8', response.content_type
343
+ end
344
+
345
+ it 'should not invoke error handler when halting with 500 inside an error handler' do
346
+ mock_app do
347
+ disable :raise_errors
348
+ not_found do
349
+ body "not_found handler"
350
+ halt 404
351
+ end
352
+
353
+ error do
354
+ body "error handler"
355
+ halt 404
356
+ end
357
+
296
358
  get '/' do
359
+ raise
360
+ end
361
+ end
362
+
363
+ get '/'
364
+ assert_equal 404, status
365
+ assert_equal 'error handler', body
366
+ end
367
+
368
+ it 'should not invoke not_found handler when halting with 404 inside a not found handler' do
369
+ mock_app do
370
+ disable :raise_errors
371
+
372
+ not_found do
373
+ body "not_found handler"
374
+ halt 500
375
+ end
376
+
377
+ error do
378
+ body "error handler"
379
+ halt 500
380
+ end
381
+ end
382
+
383
+ get '/'
384
+ assert_equal 500, status
385
+ assert_equal 'not_found handler', body
386
+ end
387
+
388
+ it 'uses a 500 status code when first argument is a body' do
389
+ mock_app do
390
+ get('/') do
297
391
  error 'FAIL'
298
392
  fail 'error should halt'
299
393
  end
300
- }
394
+ end
301
395
 
302
396
  get '/'
303
397
  assert_equal 500, status
@@ -307,12 +401,12 @@ class HelpersTest < Test::Unit::TestCase
307
401
 
308
402
  describe 'not_found' do
309
403
  it 'halts with a 404 status' do
310
- mock_app {
311
- get '/' do
404
+ mock_app do
405
+ get('/') do
312
406
  not_found
313
407
  fail 'not_found should halt'
314
408
  end
315
- }
409
+ end
316
410
 
317
411
  get '/'
318
412
  assert_equal 404, status
@@ -320,12 +414,12 @@ class HelpersTest < Test::Unit::TestCase
320
414
  end
321
415
 
322
416
  it 'does not set a X-Cascade header' do
323
- mock_app {
324
- get '/' do
417
+ mock_app do
418
+ get('/') do
325
419
  not_found
326
420
  fail 'not_found should halt'
327
421
  end
328
- }
422
+ end
329
423
 
330
424
  get '/'
331
425
  assert_equal 404, status
@@ -335,12 +429,12 @@ class HelpersTest < Test::Unit::TestCase
335
429
 
336
430
  describe 'headers' do
337
431
  it 'sets headers on the response object when given a Hash' do
338
- mock_app {
339
- get '/' do
432
+ mock_app do
433
+ get('/') do
340
434
  headers 'X-Foo' => 'bar', 'X-Baz' => 'bling'
341
435
  'kthx'
342
436
  end
343
- }
437
+ end
344
438
 
345
439
  get '/'
346
440
  assert ok?
@@ -350,12 +444,12 @@ class HelpersTest < Test::Unit::TestCase
350
444
  end
351
445
 
352
446
  it 'returns the response headers hash when no hash provided' do
353
- mock_app {
354
- get '/' do
447
+ mock_app do
448
+ get('/') do
355
449
  headers['X-Foo'] = 'bar'
356
450
  'kthx'
357
451
  end
358
- }
452
+ end
359
453
 
360
454
  get '/'
361
455
  assert ok?
@@ -365,30 +459,30 @@ class HelpersTest < Test::Unit::TestCase
365
459
 
366
460
  describe 'session' do
367
461
  it 'uses the existing rack.session' do
368
- mock_app {
369
- get '/' do
462
+ mock_app do
463
+ get('/') do
370
464
  session[:foo]
371
465
  end
372
- }
466
+ end
373
467
 
374
- get '/', {}, { 'rack.session' => { :foo => 'bar' } }
468
+ get('/', {}, { 'rack.session' => { :foo => 'bar' } })
375
469
  assert_equal 'bar', body
376
470
  end
377
471
 
378
472
  it 'creates a new session when none provided' do
379
- mock_app {
473
+ mock_app do
380
474
  enable :sessions
381
475
 
382
- get '/' do
476
+ get('/') do
383
477
  assert session[:foo].nil?
384
478
  session[:foo] = 'bar'
385
479
  redirect '/hi'
386
480
  end
387
481
 
388
- get '/hi' do
482
+ get('/hi') do
389
483
  "hi #{session[:foo]}"
390
484
  end
391
- }
485
+ end
392
486
 
393
487
  get '/'
394
488
  follow_redirect!
@@ -398,7 +492,8 @@ class HelpersTest < Test::Unit::TestCase
398
492
  it 'inserts session middleware' do
399
493
  mock_app do
400
494
  enable :sessions
401
- get '/' do
495
+
496
+ get('/') do
402
497
  assert env['rack.session']
403
498
  assert env['rack.session.options']
404
499
  'ok'
@@ -412,7 +507,8 @@ class HelpersTest < Test::Unit::TestCase
412
507
  it 'sets a default session secret' do
413
508
  mock_app do
414
509
  enable :sessions
415
- get '/' do
510
+
511
+ get('/') do
416
512
  secret = env['rack.session.options'][:secret]
417
513
  assert secret
418
514
  assert_equal secret, settings.session_secret
@@ -428,23 +524,22 @@ class HelpersTest < Test::Unit::TestCase
428
524
  mock_app do
429
525
  enable :sessions
430
526
  disable :session_secret
431
- get '/' do
527
+
528
+ get('/') do
432
529
  assert !env['rack.session.options'].include?(:session_secret)
433
530
  'ok'
434
531
  end
435
532
  end
436
533
 
437
- # Silence warnings since Rack::Session::Cookie complains about the non-present session secret
438
- silence_warnings do
439
- get '/'
440
- end
534
+ get '/'
441
535
  assert_body 'ok'
442
536
  end
443
537
 
444
538
  it 'accepts an options hash' do
445
539
  mock_app do
446
540
  set :sessions, :foo => :bar
447
- get '/' do
541
+
542
+ get('/') do
448
543
  assert_equal env['rack.session.options'][:foo], :bar
449
544
  'ok'
450
545
  end
@@ -479,13 +574,13 @@ class HelpersTest < Test::Unit::TestCase
479
574
  end
480
575
 
481
576
  test 'Base.mime_type registers mime type' do
482
- mock_app {
577
+ mock_app do
483
578
  mime_type :foo, 'application/foo'
484
579
 
485
- get '/' do
580
+ get('/') do
486
581
  "foo is #{mime_type(:foo)}"
487
582
  end
488
- }
583
+ end
489
584
 
490
585
  get '/'
491
586
  assert_equal 'foo is application/foo', body
@@ -493,12 +588,12 @@ class HelpersTest < Test::Unit::TestCase
493
588
 
494
589
  describe 'content_type' do
495
590
  it 'sets the Content-Type header' do
496
- mock_app {
497
- get '/' do
591
+ mock_app do
592
+ get('/') do
498
593
  content_type 'text/plain'
499
594
  'Hello World'
500
595
  end
501
- }
596
+ end
502
597
 
503
598
  get '/'
504
599
  assert_equal 'text/plain;charset=utf-8', response['Content-Type']
@@ -506,12 +601,12 @@ class HelpersTest < Test::Unit::TestCase
506
601
  end
507
602
 
508
603
  it 'takes media type parameters (like charset=)' do
509
- mock_app {
510
- get '/' do
604
+ mock_app do
605
+ get('/') do
511
606
  content_type 'text/html', :charset => 'latin1'
512
607
  "<h1>Hello, World</h1>"
513
608
  end
514
- }
609
+ end
515
610
 
516
611
  get '/'
517
612
  assert ok?
@@ -521,12 +616,12 @@ class HelpersTest < Test::Unit::TestCase
521
616
 
522
617
  it "looks up symbols in Rack's mime types dictionary" do
523
618
  Rack::Mime::MIME_TYPES['.foo'] = 'application/foo'
524
- mock_app {
525
- get '/foo.xml' do
619
+ mock_app do
620
+ get('/foo.xml') do
526
621
  content_type :foo
527
622
  "I AM FOO"
528
623
  end
529
- }
624
+ end
530
625
 
531
626
  get '/foo.xml'
532
627
  assert ok?
@@ -535,12 +630,12 @@ class HelpersTest < Test::Unit::TestCase
535
630
  end
536
631
 
537
632
  it 'fails when no mime type is registered for the argument provided' do
538
- mock_app {
539
- get '/foo.xml' do
633
+ mock_app do
634
+ get('/foo.xml') do
540
635
  content_type :bizzle
541
636
  "I AM FOO"
542
637
  end
543
- }
638
+ end
544
639
 
545
640
  assert_raise(RuntimeError) { get '/foo.xml' }
546
641
  end
@@ -552,7 +647,7 @@ class HelpersTest < Test::Unit::TestCase
552
647
  mime_type :bar, 'application/bar'
553
648
  mime_type :baz, 'application/baz'
554
649
  add_charset << mime_type(:baz)
555
- get '/' do
650
+ get('/') do
556
651
  assert_equal content_type(:txt), 'text/plain;charset=utf-8'
557
652
  assert_equal content_type(:css), 'text/css;charset=utf-8'
558
653
  assert_equal content_type(:html), 'text/html;charset=utf-8'
@@ -568,70 +663,97 @@ class HelpersTest < Test::Unit::TestCase
568
663
  "done"
569
664
  end
570
665
  end
666
+
571
667
  get '/'
572
668
  assert tests_ran
573
669
  end
574
670
 
575
671
  it 'handles already present params' do
576
672
  mock_app do
577
- get '/' do
673
+ get('/') do
578
674
  content_type 'foo/bar;level=1', :charset => 'utf-8'
579
675
  'ok'
580
676
  end
581
677
  end
678
+
582
679
  get '/'
583
680
  assert_equal 'foo/bar;level=1, charset=utf-8', response['Content-Type']
584
681
  end
585
682
 
586
683
  it 'does not add charset if present' do
587
684
  mock_app do
588
- get '/' do
685
+ get('/') do
589
686
  content_type 'text/plain;charset=utf-16'
590
687
  'ok'
591
688
  end
592
689
  end
690
+
593
691
  get '/'
594
692
  assert_equal 'text/plain;charset=utf-16', response['Content-Type']
595
693
  end
694
+
695
+ it 'properly encodes parameters with delimiter characters' do
696
+ mock_app do
697
+ before '/comma' do
698
+ content_type 'image/png', :comment => 'Hello, world!'
699
+ end
700
+ before '/semicolon' do
701
+ content_type 'image/png', :comment => 'semi;colon'
702
+ end
703
+ before '/quote' do
704
+ content_type 'image/png', :comment => '"Whatever."'
705
+ end
706
+
707
+ get('*') { 'ok' }
708
+ end
709
+
710
+ get '/comma'
711
+ assert_equal 'image/png;comment="Hello, world!"', response['Content-Type']
712
+ get '/semicolon'
713
+ assert_equal 'image/png;comment="semi;colon"', response['Content-Type']
714
+ get '/quote'
715
+ assert_equal 'image/png;comment="\"Whatever.\""', response['Content-Type']
716
+ end
596
717
  end
597
718
 
598
719
  describe 'attachment' do
599
720
  def attachment_app(filename=nil)
600
- mock_app {
601
- get '/attachment' do
721
+ mock_app do
722
+ get('/attachment') do
602
723
  attachment filename
603
724
  response.write("<sinatra></sinatra>")
604
725
  end
605
- }
726
+ end
606
727
  end
607
-
728
+
608
729
  it 'sets the Content-Type response header' do
609
730
  attachment_app('test.xml')
610
731
  get '/attachment'
611
732
  assert_equal 'application/xml;charset=utf-8', response['Content-Type']
612
733
  assert_equal '<sinatra></sinatra>', body
613
- end
614
-
734
+ end
735
+
615
736
  it 'sets the Content-Type response header without extname' do
616
737
  attachment_app('test')
617
738
  get '/attachment'
618
739
  assert_equal 'text/html;charset=utf-8', response['Content-Type']
619
- assert_equal '<sinatra></sinatra>', body
740
+ assert_equal '<sinatra></sinatra>', body
620
741
  end
621
-
742
+
622
743
  it 'sets the Content-Type response header with extname' do
623
744
  mock_app do
624
- get '/attachment' do
745
+ get('/attachment') do
625
746
  content_type :atom
626
747
  attachment 'test.xml'
627
748
  response.write("<sinatra></sinatra>")
628
749
  end
629
750
  end
751
+
630
752
  get '/attachment'
631
753
  assert_equal 'application/atom+xml', response['Content-Type']
632
- assert_equal '<sinatra></sinatra>', body
754
+ assert_equal '<sinatra></sinatra>', body
633
755
  end
634
-
756
+
635
757
  end
636
758
 
637
759
  describe 'send_file' do
@@ -700,9 +822,7 @@ class HelpersTest < Test::Unit::TestCase
700
822
 
701
823
  it "returns a 404 when not found" do
702
824
  mock_app {
703
- get '/' do
704
- send_file 'this-file-does-not-exist.txt'
705
- end
825
+ get('/') { send_file 'this-file-does-not-exist.txt' }
706
826
  }
707
827
  get '/'
708
828
  assert not_found?
@@ -720,10 +840,16 @@ class HelpersTest < Test::Unit::TestCase
720
840
  assert_equal 'attachment; filename="file.txt"', response['Content-Disposition']
721
841
  end
722
842
 
843
+ it "does not set add a file name if filename is false" do
844
+ send_file_app :disposition => 'inline', :filename => false
845
+ get '/file.txt'
846
+ assert_equal 'inline', response['Content-Disposition']
847
+ end
848
+
723
849
  it "sets the Content-Disposition header when :disposition set to 'inline'" do
724
850
  send_file_app :disposition => 'inline'
725
851
  get '/file.txt'
726
- assert_equal 'inline', response['Content-Disposition']
852
+ assert_equal 'inline; filename="file.txt"', response['Content-Disposition']
727
853
  end
728
854
 
729
855
  it "sets the Content-Disposition header when :filename provided" do
@@ -732,6 +858,12 @@ class HelpersTest < Test::Unit::TestCase
732
858
  assert_equal 'attachment; filename="foo.txt"', response['Content-Disposition']
733
859
  end
734
860
 
861
+ it 'allows setting a custom status code' do
862
+ send_file_app :status => 201
863
+ get '/file.txt'
864
+ assert_status 201
865
+ end
866
+
735
867
  it "is able to send files with unkown mime type" do
736
868
  @file = File.dirname(__FILE__) + '/file.foobar'
737
869
  File.open(@file, 'wb') { |io| io.write('Hello World') }
@@ -743,7 +875,7 @@ class HelpersTest < Test::Unit::TestCase
743
875
  it "does not override Content-Type if already set and no explicit type is given" do
744
876
  path = @file
745
877
  mock_app do
746
- get '/' do
878
+ get('/') do
747
879
  content_type :png
748
880
  send_file path
749
881
  end
@@ -755,7 +887,7 @@ class HelpersTest < Test::Unit::TestCase
755
887
  it "does override Content-Type even if already set, if explicit type is given" do
756
888
  path = @file
757
889
  mock_app do
758
- get '/' do
890
+ get('/') do
759
891
  content_type :png
760
892
  send_file path, :type => :gif
761
893
  end
@@ -768,12 +900,12 @@ class HelpersTest < Test::Unit::TestCase
768
900
  describe 'cache_control' do
769
901
  setup do
770
902
  mock_app do
771
- get '/foo' do
903
+ get('/foo') do
772
904
  cache_control :public, :no_cache, :max_age => 60.0
773
905
  'Hello World'
774
906
  end
775
907
 
776
- get '/bar' do
908
+ get('/bar') do
777
909
  cache_control :public, :no_cache
778
910
  'Hello World'
779
911
  end
@@ -794,20 +926,16 @@ class HelpersTest < Test::Unit::TestCase
794
926
  describe 'expires' do
795
927
  setup do
796
928
  mock_app do
797
- get '/foo' do
929
+ get('/foo') do
798
930
  expires 60, :public, :no_cache
799
931
  'Hello World'
800
932
  end
801
933
 
802
- get '/bar' do
803
- expires Time.now
804
- end
934
+ get('/bar') { expires Time.now }
805
935
 
806
- get '/baz' do
807
- expires Time.at(0)
808
- end
936
+ get('/baz') { expires Time.at(0) }
809
937
 
810
- get '/blah' do
938
+ get('/blah') do
811
939
  obj = Object.new
812
940
  def obj.method_missing(*a, &b) 60.send(*a, &b) end
813
941
  def obj.is_a?(thing) 60.is_a?(thing) end
@@ -815,9 +943,7 @@ class HelpersTest < Test::Unit::TestCase
815
943
  'Hello World'
816
944
  end
817
945
 
818
- get '/boom' do
819
- expires '9999'
820
- end
946
+ get('/boom') { expires '9999' }
821
947
  end
822
948
  end
823
949
 
@@ -853,9 +979,7 @@ class HelpersTest < Test::Unit::TestCase
853
979
 
854
980
  describe 'last_modified' do
855
981
  it 'ignores nil' do
856
- mock_app do
857
- get '/' do last_modified nil; 200; end
858
- end
982
+ mock_app { get('/') { last_modified nil; 200; } }
859
983
 
860
984
  get '/'
861
985
  assert ! response['Last-Modified']
@@ -863,7 +987,7 @@ class HelpersTest < Test::Unit::TestCase
863
987
 
864
988
  it 'does not change a status other than 200' do
865
989
  mock_app do
866
- get '/' do
990
+ get('/') do
867
991
  status 299
868
992
  last_modified Time.at(0)
869
993
  'ok'
@@ -880,7 +1004,7 @@ class HelpersTest < Test::Unit::TestCase
880
1004
  describe "with #{last_modified_time.class.name}" do
881
1005
  setup do
882
1006
  mock_app do
883
- get '/' do
1007
+ get('/') do
884
1008
  last_modified last_modified_time
885
1009
  'Boo!'
886
1010
  end
@@ -907,12 +1031,12 @@ class HelpersTest < Test::Unit::TestCase
907
1031
 
908
1032
  context "when there's an invalid If-Modified-Since header" do
909
1033
  it 'sets the Last-Modified header to a valid RFC 2616 date value' do
910
- get '/', {}, { 'HTTP_IF_MODIFIED_SINCE' => 'a really weird date' }
1034
+ get('/', {}, { 'HTTP_IF_MODIFIED_SINCE' => 'a really weird date' })
911
1035
  assert_equal @last_modified_time.httpdate, response['Last-Modified']
912
1036
  end
913
1037
 
914
1038
  it 'conditional GET misses and returns a body' do
915
- get '/', {}, { 'HTTP_IF_MODIFIED_SINCE' => 'a really weird date' }
1039
+ get('/', {}, { 'HTTP_IF_MODIFIED_SINCE' => 'a really weird date' })
916
1040
  assert_equal 200, status
917
1041
  assert_equal 'Boo!', body
918
1042
  end
@@ -920,28 +1044,28 @@ class HelpersTest < Test::Unit::TestCase
920
1044
 
921
1045
  context "when the resource has been modified since the If-Modified-Since header date" do
922
1046
  it 'sets the Last-Modified header to a valid RFC 2616 date value' do
923
- get '/', {}, { 'HTTP_IF_MODIFIED_SINCE' => (@last_modified_time - 1).httpdate }
1047
+ get('/', {}, { 'HTTP_IF_MODIFIED_SINCE' => (@last_modified_time - 1).httpdate })
924
1048
  assert_equal @last_modified_time.httpdate, response['Last-Modified']
925
1049
  end
926
1050
 
927
1051
  it 'conditional GET misses and returns a body' do
928
- get '/', {}, { 'HTTP_IF_MODIFIED_SINCE' => (@last_modified_time - 1).httpdate }
1052
+ get('/', {}, { 'HTTP_IF_MODIFIED_SINCE' => (@last_modified_time - 1).httpdate })
929
1053
  assert_equal 200, status
930
1054
  assert_equal 'Boo!', body
931
1055
  end
932
1056
 
933
1057
  it 'does not rely on string comparison' do
934
1058
  mock_app do
935
- get '/compare' do
1059
+ get('/compare') do
936
1060
  last_modified "Mon, 18 Oct 2010 20:57:11 GMT"
937
1061
  "foo"
938
1062
  end
939
1063
  end
940
1064
 
941
- get '/compare', {}, { 'HTTP_IF_MODIFIED_SINCE' => 'Sun, 26 Sep 2010 23:43:52 GMT' }
1065
+ get('/compare', {}, { 'HTTP_IF_MODIFIED_SINCE' => 'Sun, 26 Sep 2010 23:43:52 GMT' })
942
1066
  assert_equal 200, status
943
1067
  assert_equal 'foo', body
944
- get '/compare', {}, { 'HTTP_IF_MODIFIED_SINCE' => 'Sun, 26 Sep 2030 23:43:52 GMT' }
1068
+ get('/compare', {}, { 'HTTP_IF_MODIFIED_SINCE' => 'Sun, 26 Sep 2030 23:43:52 GMT' })
945
1069
  assert_equal 304, status
946
1070
  assert_equal '', body
947
1071
  end
@@ -949,12 +1073,12 @@ class HelpersTest < Test::Unit::TestCase
949
1073
 
950
1074
  context "when the resource has been modified on the exact If-Modified-Since header date" do
951
1075
  it 'sets the Last-Modified header to a valid RFC 2616 date value' do
952
- get '/', {}, { 'HTTP_IF_MODIFIED_SINCE' => @last_modified_time.httpdate }
1076
+ get('/', {}, { 'HTTP_IF_MODIFIED_SINCE' => @last_modified_time.httpdate })
953
1077
  assert_equal @last_modified_time.httpdate, response['Last-Modified']
954
1078
  end
955
1079
 
956
1080
  it 'conditional GET matches and halts' do
957
- get '/', {}, { 'HTTP_IF_MODIFIED_SINCE' => @last_modified_time.httpdate }
1081
+ get( '/', {}, { 'HTTP_IF_MODIFIED_SINCE' => @last_modified_time.httpdate })
958
1082
  assert_equal 304, status
959
1083
  assert_equal '', body
960
1084
  end
@@ -962,12 +1086,12 @@ class HelpersTest < Test::Unit::TestCase
962
1086
 
963
1087
  context "when the resource hasn't been modified since the If-Modified-Since header date" do
964
1088
  it 'sets the Last-Modified header to a valid RFC 2616 date value' do
965
- get '/', {}, { 'HTTP_IF_MODIFIED_SINCE' => (@last_modified_time + 1).httpdate }
1089
+ get('/', {}, { 'HTTP_IF_MODIFIED_SINCE' => (@last_modified_time + 1).httpdate })
966
1090
  assert_equal @last_modified_time.httpdate, response['Last-Modified']
967
1091
  end
968
1092
 
969
1093
  it 'conditional GET matches and halts' do
970
- get '/', {}, { 'HTTP_IF_MODIFIED_SINCE' => (@last_modified_time + 1).httpdate }
1094
+ get('/', {}, { 'HTTP_IF_MODIFIED_SINCE' => (@last_modified_time + 1).httpdate })
971
1095
  assert_equal 304, status
972
1096
  assert_equal '', body
973
1097
  end
@@ -975,13 +1099,13 @@ class HelpersTest < Test::Unit::TestCase
975
1099
 
976
1100
  context "If-Unmodified-Since" do
977
1101
  it 'results in 200 if resource has not been modified' do
978
- get '/', {}, { 'HTTP_IF_UNMODIFIED_SINCE' => 'Sun, 26 Sep 2030 23:43:52 GMT' }
1102
+ get('/', {}, { 'HTTP_IF_UNMODIFIED_SINCE' => 'Sun, 26 Sep 2030 23:43:52 GMT' })
979
1103
  assert_equal 200, status
980
1104
  assert_equal 'Boo!', body
981
1105
  end
982
1106
 
983
1107
  it 'results in 412 if resource has been modified' do
984
- get '/', {}, { 'HTTP_IF_UNMODIFIED_SINCE' => Time.at(0).httpdate }
1108
+ get('/', {}, { 'HTTP_IF_UNMODIFIED_SINCE' => Time.at(0).httpdate })
985
1109
  assert_equal 412, status
986
1110
  assert_equal '', body
987
1111
  end
@@ -994,13 +1118,13 @@ class HelpersTest < Test::Unit::TestCase
994
1118
  context "safe requests" do
995
1119
  it 'returns 200 for normal requests' do
996
1120
  mock_app do
997
- get '/' do
1121
+ get('/') do
998
1122
  etag 'foo'
999
1123
  'ok'
1000
1124
  end
1001
1125
  end
1002
1126
 
1003
- get('/')
1127
+ get '/'
1004
1128
  assert_status 200
1005
1129
  assert_body 'ok'
1006
1130
  end
@@ -1008,7 +1132,7 @@ class HelpersTest < Test::Unit::TestCase
1008
1132
  context "If-None-Match" do
1009
1133
  it 'returns 304 when If-None-Match is *' do
1010
1134
  mock_app do
1011
- get '/' do
1135
+ get('/') do
1012
1136
  etag 'foo'
1013
1137
  'ok'
1014
1138
  end
@@ -1021,7 +1145,7 @@ class HelpersTest < Test::Unit::TestCase
1021
1145
 
1022
1146
  it 'returns 200 when If-None-Match is * for new resources' do
1023
1147
  mock_app do
1024
- get '/' do
1148
+ get('/') do
1025
1149
  etag 'foo', :new_resource => true
1026
1150
  'ok'
1027
1151
  end
@@ -1034,7 +1158,7 @@ class HelpersTest < Test::Unit::TestCase
1034
1158
 
1035
1159
  it 'returns 304 when If-None-Match is * for existing resources' do
1036
1160
  mock_app do
1037
- get '/' do
1161
+ get('/') do
1038
1162
  etag 'foo', :new_resource => false
1039
1163
  'ok'
1040
1164
  end
@@ -1047,7 +1171,7 @@ class HelpersTest < Test::Unit::TestCase
1047
1171
 
1048
1172
  it 'returns 304 when If-None-Match is the etag' do
1049
1173
  mock_app do
1050
- get '/' do
1174
+ get('/') do
1051
1175
  etag 'foo'
1052
1176
  'ok'
1053
1177
  end
@@ -1060,7 +1184,7 @@ class HelpersTest < Test::Unit::TestCase
1060
1184
 
1061
1185
  it 'returns 304 when If-None-Match includes the etag' do
1062
1186
  mock_app do
1063
- get '/' do
1187
+ get('/') do
1064
1188
  etag 'foo'
1065
1189
  'ok'
1066
1190
  end
@@ -1073,7 +1197,7 @@ class HelpersTest < Test::Unit::TestCase
1073
1197
 
1074
1198
  it 'returns 200 when If-None-Match does not include the etag' do
1075
1199
  mock_app do
1076
- get '/' do
1200
+ get('/') do
1077
1201
  etag 'foo'
1078
1202
  'ok'
1079
1203
  end
@@ -1086,7 +1210,7 @@ class HelpersTest < Test::Unit::TestCase
1086
1210
 
1087
1211
  it 'ignores If-Modified-Since if If-None-Match does not match' do
1088
1212
  mock_app do
1089
- get '/' do
1213
+ get('/') do
1090
1214
  etag 'foo'
1091
1215
  last_modified Time.at(0)
1092
1216
  'ok'
@@ -1100,7 +1224,7 @@ class HelpersTest < Test::Unit::TestCase
1100
1224
 
1101
1225
  it 'does not change a status code other than 2xx or 304' do
1102
1226
  mock_app do
1103
- get '/' do
1227
+ get('/') do
1104
1228
  status 499
1105
1229
  etag 'foo'
1106
1230
  'ok'
@@ -1114,7 +1238,7 @@ class HelpersTest < Test::Unit::TestCase
1114
1238
 
1115
1239
  it 'does change 2xx status codes' do
1116
1240
  mock_app do
1117
- get '/' do
1241
+ get('/') do
1118
1242
  status 299
1119
1243
  etag 'foo'
1120
1244
  'ok'
@@ -1128,7 +1252,7 @@ class HelpersTest < Test::Unit::TestCase
1128
1252
 
1129
1253
  it 'does not send a body on 304 status codes' do
1130
1254
  mock_app do
1131
- get '/' do
1255
+ get('/') do
1132
1256
  status 304
1133
1257
  etag 'foo'
1134
1258
  'ok'
@@ -1144,7 +1268,7 @@ class HelpersTest < Test::Unit::TestCase
1144
1268
  context "If-Match" do
1145
1269
  it 'returns 200 when If-Match is the etag' do
1146
1270
  mock_app do
1147
- get '/' do
1271
+ get('/') do
1148
1272
  etag 'foo'
1149
1273
  'ok'
1150
1274
  end
@@ -1157,7 +1281,7 @@ class HelpersTest < Test::Unit::TestCase
1157
1281
 
1158
1282
  it 'returns 200 when If-Match includes the etag' do
1159
1283
  mock_app do
1160
- get '/' do
1284
+ get('/') do
1161
1285
  etag 'foo'
1162
1286
  'ok'
1163
1287
  end
@@ -1170,7 +1294,7 @@ class HelpersTest < Test::Unit::TestCase
1170
1294
 
1171
1295
  it 'returns 200 when If-Match is *' do
1172
1296
  mock_app do
1173
- get '/' do
1297
+ get('/') do
1174
1298
  etag 'foo'
1175
1299
  'ok'
1176
1300
  end
@@ -1183,7 +1307,7 @@ class HelpersTest < Test::Unit::TestCase
1183
1307
 
1184
1308
  it 'returns 412 when If-Match is * for new resources' do
1185
1309
  mock_app do
1186
- get '/' do
1310
+ get('/') do
1187
1311
  etag 'foo', :new_resource => true
1188
1312
  'ok'
1189
1313
  end
@@ -1196,7 +1320,7 @@ class HelpersTest < Test::Unit::TestCase
1196
1320
 
1197
1321
  it 'returns 200 when If-Match is * for existing resources' do
1198
1322
  mock_app do
1199
- get '/' do
1323
+ get('/') do
1200
1324
  etag 'foo', :new_resource => false
1201
1325
  'ok'
1202
1326
  end
@@ -1209,7 +1333,7 @@ class HelpersTest < Test::Unit::TestCase
1209
1333
 
1210
1334
  it 'returns 412 when If-Match does not include the etag' do
1211
1335
  mock_app do
1212
- get '/' do
1336
+ get('/') do
1213
1337
  etag 'foo'
1214
1338
  'ok'
1215
1339
  end
@@ -1225,13 +1349,13 @@ class HelpersTest < Test::Unit::TestCase
1225
1349
  context "idempotent requests" do
1226
1350
  it 'returns 200 for normal requests' do
1227
1351
  mock_app do
1228
- put '/' do
1352
+ put('/') do
1229
1353
  etag 'foo'
1230
1354
  'ok'
1231
1355
  end
1232
1356
  end
1233
1357
 
1234
- put('/')
1358
+ put '/'
1235
1359
  assert_status 200
1236
1360
  assert_body 'ok'
1237
1361
  end
@@ -1239,7 +1363,7 @@ class HelpersTest < Test::Unit::TestCase
1239
1363
  context "If-None-Match" do
1240
1364
  it 'returns 412 when If-None-Match is *' do
1241
1365
  mock_app do
1242
- put '/' do
1366
+ put('/') do
1243
1367
  etag 'foo'
1244
1368
  'ok'
1245
1369
  end
@@ -1252,7 +1376,7 @@ class HelpersTest < Test::Unit::TestCase
1252
1376
 
1253
1377
  it 'returns 200 when If-None-Match is * for new resources' do
1254
1378
  mock_app do
1255
- put '/' do
1379
+ put('/') do
1256
1380
  etag 'foo', :new_resource => true
1257
1381
  'ok'
1258
1382
  end
@@ -1265,7 +1389,7 @@ class HelpersTest < Test::Unit::TestCase
1265
1389
 
1266
1390
  it 'returns 412 when If-None-Match is * for existing resources' do
1267
1391
  mock_app do
1268
- put '/' do
1392
+ put('/') do
1269
1393
  etag 'foo', :new_resource => false
1270
1394
  'ok'
1271
1395
  end
@@ -1291,7 +1415,7 @@ class HelpersTest < Test::Unit::TestCase
1291
1415
 
1292
1416
  it 'returns 412 when If-None-Match includes the etag' do
1293
1417
  mock_app do
1294
- put '/' do
1418
+ put('/') do
1295
1419
  etag 'foo'
1296
1420
  'ok'
1297
1421
  end
@@ -1304,7 +1428,7 @@ class HelpersTest < Test::Unit::TestCase
1304
1428
 
1305
1429
  it 'returns 200 when If-None-Match does not include the etag' do
1306
1430
  mock_app do
1307
- put '/' do
1431
+ put('/') do
1308
1432
  etag 'foo'
1309
1433
  'ok'
1310
1434
  end
@@ -1317,7 +1441,7 @@ class HelpersTest < Test::Unit::TestCase
1317
1441
 
1318
1442
  it 'ignores If-Modified-Since if If-None-Match does not match' do
1319
1443
  mock_app do
1320
- put '/' do
1444
+ put('/') do
1321
1445
  etag 'foo'
1322
1446
  last_modified Time.at(0)
1323
1447
  'ok'
@@ -1333,7 +1457,7 @@ class HelpersTest < Test::Unit::TestCase
1333
1457
  context "If-Match" do
1334
1458
  it 'returns 200 when If-Match is the etag' do
1335
1459
  mock_app do
1336
- put '/' do
1460
+ put('/') do
1337
1461
  etag 'foo'
1338
1462
  'ok'
1339
1463
  end
@@ -1346,7 +1470,7 @@ class HelpersTest < Test::Unit::TestCase
1346
1470
 
1347
1471
  it 'returns 200 when If-Match includes the etag' do
1348
1472
  mock_app do
1349
- put '/' do
1473
+ put('/') do
1350
1474
  etag 'foo'
1351
1475
  'ok'
1352
1476
  end
@@ -1359,7 +1483,7 @@ class HelpersTest < Test::Unit::TestCase
1359
1483
 
1360
1484
  it 'returns 200 when If-Match is *' do
1361
1485
  mock_app do
1362
- put '/' do
1486
+ put('/') do
1363
1487
  etag 'foo'
1364
1488
  'ok'
1365
1489
  end
@@ -1372,7 +1496,7 @@ class HelpersTest < Test::Unit::TestCase
1372
1496
 
1373
1497
  it 'returns 412 when If-Match is * for new resources' do
1374
1498
  mock_app do
1375
- put '/' do
1499
+ put('/') do
1376
1500
  etag 'foo', :new_resource => true
1377
1501
  'ok'
1378
1502
  end
@@ -1385,7 +1509,7 @@ class HelpersTest < Test::Unit::TestCase
1385
1509
 
1386
1510
  it 'returns 200 when If-Match is * for existing resources' do
1387
1511
  mock_app do
1388
- put '/' do
1512
+ put('/') do
1389
1513
  etag 'foo', :new_resource => false
1390
1514
  'ok'
1391
1515
  end
@@ -1398,7 +1522,7 @@ class HelpersTest < Test::Unit::TestCase
1398
1522
 
1399
1523
  it 'returns 412 when If-Match does not include the etag' do
1400
1524
  mock_app do
1401
- put '/' do
1525
+ put('/') do
1402
1526
  etag 'foo'
1403
1527
  'ok'
1404
1528
  end
@@ -1414,7 +1538,7 @@ class HelpersTest < Test::Unit::TestCase
1414
1538
  context "post requests" do
1415
1539
  it 'returns 200 for normal requests' do
1416
1540
  mock_app do
1417
- post '/' do
1541
+ post('/') do
1418
1542
  etag 'foo'
1419
1543
  'ok'
1420
1544
  end
@@ -1428,7 +1552,7 @@ class HelpersTest < Test::Unit::TestCase
1428
1552
  context "If-None-Match" do
1429
1553
  it 'returns 200 when If-None-Match is *' do
1430
1554
  mock_app do
1431
- post '/' do
1555
+ post('/') do
1432
1556
  etag 'foo'
1433
1557
  'ok'
1434
1558
  end
@@ -1441,7 +1565,7 @@ class HelpersTest < Test::Unit::TestCase
1441
1565
 
1442
1566
  it 'returns 200 when If-None-Match is * for new resources' do
1443
1567
  mock_app do
1444
- post '/' do
1568
+ post('/') do
1445
1569
  etag 'foo', :new_resource => true
1446
1570
  'ok'
1447
1571
  end
@@ -1454,7 +1578,7 @@ class HelpersTest < Test::Unit::TestCase
1454
1578
 
1455
1579
  it 'returns 412 when If-None-Match is * for existing resources' do
1456
1580
  mock_app do
1457
- post '/' do
1581
+ post('/') do
1458
1582
  etag 'foo', :new_resource => false
1459
1583
  'ok'
1460
1584
  end
@@ -1467,7 +1591,7 @@ class HelpersTest < Test::Unit::TestCase
1467
1591
 
1468
1592
  it 'returns 412 when If-None-Match is the etag' do
1469
1593
  mock_app do
1470
- post '/' do
1594
+ post('/') do
1471
1595
  etag 'foo'
1472
1596
  'ok'
1473
1597
  end
@@ -1480,7 +1604,7 @@ class HelpersTest < Test::Unit::TestCase
1480
1604
 
1481
1605
  it 'returns 412 when If-None-Match includes the etag' do
1482
1606
  mock_app do
1483
- post '/' do
1607
+ post('/') do
1484
1608
  etag 'foo'
1485
1609
  'ok'
1486
1610
  end
@@ -1493,7 +1617,7 @@ class HelpersTest < Test::Unit::TestCase
1493
1617
 
1494
1618
  it 'returns 200 when If-None-Match does not include the etag' do
1495
1619
  mock_app do
1496
- post '/' do
1620
+ post('/') do
1497
1621
  etag 'foo'
1498
1622
  'ok'
1499
1623
  end
@@ -1506,7 +1630,7 @@ class HelpersTest < Test::Unit::TestCase
1506
1630
 
1507
1631
  it 'ignores If-Modified-Since if If-None-Match does not match' do
1508
1632
  mock_app do
1509
- post '/' do
1633
+ post('/') do
1510
1634
  etag 'foo'
1511
1635
  last_modified Time.at(0)
1512
1636
  'ok'
@@ -1522,7 +1646,7 @@ class HelpersTest < Test::Unit::TestCase
1522
1646
  context "If-Match" do
1523
1647
  it 'returns 200 when If-Match is the etag' do
1524
1648
  mock_app do
1525
- post '/' do
1649
+ post('/') do
1526
1650
  etag 'foo'
1527
1651
  'ok'
1528
1652
  end
@@ -1535,7 +1659,7 @@ class HelpersTest < Test::Unit::TestCase
1535
1659
 
1536
1660
  it 'returns 200 when If-Match includes the etag' do
1537
1661
  mock_app do
1538
- post '/' do
1662
+ post('/') do
1539
1663
  etag 'foo'
1540
1664
  'ok'
1541
1665
  end
@@ -1548,7 +1672,7 @@ class HelpersTest < Test::Unit::TestCase
1548
1672
 
1549
1673
  it 'returns 412 when If-Match is *' do
1550
1674
  mock_app do
1551
- post '/' do
1675
+ post('/') do
1552
1676
  etag 'foo'
1553
1677
  'ok'
1554
1678
  end
@@ -1561,7 +1685,7 @@ class HelpersTest < Test::Unit::TestCase
1561
1685
 
1562
1686
  it 'returns 412 when If-Match is * for new resources' do
1563
1687
  mock_app do
1564
- post '/' do
1688
+ post('/') do
1565
1689
  etag 'foo', :new_resource => true
1566
1690
  'ok'
1567
1691
  end
@@ -1574,7 +1698,7 @@ class HelpersTest < Test::Unit::TestCase
1574
1698
 
1575
1699
  it 'returns 200 when If-Match is * for existing resources' do
1576
1700
  mock_app do
1577
- post '/' do
1701
+ post('/') do
1578
1702
  etag 'foo', :new_resource => false
1579
1703
  'ok'
1580
1704
  end
@@ -1587,7 +1711,7 @@ class HelpersTest < Test::Unit::TestCase
1587
1711
 
1588
1712
  it 'returns 412 when If-Match does not include the etag' do
1589
1713
  mock_app do
1590
- post '/' do
1714
+ post('/') do
1591
1715
  etag 'foo'
1592
1716
  'ok'
1593
1717
  end
@@ -1602,7 +1726,7 @@ class HelpersTest < Test::Unit::TestCase
1602
1726
 
1603
1727
  it 'uses a weak etag with the :weak option' do
1604
1728
  mock_app do
1605
- get '/' do
1729
+ get('/') do
1606
1730
  etag 'FOO', :weak
1607
1731
  "that's weak, dude."
1608
1732
  end
@@ -1613,24 +1737,20 @@ class HelpersTest < Test::Unit::TestCase
1613
1737
 
1614
1738
  it 'raises an ArgumentError for an invalid strength' do
1615
1739
  mock_app do
1616
- get '/' do
1740
+ get('/') do
1617
1741
  etag 'FOO', :w00t
1618
1742
  "that's weak, dude."
1619
1743
  end
1620
1744
  end
1621
- assert_raise(ArgumentError) { get '/' }
1745
+ assert_raise(ArgumentError) { get('/') }
1622
1746
  end
1623
1747
  end
1624
1748
 
1625
1749
  describe 'back' do
1626
1750
  it "makes redirecting back pretty" do
1627
- mock_app {
1628
- get '/foo' do
1629
- redirect back
1630
- end
1631
- }
1751
+ mock_app { get('/foo') { redirect back } }
1632
1752
 
1633
- get '/foo', {}, 'HTTP_REFERER' => 'http://github.com'
1753
+ get('/foo', {}, 'HTTP_REFERER' => 'http://github.com')
1634
1754
  assert redirect?
1635
1755
  assert_equal "http://github.com", response.location
1636
1756
  end
@@ -1690,7 +1810,7 @@ class HelpersTest < Test::Unit::TestCase
1690
1810
  it 'logging works when logging is enabled' do
1691
1811
  mock_app do
1692
1812
  enable :logging
1693
- get '/' do
1813
+ get('/') do
1694
1814
  logger.info "Program started"
1695
1815
  logger.warn "Nothing to do!"
1696
1816
  end
@@ -1704,7 +1824,7 @@ class HelpersTest < Test::Unit::TestCase
1704
1824
  it 'logging works when logging is disable, but no output is produced' do
1705
1825
  mock_app do
1706
1826
  disable :logging
1707
- get '/' do
1827
+ get('/') do
1708
1828
  logger.info "Program started"
1709
1829
  logger.warn "Nothing to do!"
1710
1830
  end
@@ -1731,17 +1851,13 @@ class HelpersTest < Test::Unit::TestCase
1731
1851
 
1732
1852
  describe 'Adding new helpers' do
1733
1853
  it 'takes a list of modules to mix into the app' do
1734
- mock_app {
1854
+ mock_app do
1735
1855
  helpers ::HelperOne, ::HelperTwo
1736
1856
 
1737
- get '/one' do
1738
- one
1739
- end
1857
+ get('/one') { one }
1740
1858
 
1741
- get '/two' do
1742
- two
1743
- end
1744
- }
1859
+ get('/two') { two }
1860
+ end
1745
1861
 
1746
1862
  get '/one'
1747
1863
  assert_equal '1', body
@@ -1751,32 +1867,26 @@ class HelpersTest < Test::Unit::TestCase
1751
1867
  end
1752
1868
 
1753
1869
  it 'takes a block to mix into the app' do
1754
- mock_app {
1870
+ mock_app do
1755
1871
  helpers do
1756
1872
  def foo
1757
1873
  'foo'
1758
1874
  end
1759
1875
  end
1760
1876
 
1761
- get '/' do
1762
- foo
1763
- end
1764
- }
1877
+ get('/') { foo }
1878
+ end
1765
1879
 
1766
1880
  get '/'
1767
1881
  assert_equal 'foo', body
1768
1882
  end
1769
1883
 
1770
1884
  it 'evaluates the block in class context so that methods can be aliased' do
1771
- mock_app {
1772
- helpers do
1773
- alias_method :h, :escape_html
1774
- end
1885
+ mock_app do
1886
+ helpers { alias_method :h, :escape_html }
1775
1887
 
1776
- get '/' do
1777
- h('42 < 43')
1778
- end
1779
- }
1888
+ get('/') { h('42 < 43') }
1889
+ end
1780
1890
 
1781
1891
  get '/'
1782
1892
  assert ok?