sinatra 1.3.0.d → 1.3.0.e

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 (53) hide show
  1. data/.gitignore +6 -0
  2. data/.yardopts +4 -0
  3. data/CHANGES +80 -3
  4. data/Gemfile +18 -12
  5. data/README.de.rdoc +189 -381
  6. data/README.es.rdoc +193 -316
  7. data/README.fr.rdoc +327 -475
  8. data/README.jp.rdoc +7 -1
  9. data/README.rdoc +132 -101
  10. data/README.ru.rdoc +3 -3
  11. data/README.zh.rdoc +2 -2
  12. data/Rakefile +19 -27
  13. data/lib/sinatra/base.rb +186 -262
  14. data/lib/sinatra/version.rb +3 -0
  15. data/sinatra.gemspec +12 -128
  16. data/test/base_test.rb +1 -1
  17. data/test/builder_test.rb +1 -1
  18. data/test/coffee_test.rb +1 -1
  19. data/test/creole_test.rb +1 -1
  20. data/test/delegator_test.rb +9 -7
  21. data/test/encoding_test.rb +1 -1
  22. data/test/erb_test.rb +1 -1
  23. data/test/extensions_test.rb +1 -1
  24. data/test/filter_test.rb +7 -4
  25. data/test/haml_test.rb +1 -1
  26. data/test/helper.rb +16 -1
  27. data/test/helpers_test.rb +12 -1
  28. data/test/less_test.rb +1 -1
  29. data/test/liquid_test.rb +1 -1
  30. data/test/mapped_error_test.rb +44 -1
  31. data/test/markaby_test.rb +1 -1
  32. data/test/markdown_test.rb +1 -1
  33. data/test/middleware_test.rb +1 -1
  34. data/test/nokogiri_test.rb +1 -1
  35. data/test/radius_test.rb +1 -1
  36. data/test/rdoc_test.rb +2 -2
  37. data/test/readme_test.rb +136 -0
  38. data/test/request_test.rb +1 -1
  39. data/test/response_test.rb +13 -3
  40. data/test/result_test.rb +3 -3
  41. data/test/route_added_hook_test.rb +1 -1
  42. data/test/routing_test.rb +9 -2
  43. data/test/sass_test.rb +1 -1
  44. data/test/scss_test.rb +1 -1
  45. data/test/server_test.rb +1 -1
  46. data/test/settings_test.rb +55 -22
  47. data/test/sinatra_test.rb +1 -1
  48. data/test/slim_test.rb +1 -1
  49. data/test/static_test.rb +22 -1
  50. data/test/templates_test.rb +1 -1
  51. data/test/textile_test.rb +1 -1
  52. metadata +47 -59
  53. data/lib/sinatra/rack.rb +0 -44
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/helper'
1
+ require File.expand_path('../helper', __FILE__)
2
2
 
3
3
  begin
4
4
  require 'nokogiri'
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/helper'
1
+ require File.expand_path('../helper', __FILE__)
2
2
 
3
3
  begin
4
4
  require 'radius'
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/helper'
1
+ require File.expand_path('../helper', __FILE__)
2
2
 
3
3
  begin
4
4
  require 'rdoc/markup/to_html'
@@ -36,7 +36,7 @@ class RdocTest < Test::Unit::TestCase
36
36
  end
37
37
  get '/'
38
38
  assert ok?
39
- assert_like 'THIS. IS.<P>SPARTA</P>!', body
39
+ assert_like 'THIS. IS. <P>SPARTA</P>!', body
40
40
  end
41
41
 
42
42
  it "renders with file layouts" do
