darkhelmet-sinatra 0.9.1.1 → 0.10.1
Sign up to get free protection for your applications and to get access to all the features.
- data/AUTHORS +2 -0
- data/CHANGES +180 -0
- data/LICENSE +1 -1
- data/README.jp.rdoc +552 -0
- data/README.rdoc +177 -38
- data/Rakefile +18 -25
- data/lib/sinatra.rb +1 -2
- data/lib/sinatra/base.rb +405 -305
- data/lib/sinatra/main.rb +5 -24
- data/lib/sinatra/showexceptions.rb +303 -0
- data/lib/sinatra/tilt.rb +509 -0
- data/sinatra.gemspec +21 -51
- data/test/base_test.rb +123 -93
- data/test/builder_test.rb +2 -1
- data/test/contest.rb +64 -0
- data/test/erb_test.rb +1 -1
- data/test/erubis_test.rb +82 -0
- data/test/extensions_test.rb +24 -8
- data/test/filter_test.rb +99 -3
- data/test/haml_test.rb +25 -3
- data/test/helper.rb +43 -48
- data/test/helpers_test.rb +500 -424
- data/test/mapped_error_test.rb +163 -137
- data/test/middleware_test.rb +3 -3
- data/test/request_test.rb +16 -1
- data/test/response_test.rb +2 -2
- data/test/result_test.rb +1 -1
- data/test/route_added_hook_test.rb +59 -0
- data/test/routing_test.rb +170 -22
- data/test/sass_test.rb +44 -1
- data/test/server_test.rb +19 -13
- data/test/sinatra_test.rb +1 -1
- data/test/static_test.rb +9 -2
- data/test/templates_test.rb +78 -11
- data/test/views/error.builder +3 -0
- data/test/views/error.erb +3 -0
- data/test/views/error.erubis +3 -0
- data/test/views/error.haml +3 -0
- data/test/views/error.sass +2 -0
- data/test/views/foo/hello.test +1 -0
- data/test/views/hello.erubis +1 -0
- data/test/views/layout2.erubis +2 -0
- metadata +37 -55
- 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 -233
- data/compat/helper.rb +0 -30
- 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 -57
- 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 -250
- data/lib/sinatra/test.rb +0 -126
- 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/data/reload_app_file.rb +0 -3
- data/test/options_test.rb +0 -374
- data/test/reload_test.rb +0 -68
- data/test/test_test.rb +0 -144
data/compat/helper.rb
DELETED
@@ -1,30 +0,0 @@
|
|
1
|
-
require 'rubygems'
|
2
|
-
require 'mocha'
|
3
|
-
|
4
|
-
# disable warnings in compat specs.
|
5
|
-
$VERBOSE = nil
|
6
|
-
|
7
|
-
$:.unshift File.dirname(File.dirname(__FILE__)) + "/lib"
|
8
|
-
|
9
|
-
ENV['RACK_ENV'] ||= 'test'
|
10
|
-
|
11
|
-
require 'sinatra'
|
12
|
-
require 'sinatra/test'
|
13
|
-
require 'sinatra/test/unit'
|
14
|
-
require 'sinatra/test/spec'
|
15
|
-
|
16
|
-
module Sinatra::Test
|
17
|
-
# we need to remove the new test helper methods since they conflict with
|
18
|
-
# the top-level methods of the same name.
|
19
|
-
%w(get head post put delete).each do |verb|
|
20
|
-
remove_method verb
|
21
|
-
end
|
22
|
-
include Sinatra::Delegator
|
23
|
-
end
|
24
|
-
|
25
|
-
class Test::Unit::TestCase
|
26
|
-
include Sinatra::Test
|
27
|
-
def setup
|
28
|
-
@app = lambda { |env| Sinatra::Application.call(env) }
|
29
|
-
end
|
30
|
-
end
|
data/compat/mapped_error_test.rb
DELETED
@@ -1,72 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/helper'
|
2
|
-
|
3
|
-
class FooError < RuntimeError; end
|
4
|
-
|
5
|
-
context "Mapped errors" do
|
6
|
-
|
7
|
-
setup do
|
8
|
-
Sinatra.application = nil
|
9
|
-
Sinatra.application.options.raise_errors = false
|
10
|
-
end
|
11
|
-
|
12
|
-
specify "are rescued and run in context" do
|
13
|
-
|
14
|
-
error FooError do
|
15
|
-
'MAPPED ERROR!'
|
16
|
-
end
|
17
|
-
|
18
|
-
get '/' do
|
19
|
-
raise FooError
|
20
|
-
end
|
21
|
-
|
22
|
-
get_it '/'
|
23
|
-
|
24
|
-
should.be.server_error
|
25
|
-
body.should.equal 'MAPPED ERROR!'
|
26
|
-
|
27
|
-
end
|
28
|
-
|
29
|
-
specify "renders empty if no each method on result" do
|
30
|
-
|
31
|
-
error FooError do
|
32
|
-
nil
|
33
|
-
end
|
34
|
-
|
35
|
-
get '/' do
|
36
|
-
raise FooError
|
37
|
-
end
|
38
|
-
|
39
|
-
get_it '/'
|
40
|
-
|
41
|
-
should.be.server_error
|
42
|
-
body.should.be.empty
|
43
|
-
|
44
|
-
end
|
45
|
-
|
46
|
-
specify "doesn't override status if set" do
|
47
|
-
|
48
|
-
error FooError do
|
49
|
-
status(200)
|
50
|
-
end
|
51
|
-
|
52
|
-
get '/' do
|
53
|
-
raise FooError
|
54
|
-
end
|
55
|
-
|
56
|
-
get_it '/'
|
57
|
-
|
58
|
-
should.be.ok
|
59
|
-
|
60
|
-
end
|
61
|
-
|
62
|
-
specify "raises errors when the raise_errors option is set" do
|
63
|
-
Sinatra.application.options.raise_errors = true
|
64
|
-
error FooError do
|
65
|
-
end
|
66
|
-
get '/' do
|
67
|
-
raise FooError
|
68
|
-
end
|
69
|
-
assert_raises(FooError) { get_it('/') }
|
70
|
-
end
|
71
|
-
|
72
|
-
end
|
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,57 +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
|
-
end
|
56
|
-
|
57
|
-
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
|
-
|