sinatra 1.4.8 → 2.0.0
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +111 -47
- data/CONTRIBUTING.md +1 -1
- data/Gemfile +41 -49
- data/LICENSE +4 -1
- data/MAINTENANCE.md +42 -0
- data/README.de.md +644 -436
- data/README.es.md +6 -6
- data/README.fr.md +9 -9
- data/README.hu.md +37 -3
- data/README.ja.md +103 -45
- data/README.ko.md +8 -8
- data/README.md +471 -363
- data/README.pt-br.md +3 -3
- data/README.pt-pt.md +2 -2
- data/README.ru.md +42 -64
- data/README.zh.md +8 -8
- data/Rakefile +72 -49
- data/SECURITY.md +35 -0
- data/lib/sinatra/base.rb +137 -195
- data/lib/sinatra/indifferent_hash.rb +150 -0
- data/lib/sinatra/main.rb +1 -0
- data/lib/sinatra/show_exceptions.rb +63 -55
- data/lib/sinatra/version.rb +1 -1
- data/sinatra.gemspec +19 -7
- metadata +30 -164
- data/lib/sinatra/ext.rb +0 -17
- data/test/asciidoctor_test.rb +0 -72
- data/test/base_test.rb +0 -167
- data/test/builder_test.rb +0 -91
- data/test/coffee_test.rb +0 -96
- data/test/compile_test.rb +0 -183
- data/test/contest.rb +0 -91
- data/test/creole_test.rb +0 -65
- data/test/delegator_test.rb +0 -160
- data/test/encoding_test.rb +0 -20
- data/test/erb_test.rb +0 -116
- data/test/extensions_test.rb +0 -98
- data/test/filter_test.rb +0 -487
- data/test/haml_test.rb +0 -109
- data/test/helper.rb +0 -132
- data/test/helpers_test.rb +0 -1917
- data/test/integration/app.rb +0 -79
- data/test/integration_helper.rb +0 -236
- data/test/integration_test.rb +0 -104
- data/test/less_test.rb +0 -69
- data/test/liquid_test.rb +0 -77
- data/test/mapped_error_test.rb +0 -285
- data/test/markaby_test.rb +0 -80
- data/test/markdown_test.rb +0 -85
- data/test/mediawiki_test.rb +0 -68
- data/test/middleware_test.rb +0 -68
- data/test/nokogiri_test.rb +0 -67
- data/test/public/favicon.ico +0 -0
- data/test/public/hello+world.txt +0 -1
- data/test/rabl_test.rb +0 -89
- data/test/rack_test.rb +0 -45
- data/test/radius_test.rb +0 -59
- data/test/rdoc_test.rb +0 -66
- data/test/readme_test.rb +0 -130
- data/test/request_test.rb +0 -100
- data/test/response_test.rb +0 -63
- data/test/result_test.rb +0 -76
- data/test/route_added_hook_test.rb +0 -59
- data/test/routing_test.rb +0 -1456
- data/test/sass_test.rb +0 -115
- data/test/scss_test.rb +0 -88
- data/test/server_test.rb +0 -56
- data/test/settings_test.rb +0 -582
- data/test/sinatra_test.rb +0 -12
- data/test/slim_test.rb +0 -102
- data/test/static_test.rb +0 -266
- data/test/streaming_test.rb +0 -149
- data/test/stylus_test.rb +0 -90
- data/test/templates_test.rb +0 -382
- data/test/textile_test.rb +0 -65
- data/test/views/a/in_a.str +0 -1
- data/test/views/ascii.erb +0 -2
- data/test/views/b/in_b.str +0 -1
- data/test/views/calc.html.erb +0 -1
- data/test/views/error.builder +0 -3
- data/test/views/error.erb +0 -3
- data/test/views/error.haml +0 -3
- data/test/views/error.sass +0 -2
- data/test/views/explicitly_nested.str +0 -1
- data/test/views/foo/hello.test +0 -1
- data/test/views/hello.asciidoc +0 -1
- data/test/views/hello.builder +0 -1
- data/test/views/hello.coffee +0 -1
- data/test/views/hello.creole +0 -1
- data/test/views/hello.erb +0 -1
- data/test/views/hello.haml +0 -1
- data/test/views/hello.less +0 -5
- data/test/views/hello.liquid +0 -1
- data/test/views/hello.mab +0 -1
- data/test/views/hello.md +0 -1
- data/test/views/hello.mediawiki +0 -1
- data/test/views/hello.nokogiri +0 -1
- data/test/views/hello.rabl +0 -2
- data/test/views/hello.radius +0 -1
- data/test/views/hello.rdoc +0 -1
- data/test/views/hello.sass +0 -2
- data/test/views/hello.scss +0 -3
- data/test/views/hello.slim +0 -1
- data/test/views/hello.str +0 -1
- data/test/views/hello.styl +0 -2
- data/test/views/hello.test +0 -1
- data/test/views/hello.textile +0 -1
- data/test/views/hello.wlang +0 -1
- data/test/views/hello.yajl +0 -1
- data/test/views/layout2.builder +0 -3
- data/test/views/layout2.erb +0 -2
- data/test/views/layout2.haml +0 -2
- data/test/views/layout2.liquid +0 -2
- data/test/views/layout2.mab +0 -2
- data/test/views/layout2.nokogiri +0 -3
- data/test/views/layout2.rabl +0 -3
- data/test/views/layout2.radius +0 -2
- data/test/views/layout2.slim +0 -3
- data/test/views/layout2.str +0 -2
- data/test/views/layout2.test +0 -1
- data/test/views/layout2.wlang +0 -2
- data/test/views/nested.str +0 -1
- data/test/views/utf8.erb +0 -2
- data/test/wlang_test.rb +0 -87
- data/test/yajl_test.rb +0 -86
data/test/settings_test.rb
DELETED
@@ -1,582 +0,0 @@
|
|
1
|
-
require File.expand_path('../helper', __FILE__)
|
2
|
-
|
3
|
-
class SettingsTest < Minitest::Test
|
4
|
-
setup do
|
5
|
-
@base = Sinatra.new(Sinatra::Base)
|
6
|
-
@base.set :environment => :foo, :app_file => nil
|
7
|
-
|
8
|
-
@application = Sinatra.new(Sinatra::Application)
|
9
|
-
@application.set :environment => :foo, :app_file => nil
|
10
|
-
end
|
11
|
-
|
12
|
-
it 'sets settings to literal values' do
|
13
|
-
@base.set(:foo, 'bar')
|
14
|
-
assert @base.respond_to?(:foo)
|
15
|
-
assert_equal 'bar', @base.foo
|
16
|
-
end
|
17
|
-
|
18
|
-
it 'sets settings to Procs' do
|
19
|
-
@base.set(:foo, Proc.new { 'baz' })
|
20
|
-
assert @base.respond_to?(:foo)
|
21
|
-
assert_equal 'baz', @base.foo
|
22
|
-
end
|
23
|
-
|
24
|
-
it 'sets settings using a block' do
|
25
|
-
@base.set(:foo){ 'baz' }
|
26
|
-
assert @base.respond_to?(:foo)
|
27
|
-
assert_equal 'baz', @base.foo
|
28
|
-
end
|
29
|
-
|
30
|
-
it 'raises an error with a value and a block' do
|
31
|
-
assert_raises ArgumentError do
|
32
|
-
@base.set(:fiz, 'boom!'){ 'baz' }
|
33
|
-
end
|
34
|
-
assert !@base.respond_to?(:fiz)
|
35
|
-
end
|
36
|
-
|
37
|
-
it 'raises an error without value and block' do
|
38
|
-
assert_raises(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_raises ArgumentError do
|
50
|
-
@base.set(:fiz, @base) { 'baz' }
|
51
|
-
end
|
52
|
-
assert !@base.respond_to?(:fiz)
|
53
|
-
end
|
54
|
-
|
55
|
-
it "sets multiple settings with a Hash" do
|
56
|
-
@base.set :foo => 1234,
|
57
|
-
:bar => 'Hello World',
|
58
|
-
:baz => Proc.new { 'bizzle' }
|
59
|
-
assert_equal 1234, @base.foo
|
60
|
-
assert_equal 'Hello World', @base.bar
|
61
|
-
assert_equal 'bizzle', @base.baz
|
62
|
-
end
|
63
|
-
|
64
|
-
it 'sets multiple settings using #each' do
|
65
|
-
@base.set [["foo", "bar"]]
|
66
|
-
assert_equal "bar", @base.foo
|
67
|
-
end
|
68
|
-
|
69
|
-
it 'inherits settings methods when subclassed' do
|
70
|
-
@base.set :foo, 'bar'
|
71
|
-
@base.set :biz, Proc.new { 'baz' }
|
72
|
-
|
73
|
-
sub = Class.new(@base)
|
74
|
-
assert sub.respond_to?(:foo)
|
75
|
-
assert_equal 'bar', sub.foo
|
76
|
-
assert sub.respond_to?(:biz)
|
77
|
-
assert_equal 'baz', sub.biz
|
78
|
-
end
|
79
|
-
|
80
|
-
it 'overrides settings in subclass' do
|
81
|
-
@base.set :foo, 'bar'
|
82
|
-
@base.set :biz, Proc.new { 'baz' }
|
83
|
-
sub = Class.new(@base)
|
84
|
-
sub.set :foo, 'bling'
|
85
|
-
assert_equal 'bling', sub.foo
|
86
|
-
assert_equal 'bar', @base.foo
|
87
|
-
end
|
88
|
-
|
89
|
-
it 'creates setter methods when first defined' do
|
90
|
-
@base.set :foo, 'bar'
|
91
|
-
assert @base.respond_to?('foo=')
|
92
|
-
@base.foo = 'biz'
|
93
|
-
assert_equal 'biz', @base.foo
|
94
|
-
end
|
95
|
-
|
96
|
-
it 'creates predicate methods when first defined' do
|
97
|
-
@base.set :foo, 'hello world'
|
98
|
-
assert @base.respond_to?(:foo?)
|
99
|
-
assert @base.foo?
|
100
|
-
@base.set :foo, nil
|
101
|
-
assert !@base.foo?
|
102
|
-
end
|
103
|
-
|
104
|
-
it 'uses existing setter methods if detected' do
|
105
|
-
class << @base
|
106
|
-
def foo
|
107
|
-
@foo
|
108
|
-
end
|
109
|
-
def foo=(value)
|
110
|
-
@foo = 'oops'
|
111
|
-
end
|
112
|
-
end
|
113
|
-
|
114
|
-
@base.set :foo, 'bam'
|
115
|
-
assert_equal 'oops', @base.foo
|
116
|
-
end
|
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
|
-
|
144
|
-
it "sets multiple settings to true with #enable" do
|
145
|
-
@base.enable :sessions, :foo, :bar
|
146
|
-
assert @base.sessions
|
147
|
-
assert @base.foo
|
148
|
-
assert @base.bar
|
149
|
-
end
|
150
|
-
|
151
|
-
it "sets multiple settings to false with #disable" do
|
152
|
-
@base.disable :sessions, :foo, :bar
|
153
|
-
assert !@base.sessions
|
154
|
-
assert !@base.foo
|
155
|
-
assert !@base.bar
|
156
|
-
end
|
157
|
-
|
158
|
-
it 'is accessible from instances via #settings' do
|
159
|
-
assert_equal :foo, @base.new!.settings.environment
|
160
|
-
end
|
161
|
-
|
162
|
-
it 'is accessible from class via #settings' do
|
163
|
-
assert_equal :foo, @base.settings.environment
|
164
|
-
end
|
165
|
-
|
166
|
-
describe 'methodoverride' do
|
167
|
-
it 'is disabled on Base' do
|
168
|
-
assert ! @base.method_override?
|
169
|
-
end
|
170
|
-
|
171
|
-
it 'is enabled on Application' do
|
172
|
-
assert @application.method_override?
|
173
|
-
end
|
174
|
-
|
175
|
-
it 'enables MethodOverride middleware' do
|
176
|
-
@base.set :method_override, true
|
177
|
-
@base.put('/') { 'okay' }
|
178
|
-
@app = @base
|
179
|
-
post '/', {'_method'=>'PUT'}, {}
|
180
|
-
assert_equal 200, status
|
181
|
-
assert_equal 'okay', body
|
182
|
-
end
|
183
|
-
|
184
|
-
it 'is backward compatible with methodoverride' do
|
185
|
-
assert ! @base.methodoverride?
|
186
|
-
@base.enable :methodoverride
|
187
|
-
assert @base.methodoverride?
|
188
|
-
end
|
189
|
-
end
|
190
|
-
|
191
|
-
describe 'run' do
|
192
|
-
it 'is disabled on Base' do
|
193
|
-
assert ! @base.run?
|
194
|
-
end
|
195
|
-
|
196
|
-
it 'is enabled on Application except in test environment' do
|
197
|
-
assert @application.run?
|
198
|
-
|
199
|
-
@application.set :environment, :test
|
200
|
-
assert ! @application.run?
|
201
|
-
end
|
202
|
-
end
|
203
|
-
|
204
|
-
describe 'raise_errors' do
|
205
|
-
it 'is enabled on Base only in test' do
|
206
|
-
assert ! @base.raise_errors?
|
207
|
-
|
208
|
-
@base.set(:environment, :test)
|
209
|
-
assert @base.raise_errors?
|
210
|
-
end
|
211
|
-
|
212
|
-
it 'is enabled on Application only in test' do
|
213
|
-
assert ! @application.raise_errors?
|
214
|
-
|
215
|
-
@application.set(:environment, :test)
|
216
|
-
assert @application.raise_errors?
|
217
|
-
end
|
218
|
-
end
|
219
|
-
|
220
|
-
describe 'show_exceptions' do
|
221
|
-
it 'is disabled on Base except under development' do
|
222
|
-
assert ! @base.show_exceptions?
|
223
|
-
@base.environment = :development
|
224
|
-
assert @base.show_exceptions?
|
225
|
-
end
|
226
|
-
|
227
|
-
it 'is disabled on Application except in development' do
|
228
|
-
assert ! @application.show_exceptions?
|
229
|
-
|
230
|
-
@application.set(:environment, :development)
|
231
|
-
assert @application.show_exceptions?
|
232
|
-
end
|
233
|
-
|
234
|
-
it 'returns a friendly 500' do
|
235
|
-
klass = Sinatra.new(Sinatra::Application)
|
236
|
-
mock_app(klass) {
|
237
|
-
enable :show_exceptions
|
238
|
-
|
239
|
-
get '/' do
|
240
|
-
raise StandardError
|
241
|
-
end
|
242
|
-
}
|
243
|
-
|
244
|
-
get '/'
|
245
|
-
assert_equal 500, status
|
246
|
-
assert body.include?("StandardError")
|
247
|
-
assert body.include?("<code>show_exceptions</code> setting")
|
248
|
-
end
|
249
|
-
|
250
|
-
it 'does not override app-specified error handling when set to :after_handler' do
|
251
|
-
ran = false
|
252
|
-
mock_app do
|
253
|
-
set :show_exceptions, :after_handler
|
254
|
-
error(RuntimeError) { ran = true }
|
255
|
-
get('/') { raise RuntimeError }
|
256
|
-
end
|
257
|
-
|
258
|
-
get '/'
|
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
|
270
|
-
|
271
|
-
get '/'
|
272
|
-
assert_equal 500, status
|
273
|
-
assert !ran
|
274
|
-
end
|
275
|
-
end
|
276
|
-
|
277
|
-
describe 'dump_errors' do
|
278
|
-
it 'is disabled on Base in test' do
|
279
|
-
@base.environment = :test
|
280
|
-
assert ! @base.dump_errors?
|
281
|
-
@base.environment = :development
|
282
|
-
assert @base.dump_errors?
|
283
|
-
@base.environment = :production
|
284
|
-
assert @base.dump_errors?
|
285
|
-
end
|
286
|
-
|
287
|
-
it 'dumps exception with backtrace to rack.errors' do
|
288
|
-
klass = Sinatra.new(Sinatra::Application)
|
289
|
-
|
290
|
-
mock_app(klass) {
|
291
|
-
enable :dump_errors
|
292
|
-
disable :raise_errors
|
293
|
-
|
294
|
-
error do
|
295
|
-
error = @env['rack.errors'].instance_variable_get(:@error)
|
296
|
-
error.rewind
|
297
|
-
|
298
|
-
error.read
|
299
|
-
end
|
300
|
-
|
301
|
-
get '/' do
|
302
|
-
raise
|
303
|
-
end
|
304
|
-
}
|
305
|
-
|
306
|
-
get '/'
|
307
|
-
assert body.include?("RuntimeError") && body.include?("settings_test.rb")
|
308
|
-
end
|
309
|
-
|
310
|
-
it 'does not dump 404 errors' do
|
311
|
-
klass = Sinatra.new(Sinatra::Application)
|
312
|
-
|
313
|
-
mock_app(klass) {
|
314
|
-
enable :dump_errors
|
315
|
-
disable :raise_errors
|
316
|
-
|
317
|
-
error do
|
318
|
-
error = @env['rack.errors'].instance_variable_get(:@error)
|
319
|
-
error.rewind
|
320
|
-
|
321
|
-
error.read
|
322
|
-
end
|
323
|
-
|
324
|
-
get '/' do
|
325
|
-
raise Sinatra::NotFound
|
326
|
-
end
|
327
|
-
}
|
328
|
-
|
329
|
-
get '/'
|
330
|
-
assert !body.include?("NotFound") && !body.include?("settings_test.rb")
|
331
|
-
end
|
332
|
-
end
|
333
|
-
|
334
|
-
describe 'sessions' do
|
335
|
-
it 'is disabled on Base' do
|
336
|
-
assert ! @base.sessions?
|
337
|
-
end
|
338
|
-
|
339
|
-
it 'is disabled on Application' do
|
340
|
-
assert ! @application.sessions?
|
341
|
-
end
|
342
|
-
end
|
343
|
-
|
344
|
-
describe 'logging' do
|
345
|
-
it 'is disabled on Base' do
|
346
|
-
assert ! @base.logging?
|
347
|
-
end
|
348
|
-
|
349
|
-
it 'is enabled on Application except in test environment' do
|
350
|
-
assert @application.logging?
|
351
|
-
|
352
|
-
@application.set :environment, :test
|
353
|
-
assert ! @application.logging
|
354
|
-
end
|
355
|
-
end
|
356
|
-
|
357
|
-
describe 'static' do
|
358
|
-
it 'is disabled on Base by default' do
|
359
|
-
assert ! @base.static?
|
360
|
-
end
|
361
|
-
|
362
|
-
it 'is enabled on Base when public_folder is set and exists' do
|
363
|
-
@base.set :environment, :development
|
364
|
-
@base.set :public_folder, File.dirname(__FILE__)
|
365
|
-
assert @base.static?
|
366
|
-
end
|
367
|
-
|
368
|
-
it 'is enabled on Base when root is set and root/public_folder exists' do
|
369
|
-
@base.set :environment, :development
|
370
|
-
@base.set :root, File.dirname(__FILE__)
|
371
|
-
assert @base.static?
|
372
|
-
end
|
373
|
-
|
374
|
-
it 'is disabled on Application by default' do
|
375
|
-
assert ! @application.static?
|
376
|
-
end
|
377
|
-
|
378
|
-
it 'is enabled on Application when public_folder is set and exists' do
|
379
|
-
@application.set :environment, :development
|
380
|
-
@application.set :public_folder, File.dirname(__FILE__)
|
381
|
-
assert @application.static?
|
382
|
-
end
|
383
|
-
|
384
|
-
it 'is enabled on Application when root is set and root/public_folder exists' do
|
385
|
-
@application.set :environment, :development
|
386
|
-
@application.set :root, File.dirname(__FILE__)
|
387
|
-
assert @application.static?
|
388
|
-
end
|
389
|
-
|
390
|
-
it 'is possible to use Module#public' do
|
391
|
-
@base.send(:define_method, :foo) { }
|
392
|
-
@base.send(:private, :foo)
|
393
|
-
assert !@base.public_method_defined?(:foo)
|
394
|
-
@base.send(:public, :foo)
|
395
|
-
assert @base.public_method_defined?(:foo)
|
396
|
-
end
|
397
|
-
|
398
|
-
it 'is possible to use the keyword public in a sinatra app' do
|
399
|
-
app = Sinatra.new do
|
400
|
-
private
|
401
|
-
def priv; end
|
402
|
-
public
|
403
|
-
def pub; end
|
404
|
-
end
|
405
|
-
assert !app.public_method_defined?(:priv)
|
406
|
-
assert app.public_method_defined?(:pub)
|
407
|
-
end
|
408
|
-
end
|
409
|
-
|
410
|
-
describe 'bind' do
|
411
|
-
it 'defaults to 0.0.0.0' do
|
412
|
-
assert_equal '0.0.0.0', @base.bind
|
413
|
-
assert_equal '0.0.0.0', @application.bind
|
414
|
-
end
|
415
|
-
end
|
416
|
-
|
417
|
-
describe 'port' do
|
418
|
-
it 'defaults to 4567' do
|
419
|
-
assert_equal 4567, @base.port
|
420
|
-
assert_equal 4567, @application.port
|
421
|
-
end
|
422
|
-
end
|
423
|
-
|
424
|
-
describe 'server' do
|
425
|
-
it 'includes webrick' do
|
426
|
-
assert @base.server.include?('webrick')
|
427
|
-
assert @application.server.include?('webrick')
|
428
|
-
end
|
429
|
-
|
430
|
-
it 'includes puma' do
|
431
|
-
assert @base.server.include?('puma')
|
432
|
-
assert @application.server.include?('puma')
|
433
|
-
end
|
434
|
-
|
435
|
-
it 'includes thin' do
|
436
|
-
next if RUBY_ENGINE == 'jruby'
|
437
|
-
assert @base.server.include?('thin')
|
438
|
-
assert @application.server.include?('thin')
|
439
|
-
end
|
440
|
-
end
|
441
|
-
|
442
|
-
describe 'app_file' do
|
443
|
-
it 'is nil for base classes' do
|
444
|
-
assert_nil Sinatra::Base.app_file
|
445
|
-
assert_nil Sinatra::Application.app_file
|
446
|
-
end
|
447
|
-
|
448
|
-
it 'defaults to the file subclassing' do
|
449
|
-
assert_equal File.expand_path(__FILE__), Sinatra.new.app_file
|
450
|
-
end
|
451
|
-
end
|
452
|
-
|
453
|
-
describe 'root' do
|
454
|
-
it 'is nil if app_file is not set' do
|
455
|
-
assert @base.root.nil?
|
456
|
-
assert @application.root.nil?
|
457
|
-
end
|
458
|
-
|
459
|
-
it 'is equal to the expanded basename of app_file' do
|
460
|
-
@base.app_file = __FILE__
|
461
|
-
assert_equal File.expand_path(File.dirname(__FILE__)), @base.root
|
462
|
-
|
463
|
-
@application.app_file = __FILE__
|
464
|
-
assert_equal File.expand_path(File.dirname(__FILE__)), @application.root
|
465
|
-
end
|
466
|
-
end
|
467
|
-
|
468
|
-
describe 'views' do
|
469
|
-
it 'is nil if root is not set' do
|
470
|
-
assert @base.views.nil?
|
471
|
-
assert @application.views.nil?
|
472
|
-
end
|
473
|
-
|
474
|
-
it 'is set to root joined with views/' do
|
475
|
-
@base.root = File.dirname(__FILE__)
|
476
|
-
assert_equal File.dirname(__FILE__) + "/views", @base.views
|
477
|
-
|
478
|
-
@application.root = File.dirname(__FILE__)
|
479
|
-
assert_equal File.dirname(__FILE__) + "/views", @application.views
|
480
|
-
end
|
481
|
-
end
|
482
|
-
|
483
|
-
describe 'public_folder' do
|
484
|
-
it 'is nil if root is not set' do
|
485
|
-
assert @base.public_folder.nil?
|
486
|
-
assert @application.public_folder.nil?
|
487
|
-
end
|
488
|
-
|
489
|
-
it 'is set to root joined with public/' do
|
490
|
-
@base.root = File.dirname(__FILE__)
|
491
|
-
assert_equal File.dirname(__FILE__) + "/public", @base.public_folder
|
492
|
-
|
493
|
-
@application.root = File.dirname(__FILE__)
|
494
|
-
assert_equal File.dirname(__FILE__) + "/public", @application.public_folder
|
495
|
-
end
|
496
|
-
end
|
497
|
-
|
498
|
-
describe 'public_dir' do
|
499
|
-
it 'is an alias for public_folder' do
|
500
|
-
@base.public_dir = File.dirname(__FILE__)
|
501
|
-
assert_equal File.dirname(__FILE__), @base.public_dir
|
502
|
-
assert_equal @base.public_folder, @base.public_dir
|
503
|
-
|
504
|
-
@application.public_dir = File.dirname(__FILE__)
|
505
|
-
assert_equal File.dirname(__FILE__), @application.public_dir
|
506
|
-
assert_equal @application.public_folder, @application.public_dir
|
507
|
-
end
|
508
|
-
end
|
509
|
-
|
510
|
-
describe 'lock' do
|
511
|
-
it 'is disabled by default' do
|
512
|
-
assert ! @base.lock?
|
513
|
-
assert ! @application.lock?
|
514
|
-
end
|
515
|
-
end
|
516
|
-
|
517
|
-
describe 'protection' do
|
518
|
-
class MiddlewareTracker < Rack::Builder
|
519
|
-
def self.track
|
520
|
-
Rack.send :remove_const, :Builder
|
521
|
-
Rack.const_set :Builder, MiddlewareTracker
|
522
|
-
MiddlewareTracker.used.clear
|
523
|
-
yield
|
524
|
-
ensure
|
525
|
-
Rack.send :remove_const, :Builder
|
526
|
-
Rack.const_set :Builder, MiddlewareTracker.superclass
|
527
|
-
end
|
528
|
-
|
529
|
-
def self.used
|
530
|
-
@used ||= []
|
531
|
-
end
|
532
|
-
|
533
|
-
def use(middleware, *)
|
534
|
-
MiddlewareTracker.used << middleware
|
535
|
-
super
|
536
|
-
end
|
537
|
-
end
|
538
|
-
|
539
|
-
it 'sets up Rack::Protection' do
|
540
|
-
MiddlewareTracker.track do
|
541
|
-
Sinatra::Base.new
|
542
|
-
assert_include MiddlewareTracker.used, Rack::Protection
|
543
|
-
end
|
544
|
-
end
|
545
|
-
|
546
|
-
it 'sets up Rack::Protection::PathTraversal' do
|
547
|
-
MiddlewareTracker.track do
|
548
|
-
Sinatra::Base.new
|
549
|
-
assert_include MiddlewareTracker.used, Rack::Protection::PathTraversal
|
550
|
-
end
|
551
|
-
end
|
552
|
-
|
553
|
-
it 'does not set up Rack::Protection::PathTraversal when disabling it' do
|
554
|
-
MiddlewareTracker.track do
|
555
|
-
Sinatra.new { set :protection, :except => :path_traversal }.new
|
556
|
-
assert_include MiddlewareTracker.used, Rack::Protection
|
557
|
-
assert !MiddlewareTracker.used.include?(Rack::Protection::PathTraversal)
|
558
|
-
end
|
559
|
-
end
|
560
|
-
|
561
|
-
it 'sets up RemoteToken if sessions are enabled' do
|
562
|
-
MiddlewareTracker.track do
|
563
|
-
Sinatra.new { enable :sessions }.new
|
564
|
-
assert_include MiddlewareTracker.used, Rack::Protection::RemoteToken
|
565
|
-
end
|
566
|
-
end
|
567
|
-
|
568
|
-
it 'does not set up RemoteToken if sessions are disabled' do
|
569
|
-
MiddlewareTracker.track do
|
570
|
-
Sinatra.new.new
|
571
|
-
assert !MiddlewareTracker.used.include?(Rack::Protection::RemoteToken)
|
572
|
-
end
|
573
|
-
end
|
574
|
-
|
575
|
-
it 'sets up RemoteToken if it is configured to' do
|
576
|
-
MiddlewareTracker.track do
|
577
|
-
Sinatra.new { set :protection, :session => true }.new
|
578
|
-
assert_include MiddlewareTracker.used, Rack::Protection::RemoteToken
|
579
|
-
end
|
580
|
-
end
|
581
|
-
end
|
582
|
-
end
|
data/test/sinatra_test.rb
DELETED
@@ -1,12 +0,0 @@
|
|
1
|
-
require File.expand_path('../helper', __FILE__)
|
2
|
-
|
3
|
-
class SinatraTest < Minitest::Test
|
4
|
-
it 'creates a new Sinatra::Base subclass on new' do
|
5
|
-
app = Sinatra.new { get('/') { 'Hello World' } }
|
6
|
-
assert_same Sinatra::Base, app.superclass
|
7
|
-
end
|
8
|
-
|
9
|
-
it "responds to #template_cache" do
|
10
|
-
assert_kind_of Tilt::Cache, Sinatra::Base.new!.template_cache
|
11
|
-
end
|
12
|
-
end
|
data/test/slim_test.rb
DELETED
@@ -1,102 +0,0 @@
|
|
1
|
-
require File.expand_path('../helper', __FILE__)
|
2
|
-
|
3
|
-
begin
|
4
|
-
require 'slim'
|
5
|
-
|
6
|
-
class SlimTest < Minitest::Test
|
7
|
-
def slim_app(&block)
|
8
|
-
mock_app do
|
9
|
-
set :views, File.dirname(__FILE__) + '/views'
|
10
|
-
get('/', &block)
|
11
|
-
end
|
12
|
-
get '/'
|
13
|
-
end
|
14
|
-
|
15
|
-
it 'renders inline slim strings' do
|
16
|
-
slim_app { slim "h1 Hiya\n" }
|
17
|
-
assert ok?
|
18
|
-
assert_equal "<h1>Hiya</h1>", body
|
19
|
-
end
|
20
|
-
|
21
|
-
it 'renders .slim files in views path' do
|
22
|
-
slim_app { slim :hello }
|
23
|
-
assert ok?
|
24
|
-
assert_equal "<h1>Hello From Slim</h1>", body
|
25
|
-
end
|
26
|
-
|
27
|
-
it "renders with inline layouts" do
|
28
|
-
mock_app do
|
29
|
-
layout { %(h1\n | THIS. IS. \n == yield.upcase ) }
|
30
|
-
get('/') { slim 'em Sparta' }
|
31
|
-
end
|
32
|
-
get '/'
|
33
|
-
assert ok?
|
34
|
-
assert_equal "<h1>THIS. IS. <EM>SPARTA</EM></h1>", body
|
35
|
-
end
|
36
|
-
|
37
|
-
it "renders with file layouts" do
|
38
|
-
slim_app { slim('| Hello World', :layout => :layout2) }
|
39
|
-
assert ok?
|
40
|
-
assert_equal "<h1>Slim Layout!</h1><p>Hello World</p>", body
|
41
|
-
end
|
42
|
-
|
43
|
-
it "raises error if template not found" do
|
44
|
-
mock_app { get('/') { slim(:no_such_template) } }
|
45
|
-
assert_raises(Errno::ENOENT) { get('/') }
|
46
|
-
end
|
47
|
-
|
48
|
-
HTML4_DOCTYPE = "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">"
|
49
|
-
|
50
|
-
it "passes slim options to the slim engine" do
|
51
|
-
mock_app { get('/') { slim("x foo='bar'", :attr_quote => "'") }}
|
52
|
-
get '/'
|
53
|
-
assert ok?
|
54
|
-
assert_body "<x foo='bar'></x>"
|
55
|
-
end
|
56
|
-
|
57
|
-
it "passes default slim options to the slim engine" do
|
58
|
-
mock_app do
|
59
|
-
set :slim, :attr_quote => "'"
|
60
|
-
get('/') { slim("x foo='bar'") }
|
61
|
-
end
|
62
|
-
get '/'
|
63
|
-
assert ok?
|
64
|
-
assert_body "<x foo='bar'></x>"
|
65
|
-
end
|
66
|
-
|
67
|
-
it "merges the default slim options with the overrides and passes them to the slim engine" do
|
68
|
-
mock_app do
|
69
|
-
set :slim, :attr_quote => "'"
|
70
|
-
get('/') { slim("x foo='bar'") }
|
71
|
-
get('/other') { slim("x foo='bar'", :attr_quote => '"') }
|
72
|
-
end
|
73
|
-
get '/'
|
74
|
-
assert ok?
|
75
|
-
assert_body "<x foo='bar'></x>"
|
76
|
-
get '/other'
|
77
|
-
assert ok?
|
78
|
-
assert_body '<x foo="bar"></x>'
|
79
|
-
end
|
80
|
-
|
81
|
-
it "can render truly nested layouts by accepting a layout and a block with the contents" do
|
82
|
-
mock_app do
|
83
|
-
template(:main_outer_layout) { "h1 Title\n== yield" }
|
84
|
-
template(:an_inner_layout) { "h2 Subtitle\n== yield" }
|
85
|
-
template(:a_page) { "p Contents." }
|
86
|
-
get('/') do
|
87
|
-
slim :main_outer_layout, :layout => false do
|
88
|
-
slim :an_inner_layout do
|
89
|
-
slim :a_page
|
90
|
-
end
|
91
|
-
end
|
92
|
-
end
|
93
|
-
end
|
94
|
-
get '/'
|
95
|
-
assert ok?
|
96
|
-
assert_body "<h1>Title</h1>\n<h2>Subtitle</h2>\n<p>Contents.</p>\n"
|
97
|
-
end
|
98
|
-
end
|
99
|
-
|
100
|
-
rescue LoadError
|
101
|
-
warn "#{$!.to_s}: skipping slim tests"
|
102
|
-
end
|