bmizerany-sinatra 0.9.0.4 → 0.9.0.5

Sign up to get free protection for your applications and to get access to all the features.
data/test/routing_test.rb CHANGED
@@ -484,4 +484,170 @@ describe "Routing" do
484
484
  assert_equal type, response.headers['Content-Type']
485
485
  end
486
486
  end
487
+
488
+ it 'degrades gracefully when optional accept header is not provided' do
489
+ mock_app {
490
+ get '/', :provides => :xml do
491
+ request.env['HTTP_ACCEPT']
492
+ end
493
+ get '/' do
494
+ 'default'
495
+ end
496
+ }
497
+ get '/'
498
+ assert ok?
499
+ assert_equal 'default', body
500
+ end
501
+
502
+ it 'passes a single url param as block parameters when one param is specified' do
503
+ mock_app {
504
+ get '/:foo' do |foo|
505
+ assert_equal 'bar', foo
506
+ end
507
+ }
508
+
509
+ get '/bar'
510
+ assert ok?
511
+ end
512
+
513
+ it 'passes multiple params as block parameters when many are specified' do
514
+ mock_app {
515
+ get '/:foo/:bar/:baz' do |foo, bar, baz|
516
+ assert_equal 'abc', foo
517
+ assert_equal 'def', bar
518
+ assert_equal 'ghi', baz
519
+ end
520
+ }
521
+
522
+ get '/abc/def/ghi'
523
+ assert ok?
524
+ end
525
+
526
+ it 'passes regular expression captures as block parameters' do
527
+ mock_app {
528
+ get(/^\/fo(.*)\/ba(.*)/) do |foo, bar|
529
+ assert_equal 'orooomma', foo
530
+ assert_equal 'f', bar
531
+ 'looks good'
532
+ end
533
+ }
534
+
535
+ get '/foorooomma/baf'
536
+ assert ok?
537
+ assert_equal 'looks good', body
538
+ end
539
+
540
+ it "supports mixing multiple splat params like /*/foo/*/* as block parameters" do
541
+ mock_app {
542
+ get '/*/foo/*/*' do |foo, bar, baz|
543
+ assert_equal 'bar', foo
544
+ assert_equal 'bling', bar
545
+ assert_equal 'baz/boom', baz
546
+ 'looks good'
547
+ end
548
+ }
549
+
550
+ get '/bar/foo/bling/baz/boom'
551
+ assert ok?
552
+ assert_equal 'looks good', body
553
+ end
554
+
555
+ it 'raises an ArgumentError with block arity > 1 and too many values' do
556
+ mock_app {
557
+ get '/:foo/:bar/:baz' do |foo, bar|
558
+ 'quux'
559
+ end
560
+ }
561
+
562
+ assert_raise(ArgumentError) { get '/a/b/c' }
563
+ end
564
+
565
+ it 'raises an ArgumentError with block param arity > 1 and too few values' do
566
+ mock_app {
567
+ get '/:foo/:bar' do |foo, bar, baz|
568
+ 'quux'
569
+ end
570
+ }
571
+
572
+ assert_raise(ArgumentError) { get '/a/b' }
573
+ end
574
+
575
+ it 'succeeds if no block parameters are specified' do
576
+ mock_app {
577
+ get '/:foo/:bar' do
578
+ 'quux'
579
+ end
580
+ }
581
+
582
+ get '/a/b'
583
+ assert ok?
584
+ assert_equal 'quux', body
585
+ end
586
+
587
+ it 'passes all params with block param arity -1 (splat args)' do
588
+ mock_app {
589
+ get '/:foo/:bar' do |*args|
590
+ args.join
591
+ end
592
+ }
593
+
594
+ get '/a/b'
595
+ assert ok?
596
+ assert_equal 'ab', body
597
+ end
598
+
599
+ # NOTE Block params behaves differently under 1.8 and 1.9. Under 1.8, block
600
+ # param arity is lax: declaring a mismatched number of block params results
601
+ # in a warning. Under 1.9, block param arity is strict: mismatched block
602
+ # arity raises an ArgumentError.
603
+
604
+ if RUBY_VERSION >= '1.9'
605
+
606
+ it 'raises an ArgumentError with block param arity 1 and no values' do
607
+ mock_app {
608
+ get '/foo' do |foo|
609
+ 'quux'
610
+ end
611
+ }
612
+
613
+ assert_raise(ArgumentError) { get '/foo' }
614
+ end
615
+
616
+ it 'raises an ArgumentError with block param arity 1 and too many values' do
617
+ mock_app {
618
+ get '/:foo/:bar/:baz' do |foo|
619
+ 'quux'
620
+ end
621
+ }
622
+
623
+ assert_raise(ArgumentError) { get '/a/b/c' }
624
+ end
625
+
626
+ else
627
+
628
+ it 'does not raise an ArgumentError with block param arity 1 and no values' do
629
+ mock_app {
630
+ get '/foo' do |foo|
631
+ 'quux'
632
+ end
633
+ }
634
+
635
+ silence_warnings { get '/foo' }
636
+ assert ok?
637
+ assert_equal 'quux', body
638
+ end
639
+
640
+ it 'does not raise an ArgumentError with block param arity 1 and too many values' do
641
+ mock_app {
642
+ get '/:foo/:bar/:baz' do |foo|
643
+ 'quux'
644
+ end
645
+ }
646
+
647
+ silence_warnings { get '/a/b/c' }
648
+ assert ok?
649
+ assert_equal 'quux', body
650
+ end
651
+
652
+ end
487
653
  end