@@ -0,0 +1,136 @@
1
+ # Tests to check if all the README examples work.
2
+ require File.expand_path('../helper', __FILE__)
3
+
4
+ class ReadmeTest < Test::Unit::TestCase
5
+ example do
6
+ mock_app { get('/') { 'Hello world!' } }
7
+ get '/'
8
+ assert_body 'Hello world!'
9
+ end
10
+
11
+ section "Routes" do
12
+ example do
13
+ mock_app do
14
+ get '/' do
15
+ ".. show something .."
16
+ end
17
+
18
+ post '/' do
19
+ ".. create something .."
20
+ end
21
+
22
+ put '/' do
23
+ ".. replace something .."
24
+ end
25
+
26
+ patch '/' do
27
+ ".. modify something .."
28
+ end
29
+
30
+ delete '/' do
31
+ ".. annihilate something .."
32
+ end
33
+
34
+ options '/' do
35
+ ".. appease something .."
36
+ end
37
+ end
38
+
39
+ get '/'
40
+ assert_body '.. show something ..'
41
+
42
+ post '/'
43
+ assert_body '.. create something ..'
44
+
45
+ put '/'
46
+ assert_body '.. replace something ..'
47
+
48
+ patch '/'
49
+ assert_body '.. modify something ..'
50
+
51
+ delete '/'
52
+ assert_body '.. annihilate something ..'
53
+
54
+ options '/'
55
+ assert_body '.. appease something ..'
56
+ end
57
+
58
+ example do
59
+ mock_app do
60
+ get '/hello/:name' do
61
+ # matches "GET /hello/foo" and "GET /hello/bar"
62
+ # params[:name] is 'foo' or 'bar'
63
+ "Hello #{params[:name]}!"
64
+ end
65
+ end
66
+
67
+ get '/hello/foo'
68
+ assert_body 'Hello foo!'
69
+
70
+ get '/hello/bar'
71
+ assert_body 'Hello bar!'
72
+ end
73
+
74
+ example do
75
+ mock_app do
76
+ get '/hello/:name' do |n|
77
+ "Hello #{n}!"
78
+ end
79
+ end
80
+
81
+ get '/hello/foo'
82
+ assert_body 'Hello foo!'
83
+
84
+ get '/hello/bar'
85
+ assert_body 'Hello bar!'
86
+ end
87
+
88
+ example do
89
+ mock_app do
90
+ get '/say/*/to/*' do
91
+ # matches /say/hello/to/world
92
+ params[:splat].inspect # => ["hello", "world"]
93
+ end
94
+
95
+ get '/download/*.*' do
96
+ # matches /download/path/to/file.xml
97
+ params[:splat].inspect # => ["path/to/file", "xml"]
98
+ end
99
+ end
100
+
101
+ get "/say/hello/to/world"
102
+ assert_body '["hello", "world"]'
103
+
104
+ get "/download/path/to/file.xml"
105
+ assert_body '["path/to/file", "xml"]'
106
+ end
107
+
108
+ example do
109
+ mock_app do
110
+ get %r{/hello/([\w]+)} do
111
+ "Hello, #{params[:captures].first}!"
112
+ end
113
+ end
114
+
115
+ get '/hello/foo'
116
+ assert_body 'Hello, foo!'
117
+
118
+ get '/hello/bar'
119
+ assert_body 'Hello, bar!'
120
+ end
121
+
122
+ example do
123
+ mock_app do
124
+ get %r{/hello/([\w]+)} do |c|
125
+ "Hello, #{c}!"
126
+ end
127
+ end
128
+
129
+ get '/hello/foo'
130
+ assert_body 'Hello, foo!'
131
+
132
+ get '/hello/bar'
133
+ assert_body 'Hello, bar!'
134
+ end
135
+ end
136
+ end
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/helper'
1
+ require File.expand_path('../helper', __FILE__)
2
2
  require 'stringio'
3
3
 
4
4
  class RequestTest < Test::Unit::TestCase
@@ -1,6 +1,6 @@
1
1
  # encoding: utf-8
2
2
 
3
- require File.dirname(__FILE__) + '/helper'
3
+ require File.expand_path('../helper', __FILE__)
4
4
 
5
5
  class ResponseTest < Test::Unit::TestCase
6
6
  setup do
@@ -22,7 +22,7 @@ class ResponseTest < Test::Unit::TestCase
22
22
  it 'writes to body' do
23
23
  @response.body = 'Hello'
24
24
  @response.write ' World'
25
- assert_equal 'Hello World', @response.body
25
+ assert_equal 'Hello World', @response.body.join
26
26
  end
27
27
 
28
28
  [204, 304].each do |status_code|
@@ -37,6 +37,16 @@ class ResponseTest < Test::Unit::TestCase
37
37
  @response.body = ['Hello', 'World!', '✈']
38
38
  status, headers, body = @response.finish
39
39
  assert_equal '14', headers['Content-Length']
40
- assert_equal @response.body, body
40
+ assert_equal @response.body, body.body
41
+ end
42
+
43
+ it 'does not nest a Sinatra::Response' do
44
+ @response.body = Sinatra::Response.new ["foo"]
45
+ assert_equal @response.body, ["foo"]
46
+ end
47
+
48
+ it 'does not nest a Rack::Response' do
49
+ @response.body = Rack::Response.new ["foo"]
50
+ assert_equal @response.body, ["foo"]
41
51
  end
