sinatra 1.2.9 → 1.3.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.

@@ -23,7 +23,7 @@ class RegexpLookAlike
23
23
  end
24
24
 
25
25
  class RoutingTest < Test::Unit::TestCase
26
- %w[get put post delete options].each do |verb|
26
+ %w[get put post delete options patch].each do |verb|
27
27
  it "defines #{verb.upcase} request handlers with #{verb}" do
28
28
  mock_app {
29
29
  send verb, '/hello' do
@@ -93,28 +93,12 @@ class RoutingTest < Test::Unit::TestCase
93
93
  assert_equal "<h1>Not Found</h1>", response.body
94
94
  end
95
95
 
96
- it 'matches empty PATH_INFO to "/" if no route is defined for ""' do
97
- mock_app do
98
- get '/' do
99
- 'worked'
100
- end
101
- end
102
-
103
- get '/', {}, "PATH_INFO" => ""
104
- assert ok?
105
- assert_equal 'worked', body
106
- end
107
-
108
- it 'matches empty PATH_INFO to "" if a route is defined for ""' do
109
- mock_app do
96
+ it 'matches empty PATH_INFO to "/"' do
97
+ mock_app {
110
98
  get '/' do
111
- 'did not work'
112
- end
113
-
114
- get '' do
115
99
  'worked'
116
100
  end
117
- end
101
+ }
118
102
 
119
103
  get '/', {}, "PATH_INFO" => ""
120
104
  assert ok?
@@ -227,12 +211,6 @@ class RoutingTest < Test::Unit::TestCase
227
211
  assert_equal "format=", body
228
212
  end
229
213
 
230
- it 'does not concatinate params with the same name' do
231
- mock_app { get('/:foo') { params[:foo] } }
232
- get '/a?foo=b'
233
- assert_body 'a'
234
- end
235
-
236
214
  it "supports single splat params like /*" do
237
215
  mock_app {
238
216
  get '/*' do
@@ -692,10 +670,10 @@ class RoutingTest < Test::Unit::TestCase
692
670
  it "filters by accept header" do
693
671
  mock_app {
694
672
  get '/', :provides => :xml do
695
- env['HTTP_ACCEPT']
673
+ request.env['HTTP_ACCEPT']
696
674
  end
697
675
  get '/foo', :provides => :html do
698
- env['HTTP_ACCEPT']
676
+ request.env['HTTP_ACCEPT']
699
677
  end
700
678
  }
701
679
 
@@ -720,7 +698,7 @@ class RoutingTest < Test::Unit::TestCase
720
698
 
721
699
  mock_app {
722
700
  get '/', :provides => types do
723
- env['HTTP_ACCEPT']
701
+ request.env['HTTP_ACCEPT']
724
702
  end
725
703
  }
726
704
 
@@ -735,7 +713,7 @@ class RoutingTest < Test::Unit::TestCase
735
713
  it 'degrades gracefully when optional accept header is not provided' do
736
714
  mock_app {
737
715
  get '/', :provides => :xml do
738
- env['HTTP_ACCEPT']
716
+ request.env['HTTP_ACCEPT']
739
717
  end
740
718
  get '/' do
741
719
  'default'
@@ -746,77 +724,6 @@ class RoutingTest < Test::Unit::TestCase
746
724
  assert_equal 'default', body
747
725
  end
748
726
 
749
- it 'respects user agent prefferences for the content type' do
750
- mock_app { get('/', :provides => [:png, :html]) { content_type }}
751
- get '/', {}, { 'HTTP_ACCEPT' => 'image/png;q=0.5,text/html;q=0.8' }
752
- assert_body 'text/html;charset=utf-8'
753
- get '/', {}, { 'HTTP_ACCEPT' => 'image/png;q=0.8,text/html;q=0.5' }
754
- assert_body 'image/png'
755
- end
756
-
757
- it 'accepts generic types' do
758
- mock_app do
759
- get('/', :provides => :xml) { content_type }
760
- get('/') { 'no match' }
761
- end
762
- get '/'
763
- assert_body 'no match'
764
- get '/', {}, { 'HTTP_ACCEPT' => 'foo/*' }
765
- assert_body 'no match'
766
- get '/', {}, { 'HTTP_ACCEPT' => 'application/*' }
767
- assert_body 'application/xml;charset=utf-8'
768
- get '/', {}, { 'HTTP_ACCEPT' => '*/*' }
769
- assert_body 'application/xml;charset=utf-8'
770
- end
771
-
772
- it 'prefers concrete over partly generic types' do
773
- mock_app { get('/', :provides => [:png, :html]) { content_type }}
774
- get '/', {}, { 'HTTP_ACCEPT' => 'image/*, text/html' }
775
- assert_body 'text/html;charset=utf-8'
776
- get '/', {}, { 'HTTP_ACCEPT' => 'image/png, text/*' }
777
- assert_body 'image/png'
778
- end
779
-
780
- it 'prefers concrete over fully generic types' do
781
- mock_app { get('/', :provides => [:png, :html]) { content_type }}
782
- get '/', {}, { 'HTTP_ACCEPT' => '*/*, text/html' }
783
- assert_body 'text/html;charset=utf-8'
784
- get '/', {}, { 'HTTP_ACCEPT' => 'image/png, */*' }
785
- assert_body 'image/png'
786
- end
787
-
788
- it 'prefers partly generic over fully generic types' do
789
- mock_app { get('/', :provides => [:png, :html]) { content_type }}
790
- get '/', {}, { 'HTTP_ACCEPT' => '*/*, text/*' }
791
- assert_body 'text/html;charset=utf-8'
792
- get '/', {}, { 'HTTP_ACCEPT' => 'image/*, */*' }
793
- assert_body 'image/png'
794
- end
795
-
796
- it 'respects quality with generic types' do
797
- mock_app { get('/', :provides => [:png, :html]) { content_type }}
798
- get '/', {}, { 'HTTP_ACCEPT' => 'image/*;q=1, text/html;q=0' }
799
- assert_body 'image/png'
800
- get '/', {}, { 'HTTP_ACCEPT' => 'image/png;q=0.5, text/*;q=0.7' }
801
- assert_body 'text/html;charset=utf-8'
802
- end
803
-
804
- it 'accepts both text/javascript and application/javascript for js' do
805
- mock_app { get('/', :provides => :js) { content_type }}
806
- get '/', {}, { 'HTTP_ACCEPT' => 'application/javascript' }
807
- assert_body 'application/javascript;charset=utf-8'
808
- get '/', {}, { 'HTTP_ACCEPT' => 'text/javascript' }
809
- assert_body 'text/javascript;charset=utf-8'
810
- end
811
-
812
- it 'accepts both text/xml and application/xml for xml' do
813
- mock_app { get('/', :provides => :xml) { content_type }}
814
- get '/', {}, { 'HTTP_ACCEPT' => 'application/xml' }
815
- assert_body 'application/xml;charset=utf-8'
816
- get '/', {}, { 'HTTP_ACCEPT' => 'text/xml' }
817
- assert_body 'text/xml;charset=utf-8'
818
- end
819
-
820
727
  it 'passes a single url param as block parameters when one param is specified' do
821
728
  mock_app {
822
729
  get '/:foo' do |foo|
@@ -1048,35 +955,4 @@ class RoutingTest < Test::Unit::TestCase
1048
955
  get '/foo'
1049
956
  assert not_found?
1050
957
  end
1051
-
1052
- it 'allows using call to fire another request internally' do
1053
- mock_app do
1054
- get '/foo' do
1055
- status, headers, body = call env.merge("PATH_INFO" => '/bar')
1056
- [status, headers, body.map { |e| e.upcase }]
1057
- end
1058
-
1059
- get '/bar' do
1060
- "bar"
1061
- end
1062
- end
1063
-
1064
- get '/foo'
1065
- assert ok?
1066
- assert_body "BAR"
1067
- end
1068
-
1069
- it 'plays well with other routing middleware' do
1070
- middleware = Sinatra.new
1071
- inner_app = Sinatra.new { get('/foo') { 'hello' } }
1072
- builder = Rack::Builder.new do
1073
- use middleware
1074
- map('/test') { run inner_app }
1075
- end
1076
-
1077
- @app = builder.to_app
1078
- get '/test/foo'
1079
- assert ok?
1080
- assert_body 'hello'
1081
- end
1082
958
  end
@@ -1,5 +1,4 @@
1
1
  require File.dirname(__FILE__) + '/helper'
2
- require 'stringio'
3
2
 
4
3
  module Rack::Handler
5
4
  class Mock
@@ -26,11 +25,11 @@ class ServerTest < Test::Unit::TestCase
26
25
  set :bind, 'foo.local'
27
26
  set :port, 9001
28
27
  }
29
- $stderr = StringIO.new
28
+ $stdout = File.open('/dev/null', 'wb')
30
29
  end
31
30
 
32
31
  def teardown
33
- $stderr = STDERR
32
+ $stdout = STDOUT
34
33
  end
35
34
 
36
35
  it "locates the appropriate Rack handler and calls ::run" do
@@ -34,24 +34,6 @@ class SettingsTest < Test::Unit::TestCase
34
34
  assert !@base.respond_to?(:fiz)
35
35
  end
36
36
 
37
- it 'raises an error without value and block' do
38
- assert_raise(ArgumentError) { @base.set(:fiz) }
39
- assert !@base.respond_to?(:fiz)
40
- end
41
-
42
- it 'allows setting a value to the app class' do
43
- @base.set :base, @base
44
- assert @base.respond_to?(:base)
45
- assert_equal @base, @base.base
46
- end
47
-
48
- it 'raises an error with the app class as value and a block' do
49
- assert_raise ArgumentError do
50
- @base.set(:fiz, @base) { 'baz' }
51
- end
52
- assert !@base.respond_to?(:fiz)
53
- end
54
-
55
37
  it "sets multiple settings with a Hash" do
56
38
  @base.set :foo => 1234,
57
39
  :bar => 'Hello World',
@@ -334,14 +316,6 @@ class SettingsTest < Test::Unit::TestCase
334
316
  @application.set :root, File.dirname(__FILE__)
335
317
  assert @application.static?
336
318
  end
337
-
338
- it 'is possible to use Module#public' do
339
- @base.send(:define_method, :foo) { }
340
- @base.send(:private, :foo)
341
- assert !@base.method_defined?(:foo)
342
- @base.send(:public, :foo)
343
- assert @base.method_defined?(:foo)
344
- end
345
319
  end
346
320
 
347
321
  describe 'bind' do
@@ -52,34 +52,44 @@ class SlimTest < Test::Unit::TestCase
52
52
  HTML4_DOCTYPE = "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">"
53
53
 
54
54
  it "passes slim options to the slim engine" do
55
- mock_app { get('/') { slim "x foo='bar'", :attr_wrapper => "'" }}
55
+ mock_app {
56
+ get '/' do
57
+ slim "! doctype html\nh1 Hello World", :format => :html4
58
+ end
59
+ }
56
60
  get '/'
57
61
  assert ok?
58
- assert_body "<x foo='bar'></x>"
62
+ assert_equal "#{HTML4_DOCTYPE}<h1>Hello World</h1>", body
59
63
  end
60
64
 
61
65
  it "passes default slim options to the slim engine" do
62
- mock_app do
63
- set :slim, :attr_wrapper => "'"
64
- get('/') { slim "x foo='bar'" }
65
- end
66
+ mock_app {
67
+ set :slim, {:format => :html4}
68
+ get '/' do
69
+ slim "! doctype html\nh1 Hello World"
70
+ end
71
+ }
66
72
  get '/'
67
73
  assert ok?
68
- assert_body "<x foo='bar'></x>"
74
+ assert_equal "#{HTML4_DOCTYPE}<h1>Hello World</h1>", body
69
75
  end
70
76
 
71
77
  it "merges the default slim options with the overrides and passes them to the slim engine" do
72
- mock_app do
73
- set :slim, :attr_wrapper => "'"
74
- get('/') { slim "x foo='bar'" }
75
- get('/other') { slim "x foo='bar'", :attr_wrapper => '"' }
76
- end
78
+ mock_app {
79
+ set :slim, {:format => :html4}
80
+ get '/' do
81
+ slim "! doctype html\nh1.header Hello World"
82
+ end
83
+ get '/html5' do
84
+ slim "! doctype html\nh1.header Hello World", :format => :html5
85
+ end
86
+ }
77
87
  get '/'
78
88
  assert ok?
79
- assert_body "<x foo='bar'></x>"
80
- get '/other'
89
+ assert_match(/^#{HTML4_DOCTYPE}/, body)
90
+ get '/html5'
81
91
  assert ok?
82
- assert_body '<x foo="bar"></x>'
92
+ assert_equal "<!DOCTYPE html><h1 class=\"header\">Hello World</h1>", body
83
93
  end
84
94
  end
85
95
 
@@ -36,6 +36,7 @@ class StaticTest < Test::Unit::TestCase
36
36
  head "/#{File.basename(__FILE__)}"
37
37
  assert ok?
38
38
  assert_equal '', body
39
+ assert_equal File.size(__FILE__).to_s, response['Content-Length']
39
40
  assert response.headers.include?('Last-Modified')
40
41
  end
41
42
 
metadata CHANGED
@@ -1,13 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sinatra
3
3
  version: !ruby/object:Gem::Version
4
- hash: 13
5
- prerelease:
6
- segments:
7
- - 1
8
- - 2
9
- - 9
10
- version: 1.2.9
4
+ prerelease: 6
5
+ version: 1.3.0.a
11
6
  platform: ruby
12
7
  authors:
13
8
  - Blake Mizerany
@@ -18,83 +13,45 @@ autorequire:
18
13
  bindir: bin
19
14
  cert_chain: []
20
15
 
21
- date: 2013-03-15 00:00:00 +01:00
16
+ date: 2011-03-22 00:00:00 +01:00
22
17
  default_executable:
23
18
  dependencies:
24
19
  - !ruby/object:Gem::Dependency
20
+ name: rack
21
+ prerelease: false
25
22
  requirement: &id001 !ruby/object:Gem::Requirement
26
23
  none: false
27
24
  requirements:
28
25
  - - ~>
29
26
  - !ruby/object:Gem::Version
30
- hash: 13
31
- segments:
32
- - 1
33
- - 1
34
- version: "1.1"
35
- - - <
36
- - !ruby/object:Gem::Version
37
- hash: 5
38
- segments:
39
- - 1
40
- - 5
41
- version: "1.5"
42
- version_requirements: *id001
43
- name: rack
44
- prerelease: false
27
+ version: "1.2"
45
28
  type: :runtime
29
+ version_requirements: *id001
46
30
  - !ruby/object:Gem::Dependency
31
+ name: tilt
32
+ prerelease: false
47
33
  requirement: &id002 !ruby/object:Gem::Requirement
48
34
  none: false
49
35
  requirements:
50
36
  - - ">="
51
37
  - !ruby/object:Gem::Version
52
- hash: 27
53
- segments:
54
- - 1
55
- - 2
56
- - 2
57
38
  version: 1.2.2
58
39
  - - <
59
40
  - !ruby/object:Gem::Version
60
- hash: 3
61
- segments:
62
- - 2
63
- - 0
64
41
  version: "2.0"
65
- version_requirements: *id002
66
- name: tilt
67
- prerelease: false
68
42
  type: :runtime
43
+ version_requirements: *id002
69
44
  - !ruby/object:Gem::Dependency
70
- requirement: &id003 !ruby/object:Gem::Requirement
71
- none: false
72
- requirements:
73
- - - ">="
74
- - !ruby/object:Gem::Version
75
- hash: 3
76
- segments:
77
- - 0
78
- version: "0"
79
- version_requirements: *id003
80
- name: backports
45
+ name: shotgun
81
46
  prerelease: false
82
- type: :runtime
83
- - !ruby/object:Gem::Dependency
84
- requirement: &id004 !ruby/object:Gem::Requirement
47
+ requirement: &id003 !ruby/object:Gem::Requirement
85
48
  none: false
86
49
  requirements:
87
50
  - - ~>
88
51
  - !ruby/object:Gem::Version
89
- hash: 7
90
- segments:
91
- - 0
92
- - 6
93
52
  version: "0.6"
94
- version_requirements: *id004
95
- name: shotgun
96
- prerelease: false
97
53
  type: :development
54
+ version_requirements: *id003
98
55
  description: Classy web-development dressed in a DSL
99
56
  email: sinatrarb@googlegroups.com
100
57
  executables: []
@@ -131,6 +88,7 @@ files:
131
88
  - lib/sinatra/images/404.png
132
89
  - lib/sinatra/images/500.png
133
90
  - lib/sinatra/main.rb
91
+ - lib/sinatra/rack.rb
134
92
  - lib/sinatra/showexceptions.rb
135
93
  - sinatra.gemspec
136
94
  - test/base_test.rb
@@ -155,7 +113,6 @@ files:
155
113
  - test/middleware_test.rb
156
114
  - test/nokogiri_test.rb
157
115
  - test/public/favicon.ico
158
- - test/rack_test.rb
159
116
  - test/radius_test.rb
160
117
  - test/rdoc_test.rb
161
118
  - test/request_test.rb
@@ -233,23 +190,17 @@ required_ruby_version: !ruby/object:Gem::Requirement
233
190
  requirements:
234
191
  - - ">="
235
192
  - !ruby/object:Gem::Version
236
- hash: 3
237
- segments:
238
- - 0
239
193
  version: "0"
240
194
  required_rubygems_version: !ruby/object:Gem::Requirement
241
195
  none: false
242
196
  requirements:
243
- - - ">="
197
+ - - ">"
244
198
  - !ruby/object:Gem::Version
245
- hash: 3
246
- segments:
247
- - 0
248
- version: "0"
199
+ version: 1.3.1
249
200
  requirements: []
250
201
 
251
202
  rubyforge_project: sinatra
252
- rubygems_version: 1.6.2
203
+ rubygems_version: 1.5.2
253
204
  signing_key:
254
205
  specification_version: 2
255
206
  summary: Classy web-development dressed in a DSL
@@ -272,7 +223,6 @@ test_files:
272
223
  - test/markdown_test.rb
273
224
  - test/middleware_test.rb
274
225
  - test/nokogiri_test.rb
275
- - test/rack_test.rb
276
226
  - test/radius_test.rb
277
227
  - test/rdoc_test.rb
278
228
  - test/request_test.rb