@@ -0,0 +1,41 @@
1
+ require File.dirname(__FILE__) + '/helper'
2
+
3
+ class Rack::Handler::Mock
4
+ extend Test::Unit::Assertions
5
+
6
+ def self.run(app, options={})
7
+ assert(app < Sinatra::Base)
8
+ assert_equal 9001, options[:Port]
9
+ assert_equal 'foo.local', options[:Host]
10
+ yield new
11
+ end
12
+
13
+ def stop
14
+ end
15
+ end
16
+
17
+ describe 'Sinatra::Base.run!' do
18
+ before do
19
+ mock_app {
20
+ set :server, 'mock'
21
+ set :host, 'foo.local'
22
+ set :port, 9001
23
+ }
24
+ $stdout = File.open('/dev/null', 'wb')
25
+ end
26
+
27
+ after { $stdout = STDOUT }
28
+
29
+ it "locates the appropriate Rack handler and calls ::run" do
30
+ @app.run!
31
+ end
32
+
33
+ it "sets options on the app before running" do
34
+ @app.run! :sessions => true
35
+ assert @app.sessions?
36
+ end
37
+
38
+ it "falls back on the next server handler when not found" do
39
+ @app.run! :server => %w[foo bar mock]
40
+ end
41
+ end
data/test/static_test.rb CHANGED
@@ -1,17 +1,15 @@
1
1
  require File.dirname(__FILE__) + '/helper'
2
2
 
3
3
  describe 'Static' do
4
- F = ::File
5
-
6
4
  before do
7
5
  mock_app {
8
6
  set :static, true
9
- set :public, F.dirname(__FILE__)
7
+ set :public, File.dirname(__FILE__)
10
8
  }
11
9
  end
12
10
 
13
11
  it 'serves GET requests for files in the public directory' do
14
- get "/#{F.basename(__FILE__)}"
12
+ get "/#{File.basename(__FILE__)}"
15
13
  assert ok?
16
14
  assert_equal File.read(__FILE__), body
17
15
  assert_equal File.size(__FILE__).to_s, response['Content-Length']
@@ -19,7 +17,7 @@ describe 'Static' do
19
17
  end
20
18
 
21
19
  it 'produces a body that can be iterated over multiple times' do
22
- env = Rack::MockRequest.env_for("/#{F.basename(__FILE__)}")
20
+ env = Rack::MockRequest.env_for("/#{File.basename(__FILE__)}")
23
21
  status, headers, body = @app.call(env)
24
22
  buf1, buf2 = [], []
25
23
  body.each { |part| buf1 << part }
@@ -29,7 +27,7 @@ describe 'Static' do
29
27
  end
30
28
 
31
29
  it 'serves HEAD requests for files in the public directory' do
32
- head "/#{F.basename(__FILE__)}"
30
+ head "/#{File.basename(__FILE__)}"
33
31
  assert ok?
34
32
  assert_equal '', body