42
52
  end
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/helper'
1
+ require File.expand_path('../helper', __FILE__)
2
2
 
3
3
  class ResultTest < Test::Unit::TestCase
4
4
  it "sets response.body when result is a String" do
@@ -76,14 +76,14 @@ class ResultTest < Test::Unit::TestCase
76
76
  assert_equal 'formula of', body
77
77
  end
78
78
 
79
- it "raises a TypeError when result is a non two or three tuple Array" do
79
+ it "raises a ArgumentError when result is a non two or three tuple Array" do
80
80
  mock_app {
81
81
  get '/' do
82
82
  [409, 'formula of', 'something else', 'even more']
83
83
  end
84
84
  }
85
85
 
86
- assert_raise(TypeError) { get '/' }
86
+ assert_raise(ArgumentError) { get '/' }
87
87
  end
88
88
 
89
89
  it "sets status when result is a Fixnum status code" do
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/helper'
1
+ require File.expand_path('../helper', __FILE__)
2
2
 
3
3
  module RouteAddedTest
4
4
  @routes, @procs = [], []
@@ -1,5 +1,5 @@
1
1
  # I like coding: UTF-8
2
- require File.dirname(__FILE__) + '/helper'
2
+ require File.expand_path('../helper', __FILE__)
3
3
 
4
4
  # Helper method for easy route pattern matching testing
5
5
  def route_def(pattern)
@@ -78,6 +78,13 @@ class RoutingTest < Test::Unit::TestCase
78
78
  assert_equal 200, status
79
79
  end
80
80
 
81
+ it "it handles encoded slashes correctly" do
82
+ mock_app { get("/:a") { |a| a } }
83
+ get '/foo%2Fbar'
84
+ assert_equal 200, status
85
+ assert_body "foo/bar"
86
+ end
87
+
81
88
  it "overrides the content-type in error handlers" do
