sinatra-sinatra 0.9.2 → 0.10.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +1 -1
- data/README.rdoc +1 -1
- data/Rakefile +1 -20
- data/lib/sinatra.rb +0 -1
- data/lib/sinatra/base.rb +4 -27
- data/sinatra.gemspec +4 -45
- data/test/server_test.rb +14 -10
- data/test/templates_test.rb +22 -0
- data/test/views/foo/hello.test +1 -0
- metadata +4 -46
- data/compat/app_test.rb +0 -282
- data/compat/application_test.rb +0 -262
- data/compat/builder_test.rb +0 -101
- data/compat/compat_test.rb +0 -12
- data/compat/custom_error_test.rb +0 -62
- data/compat/erb_test.rb +0 -136
- data/compat/events_test.rb +0 -78
- data/compat/filter_test.rb +0 -30
- data/compat/haml_test.rb +0 -236
- data/compat/helper.rb +0 -33
- data/compat/mapped_error_test.rb +0 -72
- data/compat/pipeline_test.rb +0 -45
- data/compat/public/foo.xml +0 -1
- data/compat/sass_test.rb +0 -67
- data/compat/sessions_test.rb +0 -42
- data/compat/streaming_test.rb +0 -133
- data/compat/sym_params_test.rb +0 -19
- data/compat/template_test.rb +0 -30
- data/compat/use_in_file_templates_test.rb +0 -47
- data/compat/views/foo.builder +0 -1
- data/compat/views/foo.erb +0 -1
- data/compat/views/foo.haml +0 -1
- data/compat/views/foo.sass +0 -2
- data/compat/views/foo_layout.erb +0 -2
- data/compat/views/foo_layout.haml +0 -2
- data/compat/views/layout_test/foo.builder +0 -1
- data/compat/views/layout_test/foo.erb +0 -1
- data/compat/views/layout_test/foo.haml +0 -1
- data/compat/views/layout_test/foo.sass +0 -2
- data/compat/views/layout_test/layout.builder +0 -3
- data/compat/views/layout_test/layout.erb +0 -1
- data/compat/views/layout_test/layout.haml +0 -1
- data/compat/views/layout_test/layout.sass +0 -2
- data/compat/views/no_layout/no_layout.builder +0 -1
- data/compat/views/no_layout/no_layout.haml +0 -1
- data/lib/sinatra/compat.rb +0 -266
- data/lib/sinatra/test.rb +0 -128
- data/lib/sinatra/test/bacon.rb +0 -19
- data/lib/sinatra/test/rspec.rb +0 -13
- data/lib/sinatra/test/spec.rb +0 -11
- data/lib/sinatra/test/unit.rb +0 -13
- data/test/test_test.rb +0 -152
data/compat/pipeline_test.rb
DELETED
@@ -1,45 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/helper'
|
2
|
-
|
3
|
-
class UpcaseMiddleware
|
4
|
-
def initialize(app, *args, &block)
|
5
|
-
@app = app
|
6
|
-
@args = args
|
7
|
-
@block = block
|
8
|
-
end
|
9
|
-
def call(env)
|
10
|
-
env['PATH_INFO'] = env['PATH_INFO'].to_s.upcase
|
11
|
-
@app.call(env)
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
context "Middleware Pipelines" do
|
16
|
-
|
17
|
-
setup do
|
18
|
-
Sinatra.application = nil
|
19
|
-
@app = Sinatra.application
|
20
|
-
end
|
21
|
-
|
22
|
-
teardown do
|
23
|
-
Sinatra.application = nil
|
24
|
-
end
|
25
|
-
|
26
|
-
specify "should add middleware with use" do
|
27
|
-
block = Proc.new { |env| }
|
28
|
-
@app.use UpcaseMiddleware
|
29
|
-
@app.use UpcaseMiddleware, "foo", "bar"
|
30
|
-
@app.use UpcaseMiddleware, "foo", "bar", &block
|
31
|
-
@app.send(:middleware).should.include([UpcaseMiddleware, [], nil])
|
32
|
-
@app.send(:middleware).should.include([UpcaseMiddleware, ["foo", "bar"], nil])
|
33
|
-
@app.send(:middleware).should.include([UpcaseMiddleware, ["foo", "bar"], block])
|
34
|
-
end
|
35
|
-
|
36
|
-
specify "should run middleware added with use" do
|
37
|
-
get('/foo') { "FAIL!" }
|
38
|
-
get('/FOO') { "PASS!" }
|
39
|
-
use UpcaseMiddleware
|
40
|
-
get_it '/foo'
|
41
|
-
should.be.ok
|
42
|
-
body.should.equal "PASS!"
|
43
|
-
end
|
44
|
-
|
45
|
-
end
|
data/compat/public/foo.xml
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
<foo></foo>
|
data/compat/sass_test.rb
DELETED
@@ -1,67 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/helper'
|
2
|
-
|
3
|
-
context "Sass" do
|
4
|
-
|
5
|
-
setup do
|
6
|
-
Sinatra.application = nil
|
7
|
-
end
|
8
|
-
|
9
|
-
context "Templates (in general)" do
|
10
|
-
|
11
|
-
setup do
|
12
|
-
Sinatra.application = nil
|
13
|
-
end
|
14
|
-
|
15
|
-
specify "are read from files if Symbols" do
|
16
|
-
|
17
|
-
get '/from_file' do
|
18
|
-
sass :foo, :views_directory => File.dirname(__FILE__) + "/views"
|
19
|
-
end
|
20
|
-
|
21
|
-
get_it '/from_file'
|
22
|
-
should.be.ok
|
23
|
-
body.should.equal "#sass {\n background_color: #FFF; }\n"
|
24
|
-
|
25
|
-
end
|
26
|
-
|
27
|
-
specify "raise an error if template not found" do
|
28
|
-
get '/' do
|
29
|
-
sass :not_found
|
30
|
-
end
|
31
|
-
|
32
|
-
lambda { get_it '/' }.should.raise(Errno::ENOENT)
|
33
|
-
end
|
34
|
-
|
35
|
-
specify "ignore default layout file with .sass extension" do
|
36
|
-
get '/' do
|
37
|
-
sass :foo, :views_directory => File.dirname(__FILE__) + "/views/layout_test"
|
38
|
-
end
|
39
|
-
|
40
|
-
get_it '/'
|
41
|
-
should.be.ok
|
42
|
-
body.should.equal "#sass {\n background_color: #FFF; }\n"
|
43
|
-
end
|
44
|
-
|
45
|
-
specify "ignore explicitly specified layout file" do
|
46
|
-
get '/' do
|
47
|
-
sass :foo, :layout => :layout, :views_directory => File.dirname(__FILE__) + "/views/layout_test"
|
48
|
-
end
|
49
|
-
|
50
|
-
get_it '/'
|
51
|
-
should.be.ok
|
52
|
-
body.should.equal "#sass {\n background_color: #FFF; }\n"
|
53
|
-
end
|
54
|
-
|
55
|
-
it "passes :sass option to the Sass engine" do
|
56
|
-
get '/' do
|
57
|
-
sass "#sass\n :background-color #FFF\n :color #000\n", :sass => {:style => :compact}
|
58
|
-
end
|
59
|
-
|
60
|
-
get_it '/'
|
61
|
-
should.be.ok
|
62
|
-
body.should.equal "#sass { background-color: #FFF; color: #000; }\n"
|
63
|
-
end
|
64
|
-
|
65
|
-
end
|
66
|
-
|
67
|
-
end
|
data/compat/sessions_test.rb
DELETED
@@ -1,42 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/helper'
|
2
|
-
|
3
|
-
context "Sessions" do
|
4
|
-
|
5
|
-
setup { Sinatra.application = nil }
|
6
|
-
|
7
|
-
specify "should be off by default" do
|
8
|
-
get '/asdf' do
|
9
|
-
session[:test] = true
|
10
|
-
"asdf"
|
11
|
-
end
|
12
|
-
|
13
|
-
get '/test' do
|
14
|
-
session[:test] == true ? "true" : "false"
|
15
|
-
end
|
16
|
-
|
17
|
-
get_it '/asdf', {}, 'HTTP_HOST' => 'foo.sinatrarb.com'
|
18
|
-
assert ok?
|
19
|
-
assert !include?('Set-Cookie')
|
20
|
-
end
|
21
|
-
|
22
|
-
specify "should be able to store data accross requests" do
|
23
|
-
set_option :sessions, true
|
24
|
-
set_option :environment, :not_test # necessary because sessions are disabled
|
25
|
-
|
26
|
-
get '/foo' do
|
27
|
-
session[:test] = true
|
28
|
-
"asdf"
|
29
|
-
end
|
30
|
-
|
31
|
-
get '/bar' do
|
32
|
-
session[:test] == true ? "true" : "false"
|
33
|
-
end
|
34
|
-
|
35
|
-
get_it '/foo', :env => { :host => 'foo.sinatrarb.com' }
|
36
|
-
assert ok?
|
37
|
-
assert include?('Set-Cookie')
|
38
|
-
|
39
|
-
set_option :environment, :test
|
40
|
-
end
|
41
|
-
|
42
|
-
end
|
data/compat/streaming_test.rb
DELETED
@@ -1,133 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/helper'
|
2
|
-
|
3
|
-
context "Static files (by default)" do
|
4
|
-
|
5
|
-
setup do
|
6
|
-
Sinatra.application = nil
|
7
|
-
Sinatra.application.options.public = File.dirname(__FILE__) + '/public'
|
8
|
-
end
|
9
|
-
|
10
|
-
specify "are served from root/public" do
|
11
|
-
get_it '/foo.xml'
|
12
|
-
should.be.ok
|
13
|
-
headers['Content-Length'].should.equal '12'
|
14
|
-
headers['Content-Type'].should.equal 'application/xml'
|
15
|
-
body.should.equal "<foo></foo>\n"
|
16
|
-
end
|
17
|
-
|
18
|
-
specify "are not served when verb is not GET or HEAD" do
|
19
|
-
post_it '/foo.xml'
|
20
|
-
# these should actually be giving back a 405 Method Not Allowed but that
|
21
|
-
# complicates the routing logic quite a bit.
|
22
|
-
should.be.not_found
|
23
|
-
status.should.equal 404
|
24
|
-
end
|
25
|
-
|
26
|
-
specify "are served when verb is HEAD but missing a body" do
|
27
|
-
head_it '/foo.xml'
|
28
|
-
should.be.ok
|
29
|
-
headers['Content-Length'].should.equal '12'
|
30
|
-
headers['Content-Type'].should.equal 'application/xml'
|
31
|
-
body.should.equal ""
|
32
|
-
end
|
33
|
-
|
34
|
-
# static files override dynamic/internal events and ...
|
35
|
-
specify "are served when conflicting events exists" do
|
36
|
-
get '/foo.xml' do
|
37
|
-
'this is not foo.xml!'
|
38
|
-
end
|
39
|
-
get_it '/foo.xml'
|
40
|
-
should.be.ok
|
41
|
-
body.should.equal "<foo></foo>\n"
|
42
|
-
end
|
43
|
-
|
44
|
-
specify "are irrelevant when request_method is not GET/HEAD" do
|
45
|
-
put '/foo.xml' do
|
46
|
-
'putted!'
|
47
|
-
end
|
48
|
-
put_it '/foo.xml'
|
49
|
-
should.be.ok
|
50
|
-
body.should.equal 'putted!'
|
51
|
-
|
52
|
-
get_it '/foo.xml'
|
53
|
-
should.be.ok
|
54
|
-
body.should.equal "<foo></foo>\n"
|
55
|
-
end
|
56
|
-
|
57
|
-
specify "include a Last-Modified header" do
|
58
|
-
last_modified = File.mtime(Sinatra.application.options.public + '/foo.xml')
|
59
|
-
get_it('/foo.xml')
|
60
|
-
should.be.ok
|
61
|
-
body.should.not.be.empty
|
62
|
-
headers['Last-Modified'].should.equal last_modified.httpdate
|
63
|
-
end
|
64
|
-
|
65
|
-
# Deprecated. Use: ConditionalGet middleware.
|
66
|
-
specify "are not served when If-Modified-Since matches" do
|
67
|
-
last_modified = File.mtime(Sinatra.application.options.public + '/foo.xml')
|
68
|
-
@request = Rack::MockRequest.new(Sinatra.application)
|
69
|
-
@response = @request.get('/foo.xml', 'HTTP_IF_MODIFIED_SINCE' => last_modified.httpdate)
|
70
|
-
status.should.equal 304
|
71
|
-
body.should.be.empty
|
72
|
-
end
|
73
|
-
|
74
|
-
specify "should omit Content-Disposition headers" do
|
75
|
-
get_it('/foo.xml')
|
76
|
-
should.be.ok
|
77
|
-
headers['Content-Disposition'].should.be.nil
|
78
|
-
headers['Content-Transfer-Encoding'].should.be.nil
|
79
|
-
end
|
80
|
-
|
81
|
-
specify "should be served even if their path is url escaped" do
|
82
|
-
get_it('/fo%6f.xml')
|
83
|
-
should.be.ok
|
84
|
-
body.should.equal "<foo></foo>\n"
|
85
|
-
end
|
86
|
-
|
87
|
-
end
|
88
|
-
|
89
|
-
context "SendData" do
|
90
|
-
|
91
|
-
setup do
|
92
|
-
Sinatra.application = nil
|
93
|
-
end
|
94
|
-
|
95
|
-
# Deprecated. send_data is going away.
|
96
|
-
specify "should send the data with options" do
|
97
|
-
get '/' do
|
98
|
-
send_data 'asdf', :status => 500
|
99
|
-
end
|
100
|
-
|
101
|
-
get_it '/'
|
102
|
-
|
103
|
-
should.be.server_error
|
104
|
-
body.should.equal 'asdf'
|
105
|
-
end
|
106
|
-
|
107
|
-
# Deprecated. The Content-Disposition is no longer handled by sendfile.
|
108
|
-
specify "should include a Content-Disposition header" do
|
109
|
-
get '/' do
|
110
|
-
send_file File.dirname(__FILE__) + '/public/foo.xml',
|
111
|
-
:disposition => 'attachment'
|
112
|
-
end
|
113
|
-
|
114
|
-
get_it '/'
|
115
|
-
|
116
|
-
should.be.ok
|
117
|
-
headers['Content-Disposition'].should.not.be.nil
|
118
|
-
headers['Content-Disposition'].should.equal 'attachment; filename="foo.xml"'
|
119
|
-
end
|
120
|
-
|
121
|
-
specify "should include a Content-Disposition header when :disposition set to attachment" do
|
122
|
-
get '/' do
|
123
|
-
send_file File.dirname(__FILE__) + '/public/foo.xml',
|
124
|
-
:disposition => 'attachment'
|
125
|
-
end
|
126
|
-
|
127
|
-
get_it '/'
|
128
|
-
|
129
|
-
should.be.ok
|
130
|
-
headers['Content-Disposition'].should.not.be.nil
|
131
|
-
headers['Content-Disposition'].should.equal 'attachment; filename="foo.xml"'
|
132
|
-
end
|
133
|
-
end
|
data/compat/sym_params_test.rb
DELETED
@@ -1,19 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/helper'
|
2
|
-
|
3
|
-
context "Symbol Params" do
|
4
|
-
|
5
|
-
setup do
|
6
|
-
Sinatra.application = nil
|
7
|
-
end
|
8
|
-
|
9
|
-
specify "should be accessable as Strings or Symbols" do
|
10
|
-
get '/' do
|
11
|
-
params[:foo] + params['foo']
|
12
|
-
end
|
13
|
-
|
14
|
-
get_it '/', :foo => "X"
|
15
|
-
assert_equal('XX', body)
|
16
|
-
end
|
17
|
-
|
18
|
-
end
|
19
|
-
|
data/compat/template_test.rb
DELETED
@@ -1,30 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/helper'
|
2
|
-
|
3
|
-
context "Templates" do
|
4
|
-
|
5
|
-
specify "are read from files if Symbols" do
|
6
|
-
|
7
|
-
get '/from_file' do
|
8
|
-
@name = 'Alena'
|
9
|
-
erb :foo, :views_directory => File.dirname(__FILE__) + "/views"
|
10
|
-
end
|
11
|
-
|
12
|
-
get_it '/from_file'
|
13
|
-
|
14
|
-
body.should.equal 'You rock Alena!'
|
15
|
-
|
16
|
-
end
|
17
|
-
|
18
|
-
specify "use layout.ext by default if available" do
|
19
|
-
|
20
|
-
get '/layout_from_file' do
|
21
|
-
erb :foo, :views_directory => File.dirname(__FILE__) + "/views/layout_test"
|
22
|
-
end
|
23
|
-
|
24
|
-
get_it '/layout_from_file'
|
25
|
-
should.be.ok
|
26
|
-
body.should.equal "x This is foo! x \n"
|
27
|
-
|
28
|
-
end
|
29
|
-
|
30
|
-
end
|
@@ -1,47 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/helper'
|
2
|
-
|
3
|
-
context "Rendering in file templates" do
|
4
|
-
|
5
|
-
setup do
|
6
|
-
Sinatra.application = nil
|
7
|
-
use_in_file_templates!
|
8
|
-
end
|
9
|
-
|
10
|
-
specify "should set template" do
|
11
|
-
assert Sinatra.application.templates[:foo]
|
12
|
-
end
|
13
|
-
|
14
|
-
specify "should set layout" do
|
15
|
-
assert Sinatra.application.templates[:layout]
|
16
|
-
end
|
17
|
-
|
18
|
-
specify "should render without layout if specified" do
|
19
|
-
get '/' do
|
20
|
-
haml :foo, :layout => false
|
21
|
-
end
|
22
|
-
|
23
|
-
get_it '/'
|
24
|
-
assert_equal "this is foo\n", body
|
25
|
-
end
|
26
|
-
|
27
|
-
specify "should render with layout if specified" do
|
28
|
-
get '/' do
|
29
|
-
haml :foo
|
30
|
-
end
|
31
|
-
|
32
|
-
get_it '/'
|
33
|
-
assert_equal "X\nthis is foo\nX\n", body
|
34
|
-
end
|
35
|
-
|
36
|
-
end
|
37
|
-
|
38
|
-
__END__
|
39
|
-
|
40
|
-
@@ foo
|
41
|
-
this is foo
|
42
|
-
|
43
|
-
@@ layout
|
44
|
-
X
|
45
|
-
= yield
|
46
|
-
X
|
47
|
-
|
data/compat/views/foo.builder
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
xml.exclaim "You rock #{@name}!"
|
data/compat/views/foo.erb
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
You rock <%= @name %>!
|
data/compat/views/foo.haml
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
== You rock #{@name}!
|
data/compat/views/foo.sass
DELETED
data/compat/views/foo_layout.erb
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
xml.this "is foo!"
|
@@ -1 +0,0 @@
|
|
1
|
-
This is foo!
|
@@ -1 +0,0 @@
|
|
1
|
-
This is foo!
|
@@ -1 +0,0 @@
|
|
1
|
-
x <%= yield %> x
|
@@ -1 +0,0 @@
|
|
1
|
-
== x #{yield} x
|