35
33
  assert_equal File.size(__FILE__).to_s, response['Content-Length']
@@ -37,8 +35,8 @@ describe 'Static' do
37
35
  end
38
36
 
39
37
  it 'serves files in preference to custom routes' do
40
- @app.get("/#{F.basename(__FILE__)}") { 'Hello World' }
41
- get "/#{F.basename(__FILE__)}"
38
+ @app.get("/#{File.basename(__FILE__)}") { 'Hello World' }
39
+ get "/#{File.basename(__FILE__)}"
42
40
  assert ok?
43
41
  assert body != 'Hello World'
44
42
  end
@@ -50,13 +48,13 @@ describe 'Static' do
50
48
 
51
49
  it 'passes to the next handler when the static option is disabled' do
52
50
  @app.set :static, false
53
- get "/#{F.basename(__FILE__)}"
51
+ get "/#{File.basename(__FILE__)}"
54
52
  assert not_found?
55
53
  end
56
54
 
57
55
  it 'passes to the next handler when the public option is nil' do
58
56
  @app.set :public, nil
59
- get "/#{F.basename(__FILE__)}"
57
+ get "/#{File.basename(__FILE__)}"
60
58
  assert not_found?
61
59
  end
62
60
 
data/test/test_test.rb ADDED
@@ -0,0 +1,21 @@
1
+ require File.dirname(__FILE__) + '/helper'
2
+
3
+ describe "Sinatra::Test" do
4
+ it "support nested parameters" do
5
+ mock_app {
6
+ get '/' do
7
+ params[:post][:title]
8
+ end
9
+
10
+ post '/' do
11
+ params[:post][:content]
12
+ end
13
+ }
14
+
15
+ get '/', :post => { :title => 'My Post Title' }
16
+ assert_equal 'My Post Title', body
17
+
18
+ post '/', :post => { :content => 'Post Content' }
19
+ assert_equal 'Post Content', body
20
+ end
21
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bmizerany-sinatra
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.0.4
4
+ version: 0.9.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Blake Mizerany
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-01-25 00:00:00 -08:00
12
+ date: 2009-02-10 00:00:00 -08:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -39,6 +39,7 @@ files:
39
39
  - compat/app_test.rb
40
40
  - compat/application_test.rb
41
41
  - compat/builder_test.rb
42
+ - compat/compat_test.rb
42
43
  - compat/custom_error_test.rb
43
44
  - compat/erb_test.rb
44
45
  - compat/events_test.rb
@@ -86,6 +87,7 @@ files:
86
87
  - test/builder_test.rb
87
88
  - test/data/reload_app_file.rb
88
89
  - test/erb_test.rb
90
+ - test/extensions_test.rb
89
91
  - test/filter_test.rb
90
92
  - test/haml_test.rb
91
93
  - test/helper.rb
@@ -95,12 +97,15 @@ files:
95
97
  - test/options_test.rb
96
98
  - test/reload_test.rb
97
99
  - test/request_test.rb
100
+ - test/response_test.rb
98
101
  - test/result_test.rb
99
102
  - test/routing_test.rb
100
103
  - test/sass_test.rb
104
+ - test/server_test.rb
101
105
  - test/sinatra_test.rb
102
106
  - test/static_test.rb
103
107
  - test/templates_test.rb
108
+ - test/test_test.rb
104
109
  - test/views/hello.builder
105
110
  - test/views/hello.erb
106
111
  - test/views/hello.haml
@@ -145,6 +150,7 @@ test_files:
145
150
  - test/base_test.rb
146
151
  - test/builder_test.rb
147
152
  - test/erb_test.rb
153
+ - test/extensions_test.rb
148
154
  - test/filter_test.rb
149
155
  - test/haml_test.rb
150
156
  - test/helpers_test.rb
@@ -153,9 +159,12 @@ test_files:
153
159
  - test/options_test.rb
154
160
  - test/reload_test.rb
155
161
  - test/request_test.rb
162
+ - test/response_test.rb
156
163
  - test/result_test.rb
157
164
  - test/routing_test.rb
158
165
  - test/sass_test.rb
166
+ - test/server_test.rb
159
167
  - test/sinatra_test.rb
160
168
  - test/static_test.rb
161
169
  - test/templates_test.rb
170
+ - test/test_test.rb