82
89
  mock_app {
83
90
  before { content_type 'text/plain' }
@@ -1047,7 +1054,7 @@ class RoutingTest < Test::Unit::TestCase
1047
1054
  mock_app do
1048
1055
  get '/foo' do
1049
1056
  status, headers, body = call env.merge("PATH_INFO" => '/bar')
1050
- [status, headers, body.map(&:upcase)]
1057
+ [status, headers, body.each.map(&:upcase)]
1051
1058
  end
1052
1059
 
1053
1060
  get '/bar' do
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/helper'
1
+ require File.expand_path('../helper', __FILE__)
2
2
 
3
3
  begin
4
4
  require 'sass'
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/helper'
1
+ require File.expand_path('../helper', __FILE__)
2
2
 
3
3
  begin
4
4
  require 'sass'
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/helper'
1
+ require File.expand_path('../helper', __FILE__)
2
2
 
3
3
  module Rack::Handler
4
4
  class Mock
@@ -1,12 +1,12 @@
1
- require File.dirname(__FILE__) + '/helper'
1
+ require File.expand_path('../helper', __FILE__)
2
2
 
3
3
  class SettingsTest < Test::Unit::TestCase
4
4
  setup do
5
5
  @base = Sinatra.new(Sinatra::Base)
6
- @base.set :environment, :foo
6
+ @base.set :environment => :foo, :app_file => nil
7
7
 
8
8
  @application = Sinatra.new(Sinatra::Application)
9
- @application.set :environment, :foo
9
+ @application.set :environment => :foo, :app_file => nil
10
10
  end
11
11
 
12
12
  it 'sets settings to literal values' do
@@ -115,6 +115,32 @@ class SettingsTest < Test::Unit::TestCase
115
115
  assert_equal 'oops', @base.foo
116
116
  end
117
117
 
118
+ it 'merges values of multiple set calls if those are hashes' do
119
+ @base.set :foo, :a => 1
120
+ sub = Class.new(@base)
121
+ sub.set :foo, :b => 2
122
+ assert_equal({:a => 1, :b => 2}, sub.foo)
123
+ end
124
+
125
+ it 'merging does not affect the superclass' do
126
+ @base.set :foo, :a => 1
127
+ sub = Class.new(@base)
128
+ sub.set :foo, :b => 2
129
+ assert_equal({:a => 1}, @base.foo)
130
+ end
131
+
132
+ it 'is possible to change a value from a hash to something else' do
133
+ @base.set :foo, :a => 1
134
+ @base.set :foo, :bar
135
+ assert_equal(:bar, @base.foo)
136
+ end
137
+
138
+ it 'merges values with values of the superclass if those are hashes' do
139
+ @base.set :foo, :a => 1
140
+ @base.set :foo, :b => 2
141
+ assert_equal({:a => 1, :b => 2}, @base.foo)
142
+ end
143
+
118
144
  it "sets multiple settings to true with #enable" do
119
145
  @base.enable :sessions, :foo, :bar
120
146
  assert @base.sessions
@@ -222,27 +248,30 @@ class SettingsTest < Test::Unit::TestCase
222
248
  end
223
249
 
224
250
  it 'does not override app-specified error handling when set to :after_handler' do
225
- klass = Sinatra.new(Sinatra::Application)
226
- mock_app(klass) {
251
+ ran = false
252
+ mock_app do
227
253
  set :show_exceptions, :after_handler
228
-
229
- error RuntimeError do
230
- 'Big mistake !'
231
- end
232
-
233
- get '/' do
234
- raise RuntimeError
235
- end
236
- }
237
-
254
+ error(RuntimeError) { ran = true }
255
+ get('/') { raise RuntimeError }
256
+ end
257
+
238
258
  get '/'
239
259
  assert_equal 500, status
260
+ assert ran
261
+ end
262
+
263
+ it 'does catch any other exceptions when set to :after_handler' do
264
+ ran = false
265
+ mock_app do
266
+ set :show_exceptions, :after_handler
267
+ error(RuntimeError) { ran = true }
268
+ get('/') { raise ArgumentError }
269
+ end
240
270
 
241
- assert ! body.include?("<code>")
242
- assert body.include? "Big mistake !"
243
-
271
+ get '/'
272
+ assert_equal 500, status
273
+ assert !ran
244
274
  end
245
-
246
275
  end
247
276
 
248
277
  describe 'dump_errors' do
@@ -358,9 +387,13 @@ class SettingsTest < Test::Unit::TestCase
358
387
  end
359
388
 
360
389
  describe 'app_file' do
361
- it 'is nil' do
362
- assert_nil @base.app_file
363
- assert_nil @application.app_file
390
+ it 'is nil for base classes' do
391
+ assert_nil Sinatra::Base.app_file
392
+ assert_nil Sinatra::Application.app_file
393
+ end
394
+
395
+ it 'defaults to the file subclassing' do
396
+ assert_equal __FILE__, Sinatra.new.app_file
364
397
  end
365
398
  end
366
399
 
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/helper'
1
+ require File.expand_path('../helper', __FILE__)
2
2
 
3
3
  class SinatraTest < Test::Unit::TestCase
4
4
  it 'creates a new Sinatra::Base subclass on new' do
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/helper'
1
+ require File.expand_path('../helper', __FILE__)
2
2
 
3
3
  begin
4
4
  require 'slim'
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/helper'
1
+ require File.expand_path('../helper', __FILE__)
2
2
 
3
3
  class StaticTest < Test::Unit::TestCase
4
4
  setup do
@@ -154,4 +154,25 @@ class StaticTest < Test::Unit::TestCase
154
154
  assert_equal "bytes */#{length}",response['Content-Range'], "416 response should include actual length"
155
155
  end
156
156
  end
157
+
158
+ it 'does not include static cache control headers by default' do
159
+ env = Rack::MockRequest.env_for("/#{File.basename(__FILE__)}")
160
+ status, headers, body = @app.call(env)
161
+ assert !headers.has_key?('Cache-Control')
162
+ end
163
+
164
+ it 'sets cache control headers on static files if set' do
165
+ @app.set :static_cache_control, :public
166
+ env = Rack::MockRequest.env_for("/#{File.basename(__FILE__)}")
167
+ status, headers, body = @app.call(env)
168
+ assert headers.has_key?('Cache-Control')
169
+ assert_equal headers['Cache-Control'], 'public'
170
+
171
+ @app.set :static_cache_control, [:public, :must_revalidate, {:max_age => 300}]
172
+ env = Rack::MockRequest.env_for("/#{File.basename(__FILE__)}")
173
+ status, headers, body = @app.call(env)
174
+ assert headers.has_key?('Cache-Control')
175
+ assert_equal headers['Cache-Control'], 'public, must-revalidate, max-age=300'
176
+ end
177
+
157
178
  end
@@ -1,5 +1,5 @@
1
1
  # encoding: UTF-8
2
- require File.dirname(__FILE__) + '/helper'
2
+ require File.expand_path('../helper', __FILE__)
3
3
  File.delete(File.dirname(__FILE__) + '/views/layout.test') rescue nil
4
4
 
5
5
  class TestTemplate < Tilt::Template