sinatra-contrib 1.4.2 → 1.4.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/LICENSE +2 -0
- data/README.md +3 -0
- data/Rakefile +3 -3
- data/lib/sinatra/capture.rb +1 -1
- data/lib/sinatra/config_file.rb +4 -3
- data/lib/sinatra/contrib/version.rb +1 -1
- data/lib/sinatra/cookies.rb +2 -4
- data/lib/sinatra/custom_logger.rb +60 -0
- data/lib/sinatra/decompile.rb +7 -1
- data/lib/sinatra/namespace.rb +10 -3
- data/lib/sinatra/reloader.rb +6 -4
- data/lib/sinatra/respond_with.rb +30 -13
- data/lib/sinatra/streaming.rb +1 -1
- data/sinatra-contrib.gemspec +40 -3
- data/spec/capture_spec.rb +9 -2
- data/spec/config_file_spec.rb +1 -2
- data/spec/content_for_spec.rb +1 -2
- data/spec/cookies_spec.rb +25 -18
- data/spec/custom_logger_spec.rb +43 -0
- data/spec/decompile_spec.rb +1 -2
- data/spec/extension_spec.rb +2 -3
- data/spec/json_spec.rb +2 -3
- data/spec/link_header_spec.rb +1 -2
- data/spec/multi_route_spec.rb +1 -2
- data/spec/namespace_spec.rb +125 -60
- data/spec/reloader_spec.rb +1 -2
- data/spec/respond_with/bar.erb +1 -1
- data/spec/respond_with_spec.rb +3 -4
- data/spec/spec_helper.rb +1 -1
- data/spec/streaming_spec.rb +3 -3
- metadata +242 -30
data/spec/capture_spec.rb
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
# -*- coding: utf-8 -*-
|
2
|
-
require 'backports'
|
3
2
|
require 'slim'
|
4
|
-
|
3
|
+
require 'spec_helper'
|
5
4
|
|
6
5
|
describe Sinatra::Capture do
|
7
6
|
subject do
|
@@ -42,6 +41,10 @@ describe Sinatra::Capture do
|
|
42
41
|
it "handles utf-8 encoding" do
|
43
42
|
render(:erb, "utf_8").should == "UTF-8 –"
|
44
43
|
end
|
44
|
+
|
45
|
+
it "handles ISO-8859-1 encoding" do
|
46
|
+
render(:erb, "iso_8859_1").should == "ISO-8859-1 -"
|
47
|
+
end if RUBY_VERSION >= '1.9'
|
45
48
|
end
|
46
49
|
end
|
47
50
|
|
@@ -91,3 +94,7 @@ Hello #{a.strip}
|
|
91
94
|
@@ utf_8
|
92
95
|
<% a = capture do %>–<% end %>
|
93
96
|
UTF-8 <%= a %>
|
97
|
+
|
98
|
+
@@ iso_8859_1
|
99
|
+
<% a = capture do %>-<% end %>
|
100
|
+
ISO-8859-1 <%= a.force_encoding("iso-8859-1") %>
|
data/spec/config_file_spec.rb
CHANGED
data/spec/content_for_spec.rb
CHANGED
data/spec/cookies_spec.rb
CHANGED
@@ -1,5 +1,4 @@
|
|
1
|
-
require '
|
2
|
-
require_relative 'spec_helper'
|
1
|
+
require 'spec_helper'
|
3
2
|
|
4
3
|
describe Sinatra::Cookies do
|
5
4
|
def cookie_route(*cookies, &block)
|
@@ -9,7 +8,7 @@ describe Sinatra::Cookies do
|
|
9
8
|
result = instance_eval(&block)
|
10
9
|
"ok"
|
11
10
|
end
|
12
|
-
get '/'
|
11
|
+
get '/', {}, @headers || {}
|
13
12
|
last_response.should be_ok
|
14
13
|
body.should be == "ok"
|
15
14
|
result
|
@@ -33,7 +32,7 @@ describe Sinatra::Cookies do
|
|
33
32
|
it 'runs the block' do
|
34
33
|
ran = false
|
35
34
|
cookie_route { ran = true }
|
36
|
-
ran.should
|
35
|
+
ran.should be true
|
37
36
|
end
|
38
37
|
|
39
38
|
it 'returns the block result' do
|
@@ -97,6 +96,14 @@ describe Sinatra::Cookies do
|
|
97
96
|
end.should include('HttpOnly')
|
98
97
|
end
|
99
98
|
|
99
|
+
it 'sets domain to nil if localhost' do
|
100
|
+
@headers = {'HTTP_HOST' => 'localhost'}
|
101
|
+
cookie_route do
|
102
|
+
cookies['foo'] = 'bar'
|
103
|
+
response['Set-Cookie']
|
104
|
+
end.should_not include("domain")
|
105
|
+
end
|
106
|
+
|
100
107
|
it 'sets the domain' do
|
101
108
|
cookie_route do
|
102
109
|
cookies['foo'] = 'bar'
|
@@ -275,7 +282,7 @@ describe Sinatra::Cookies do
|
|
275
282
|
cookies.each do |key, value|
|
276
283
|
key.should == 'foo'
|
277
284
|
value.should == 'baz'
|
278
|
-
seen.should
|
285
|
+
seen.should == false
|
279
286
|
seen = true
|
280
287
|
end
|
281
288
|
end
|
@@ -435,7 +442,7 @@ describe Sinatra::Cookies do
|
|
435
442
|
cookie_route do
|
436
443
|
cookies['foo'] = 'bar'
|
437
444
|
cookies.empty?
|
438
|
-
end.should
|
445
|
+
end.should be false
|
439
446
|
end
|
440
447
|
|
441
448
|
it 'becomes true if response cookies are removed' do
|
@@ -443,14 +450,14 @@ describe Sinatra::Cookies do
|
|
443
450
|
cookies['foo'] = 'bar'
|
444
451
|
cookies.delete :foo
|
445
452
|
cookies.empty?
|
446
|
-
end.should
|
453
|
+
end.should be true
|
447
454
|
end
|
448
455
|
|
449
456
|
it 'becomes true if request cookies are removed' do
|
450
457
|
cookie_route('foo=bar') do
|
451
458
|
cookies.delete :foo
|
452
459
|
cookies.empty?
|
453
|
-
end.should
|
460
|
+
end.should be_truthy
|
454
461
|
end
|
455
462
|
|
456
463
|
it 'becomes true after clear' do
|
@@ -458,7 +465,7 @@ describe Sinatra::Cookies do
|
|
458
465
|
cookies['foo'] = 'bar'
|
459
466
|
cookies.clear
|
460
467
|
cookies.empty?
|
461
|
-
end.should
|
468
|
+
end.should be_truthy
|
462
469
|
end
|
463
470
|
end
|
464
471
|
|
@@ -595,19 +602,19 @@ describe Sinatra::Cookies do
|
|
595
602
|
|
596
603
|
describe :key? do
|
597
604
|
it 'checks request cookies' do
|
598
|
-
cookies('foo=bar').key?('foo').should
|
605
|
+
cookies('foo=bar').key?('foo').should be true
|
599
606
|
end
|
600
607
|
|
601
608
|
it 'checks response cookies' do
|
602
609
|
jar = cookies
|
603
610
|
jar['foo'] = 'bar'
|
604
|
-
jar.key?(:foo).should
|
611
|
+
jar.key?(:foo).should be true
|
605
612
|
end
|
606
613
|
|
607
614
|
it 'does not use deleted cookies' do
|
608
615
|
jar = cookies('foo=bar')
|
609
616
|
jar.delete :foo
|
610
|
-
jar.key?('foo').should
|
617
|
+
jar.key?('foo').should be false
|
611
618
|
end
|
612
619
|
end
|
613
620
|
|
@@ -622,19 +629,19 @@ describe Sinatra::Cookies do
|
|
622
629
|
|
623
630
|
describe :member? do
|
624
631
|
it 'checks request cookies' do
|
625
|
-
cookies('foo=bar').member?('foo').should
|
632
|
+
cookies('foo=bar').member?('foo').should be true
|
626
633
|
end
|
627
634
|
|
628
635
|
it 'checks response cookies' do
|
629
636
|
jar = cookies
|
630
637
|
jar['foo'] = 'bar'
|
631
|
-
jar.member?(:foo).should
|
638
|
+
jar.member?(:foo).should be true
|
632
639
|
end
|
633
640
|
|
634
641
|
it 'does not use deleted cookies' do
|
635
642
|
jar = cookies('foo=bar')
|
636
643
|
jar.delete :foo
|
637
|
-
jar.member?('foo').should
|
644
|
+
jar.member?('foo').should be false
|
638
645
|
end
|
639
646
|
end
|
640
647
|
|
@@ -776,19 +783,19 @@ describe Sinatra::Cookies do
|
|
776
783
|
|
777
784
|
describe :value? do
|
778
785
|
it 'checks request cookies' do
|
779
|
-
cookies('foo=bar').value?('bar').should
|
786
|
+
cookies('foo=bar').value?('bar').should be true
|
780
787
|
end
|
781
788
|
|
782
789
|
it 'checks response cookies' do
|
783
790
|
jar = cookies
|
784
791
|
jar[:foo] = 'bar'
|
785
|
-
jar.value?('bar').should
|
792
|
+
jar.value?('bar').should be true
|
786
793
|
end
|
787
794
|
|
788
795
|
it 'does not use deleted cookies' do
|
789
796
|
jar = cookies('foo=bar')
|
790
797
|
jar.delete :foo
|
791
|
-
jar.value?('bar').
|
798
|
+
jar.value?('bar').should be false
|
792
799
|
end
|
793
800
|
end
|
794
801
|
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'sinatra/custom_logger'
|
3
|
+
|
4
|
+
describe Sinatra::CustomLogger do
|
5
|
+
before do
|
6
|
+
rack_logger = @rack_logger = double
|
7
|
+
mock_app do
|
8
|
+
helpers Sinatra::CustomLogger
|
9
|
+
|
10
|
+
before do
|
11
|
+
env['rack.logger'] = rack_logger
|
12
|
+
end
|
13
|
+
|
14
|
+
get '/' do
|
15
|
+
logger.info 'Logged message'
|
16
|
+
'Response'
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
describe '#logger' do
|
22
|
+
it 'falls back to request.logger' do
|
23
|
+
expect(@rack_logger).to receive(:info).with('Logged message')
|
24
|
+
get '/'
|
25
|
+
end
|
26
|
+
|
27
|
+
context 'logger setting is set' do
|
28
|
+
before do
|
29
|
+
custom_logger = @custom_logger = double
|
30
|
+
@app.class_eval do
|
31
|
+
configure do
|
32
|
+
set :logger, custom_logger
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'calls custom logger' do
|
38
|
+
expect(@custom_logger).to receive(:info).with('Logged message')
|
39
|
+
get '/'
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
data/spec/decompile_spec.rb
CHANGED
data/spec/extension_spec.rb
CHANGED
@@ -1,5 +1,4 @@
|
|
1
|
-
require '
|
2
|
-
require_relative 'spec_helper'
|
1
|
+
require 'spec_helper'
|
3
2
|
|
4
3
|
describe Sinatra::Extension do
|
5
4
|
module ExampleExtension
|
@@ -24,7 +23,7 @@ describe Sinatra::Extension do
|
|
24
23
|
before { mock_app { register ExampleExtension }}
|
25
24
|
|
26
25
|
it('allows using set') { settings.foo.should == :bar }
|
27
|
-
it('implements configure') { settings.reload_stuff.should
|
26
|
+
it('implements configure') { settings.reload_stuff.should be false }
|
28
27
|
|
29
28
|
it 'allows defing routes' do
|
30
29
|
get('/').should be_ok
|
data/spec/json_spec.rb
CHANGED
data/spec/link_header_spec.rb
CHANGED
data/spec/multi_route_spec.rb
CHANGED
data/spec/namespace_spec.rb
CHANGED
@@ -1,5 +1,4 @@
|
|
1
|
-
require '
|
2
|
-
require_relative 'spec_helper'
|
1
|
+
require 'spec_helper'
|
3
2
|
|
4
3
|
describe Sinatra::Namespace do
|
5
4
|
verbs = [:get, :head, :post, :put, :delete, :options]
|
@@ -44,7 +43,7 @@ describe Sinatra::Namespace do
|
|
44
43
|
it 'accepts the path as a regular expression' do
|
45
44
|
namespace('/foo') { send(verb, /\/\d\d/) { 'bar' }}
|
46
45
|
send(verb, '/foo/12').should be_ok
|
47
|
-
body.should
|
46
|
+
body.should eq 'bar' unless verb == :head
|
48
47
|
send(verb, '/foo/123').should_not be_ok
|
49
48
|
end
|
50
49
|
end
|
@@ -119,14 +118,14 @@ describe Sinatra::Namespace do
|
|
119
118
|
ran = false
|
120
119
|
namespace('/foo') { before { ran = true }}
|
121
120
|
send(verb, '/foo')
|
122
|
-
ran.should
|
121
|
+
ran.should be true
|
123
122
|
end
|
124
123
|
|
125
124
|
specify 'are not triggered for a different namespace' do
|
126
125
|
ran = false
|
127
126
|
namespace('/foo') { before { ran = true }}
|
128
127
|
send(verb, '/fox')
|
129
|
-
ran.should
|
128
|
+
ran.should be false
|
130
129
|
end
|
131
130
|
end
|
132
131
|
|
@@ -135,14 +134,14 @@ describe Sinatra::Namespace do
|
|
135
134
|
ran = false
|
136
135
|
namespace('/foo') { after { ran = true }}
|
137
136
|
send(verb, '/foo')
|
138
|
-
ran.should
|
137
|
+
ran.should be true
|
139
138
|
end
|
140
139
|
|
141
140
|
specify 'are not triggered for a different namespace' do
|
142
141
|
ran = false
|
143
142
|
namespace('/foo') { after { ran = true }}
|
144
143
|
send(verb, '/fox')
|
145
|
-
ran.should
|
144
|
+
ran.should be false
|
146
145
|
end
|
147
146
|
end
|
148
147
|
|
@@ -177,13 +176,13 @@ describe Sinatra::Namespace do
|
|
177
176
|
send(verb, '/*') { 'ok' }
|
178
177
|
end
|
179
178
|
send(verb, '/foo', {}, 'HTTP_HOST' => 'example.org', 'HTTP_ACCEPT' => 'text/plain')
|
180
|
-
ran.should
|
179
|
+
ran.should be false
|
181
180
|
send(verb, '/foo', {}, 'HTTP_HOST' => 'example.com', 'HTTP_ACCEPT' => 'text/html')
|
182
|
-
ran.should
|
181
|
+
ran.should be false
|
183
182
|
send(verb, '/bar', {}, 'HTTP_HOST' => 'example.com', 'HTTP_ACCEPT' => 'text/plain')
|
184
|
-
ran.should
|
183
|
+
ran.should be false
|
185
184
|
send(verb, '/foo', {}, 'HTTP_HOST' => 'example.com', 'HTTP_ACCEPT' => 'text/plain')
|
186
|
-
ran.should
|
185
|
+
ran.should be true
|
187
186
|
end
|
188
187
|
|
189
188
|
specify 'are accepted in the after-filter' do
|
@@ -193,13 +192,13 @@ describe Sinatra::Namespace do
|
|
193
192
|
send(verb, '/*') { 'ok' }
|
194
193
|
end
|
195
194
|
send(verb, '/foo', {}, 'HTTP_HOST' => 'example.org', 'HTTP_ACCEPT' => 'text/plain')
|
196
|
-
ran.should
|
195
|
+
ran.should be false
|
197
196
|
send(verb, '/foo', {}, 'HTTP_HOST' => 'example.com', 'HTTP_ACCEPT' => 'text/html')
|
198
|
-
ran.should
|
197
|
+
ran.should be false
|
199
198
|
send(verb, '/bar', {}, 'HTTP_HOST' => 'example.com', 'HTTP_ACCEPT' => 'text/plain')
|
200
|
-
ran.should
|
199
|
+
ran.should be false
|
201
200
|
send(verb, '/foo', {}, 'HTTP_HOST' => 'example.com', 'HTTP_ACCEPT' => 'text/plain')
|
202
|
-
ran.should
|
201
|
+
ran.should be true
|
203
202
|
end
|
204
203
|
end
|
205
204
|
|
@@ -232,9 +231,9 @@ describe Sinatra::Namespace do
|
|
232
231
|
send(verb) { 'ok' }
|
233
232
|
end
|
234
233
|
send(verb, '/foo', {}, 'HTTP_HOST' => 'example.org')
|
235
|
-
ran.should
|
234
|
+
ran.should be false
|
236
235
|
send(verb, '/foo', {}, 'HTTP_HOST' => 'example.com')
|
237
|
-
ran.should
|
236
|
+
ran.should be true
|
238
237
|
end
|
239
238
|
|
240
239
|
specify 'are accepted in the route definition' do
|
@@ -253,11 +252,11 @@ describe Sinatra::Namespace do
|
|
253
252
|
send(verb) { 'ok' }
|
254
253
|
end
|
255
254
|
send(verb, '/', {}, 'HTTP_HOST' => 'example.org', 'HTTP_ACCEPT' => 'text/plain')
|
256
|
-
ran.should
|
255
|
+
ran.should be false
|
257
256
|
send(verb, '/', {}, 'HTTP_HOST' => 'example.com', 'HTTP_ACCEPT' => 'text/html')
|
258
|
-
ran.should
|
257
|
+
ran.should be false
|
259
258
|
send(verb, '/', {}, 'HTTP_HOST' => 'example.com', 'HTTP_ACCEPT' => 'text/plain')
|
260
|
-
ran.should
|
259
|
+
ran.should be true
|
261
260
|
end
|
262
261
|
|
263
262
|
specify 'are accepted in the filters' do
|
@@ -267,13 +266,13 @@ describe Sinatra::Namespace do
|
|
267
266
|
send(verb, '/*') { 'ok' }
|
268
267
|
end
|
269
268
|
send(verb, '/foo', {}, 'HTTP_HOST' => 'example.org', 'HTTP_ACCEPT' => 'text/plain')
|
270
|
-
ran.should
|
269
|
+
ran.should be false
|
271
270
|
send(verb, '/foo', {}, 'HTTP_HOST' => 'example.com', 'HTTP_ACCEPT' => 'text/html')
|
272
|
-
ran.should
|
271
|
+
ran.should be false
|
273
272
|
send(verb, '/far', {}, 'HTTP_HOST' => 'example.com', 'HTTP_ACCEPT' => 'text/plain')
|
274
|
-
ran.should
|
273
|
+
ran.should be false
|
275
274
|
send(verb, '/foo', {}, 'HTTP_HOST' => 'example.com', 'HTTP_ACCEPT' => 'text/plain')
|
276
|
-
ran.should
|
275
|
+
ran.should be true
|
277
276
|
end
|
278
277
|
end
|
279
278
|
end
|
@@ -479,24 +478,24 @@ describe Sinatra::Namespace do
|
|
479
478
|
namespace('/de') do
|
480
479
|
not_found { 'nicht gefunden' }
|
481
480
|
end
|
482
|
-
send(verb, '/foo').status.should
|
483
|
-
last_response.body.should_not
|
484
|
-
get('/en/foo').status.should
|
485
|
-
last_response.body.should_not
|
486
|
-
get('/de/foo').status.should
|
487
|
-
last_response.body.should
|
481
|
+
send(verb, '/foo').status.should eq 404
|
482
|
+
last_response.body.should_not eq 'nicht gefunden' unless verb == :head
|
483
|
+
get('/en/foo').status.should eq 404
|
484
|
+
last_response.body.should_not eq 'nicht gefunden' unless verb == :head
|
485
|
+
get('/de/foo').status.should eq 404
|
486
|
+
last_response.body.should eq 'nicht gefunden' unless verb == :head
|
488
487
|
end
|
489
488
|
|
490
489
|
it 'can be customized for specific error codes' do
|
491
490
|
namespace('/de') do
|
492
491
|
error(404) { 'nicht gefunden' }
|
493
492
|
end
|
494
|
-
send(verb, '/foo').status.should
|
495
|
-
last_response.body.should_not
|
496
|
-
get('/en/foo').status.should
|
497
|
-
last_response.body.should_not
|
498
|
-
get('/de/foo').status.should
|
499
|
-
last_response.body.should
|
493
|
+
send(verb, '/foo').status.should eq 404
|
494
|
+
last_response.body.should_not eq 'nicht gefunden' unless verb == :head
|
495
|
+
get('/en/foo').status.should eq 404
|
496
|
+
last_response.body.should_not eq 'nicht gefunden' unless verb == :head
|
497
|
+
get('/de/foo').status.should eq 404
|
498
|
+
last_response.body.should eq 'nicht gefunden' unless verb == :head
|
500
499
|
end
|
501
500
|
|
502
501
|
it 'falls back to the handler defined in the base app' do
|
@@ -508,12 +507,12 @@ describe Sinatra::Namespace do
|
|
508
507
|
error(404) { 'nicht gefunden' }
|
509
508
|
end
|
510
509
|
end
|
511
|
-
send(verb, '/foo').status.should
|
512
|
-
last_response.body.should
|
513
|
-
get('/en/foo').status.should
|
514
|
-
last_response.body.should
|
515
|
-
get('/de/foo').status.should
|
516
|
-
last_response.body.should
|
510
|
+
send(verb, '/foo').status.should eq 404
|
511
|
+
last_response.body.should eq 'not found...' unless verb == :head
|
512
|
+
get('/en/foo').status.should eq 404
|
513
|
+
last_response.body.should eq 'not found...' unless verb == :head
|
514
|
+
get('/de/foo').status.should eq 404
|
515
|
+
last_response.body.should eq 'nicht gefunden' unless verb == :head
|
517
516
|
end
|
518
517
|
|
519
518
|
it 'can be customized for specific Exception classes' do
|
@@ -543,10 +542,28 @@ describe Sinatra::Namespace do
|
|
543
542
|
end
|
544
543
|
end
|
545
544
|
end
|
546
|
-
get('/en/foo').status.should
|
547
|
-
last_response.body.should
|
548
|
-
get('/de/foo').status.should
|
549
|
-
last_response.body.should
|
545
|
+
get('/en/foo').status.should eq 401
|
546
|
+
last_response.body.should eq 'auth failed' unless verb == :head
|
547
|
+
get('/de/foo').status.should eq 406
|
548
|
+
last_response.body.should eq 'methode nicht erlaubt' unless verb == :head
|
549
|
+
end
|
550
|
+
|
551
|
+
it "allows custom error handlers when namespace is declared as /en/:id. Issue #119" do
|
552
|
+
mock_app {
|
553
|
+
class CError < StandardError;
|
554
|
+
end
|
555
|
+
|
556
|
+
error { raise "should not come here" }
|
557
|
+
|
558
|
+
namespace('/en/:id') do
|
559
|
+
error(CError) { 201 }
|
560
|
+
get '/?' do
|
561
|
+
raise CError
|
562
|
+
end
|
563
|
+
end
|
564
|
+
}
|
565
|
+
|
566
|
+
get('/en/1').status.should == 201
|
550
567
|
end
|
551
568
|
end
|
552
569
|
|
@@ -561,8 +578,8 @@ describe Sinatra::Namespace do
|
|
561
578
|
end
|
562
579
|
end
|
563
580
|
|
564
|
-
send(verb, '/').body.should
|
565
|
-
send(verb, '/foo').body.should
|
581
|
+
send(verb, '/').body.should eq 'hi'
|
582
|
+
send(verb, '/foo').body.should eq 'hi'
|
566
583
|
end
|
567
584
|
|
568
585
|
specify 'can be nested' do
|
@@ -575,8 +592,8 @@ describe Sinatra::Namespace do
|
|
575
592
|
end
|
576
593
|
end
|
577
594
|
|
578
|
-
send(verb, '/').body.should
|
579
|
-
send(verb, '/foo').body.should
|
595
|
+
send(verb, '/').body.should eq 'hi'
|
596
|
+
send(verb, '/foo').body.should eq 'ho'
|
580
597
|
end
|
581
598
|
|
582
599
|
specify 'can use a custom views directory' do
|
@@ -589,8 +606,8 @@ describe Sinatra::Namespace do
|
|
589
606
|
end
|
590
607
|
end
|
591
608
|
|
592
|
-
send(verb, '/').body.should
|
593
|
-
send(verb, '/foo').body.should
|
609
|
+
send(verb, '/').body.should eq "hi\n"
|
610
|
+
send(verb, '/foo').body.should eq "ho\n"
|
594
611
|
end
|
595
612
|
|
596
613
|
specify 'default to the base app\'s layout' do
|
@@ -604,8 +621,8 @@ describe Sinatra::Namespace do
|
|
604
621
|
end
|
605
622
|
end
|
606
623
|
|
607
|
-
send(verb, '/').body.should
|
608
|
-
send(verb, '/foo').body.should
|
624
|
+
send(verb, '/').body.should eq 'he said: hi'
|
625
|
+
send(verb, '/foo').body.should eq 'he said: ho'
|
609
626
|
end
|
610
627
|
|
611
628
|
specify 'can define nested layouts' do
|
@@ -619,8 +636,8 @@ describe Sinatra::Namespace do
|
|
619
636
|
end
|
620
637
|
end
|
621
638
|
|
622
|
-
send(verb, '/').body.should
|
623
|
-
send(verb, '/foo').body.should
|
639
|
+
send(verb, '/').body.should eq 'Hello World!'
|
640
|
+
send(verb, '/foo').body.should eq 'Hi World!'
|
624
641
|
end
|
625
642
|
end
|
626
643
|
end
|
@@ -634,7 +651,7 @@ describe Sinatra::Namespace do
|
|
634
651
|
value = foo
|
635
652
|
end
|
636
653
|
end
|
637
|
-
value.should
|
654
|
+
value.should eq 42
|
638
655
|
end
|
639
656
|
|
640
657
|
specify 'can be registered within a namespace' do
|
@@ -647,8 +664,8 @@ describe Sinatra::Namespace do
|
|
647
664
|
end
|
648
665
|
b = views
|
649
666
|
end
|
650
|
-
a.should
|
651
|
-
b.should_not
|
667
|
+
a.should eq 'CUSTOM!!!'
|
668
|
+
b.should_not eq 'CUSTOM!!!'
|
652
669
|
end
|
653
670
|
|
654
671
|
specify 'trigger the route_added hook' do
|
@@ -664,7 +681,7 @@ describe Sinatra::Namespace do
|
|
664
681
|
end
|
665
682
|
get('/bar') { }
|
666
683
|
end
|
667
|
-
route[1].should
|
684
|
+
route[1].should eq '/foo'
|
668
685
|
end
|
669
686
|
|
670
687
|
specify 'prevent app-global settings from being changed' do
|
@@ -673,4 +690,52 @@ describe Sinatra::Namespace do
|
|
673
690
|
end
|
674
691
|
end
|
675
692
|
end
|
693
|
+
|
694
|
+
describe 'settings' do
|
695
|
+
it 'provides access to top-level settings' do
|
696
|
+
mock_app do
|
697
|
+
set :foo, 'ok'
|
698
|
+
|
699
|
+
namespace '/foo' do
|
700
|
+
get '/bar' do
|
701
|
+
settings.foo
|
702
|
+
end
|
703
|
+
end
|
704
|
+
end
|
705
|
+
|
706
|
+
get('/foo/bar').status.should == 200
|
707
|
+
last_response.body.should == 'ok'
|
708
|
+
end
|
709
|
+
|
710
|
+
it 'uses some repro' do
|
711
|
+
mock_app do
|
712
|
+
set :foo, 42
|
713
|
+
|
714
|
+
namespace '/foo' do
|
715
|
+
get '/bar' do
|
716
|
+
#settings.respond_to?(:foo).to_s
|
717
|
+
settings.foo.to_s
|
718
|
+
end
|
719
|
+
end
|
720
|
+
end
|
721
|
+
|
722
|
+
get('/foo/bar').status.should == 200
|
723
|
+
last_response.body.should == '42'
|
724
|
+
end
|
725
|
+
|
726
|
+
it 'allows checking setting existance with respond_to?' do
|
727
|
+
mock_app do
|
728
|
+
set :foo, 42
|
729
|
+
|
730
|
+
namespace '/foo' do
|
731
|
+
get '/bar' do
|
732
|
+
settings.respond_to?(:foo).to_s
|
733
|
+
end
|
734
|
+
end
|
735
|
+
end
|
736
|
+
|
737
|
+
get('/foo/bar').status.should == 200
|
738
|
+
last_response.body.should == 'true'
|
739
|
+
end
|
740
|
+
end
|
676
741
|
end
|