sinatra 0.9.6 → 1.0.a
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of sinatra might be problematic. Click here for more details.
- data/CHANGES +83 -29
- data/README.jp.rdoc +552 -0
- data/README.rdoc +31 -9
- data/Rakefile +73 -91
- data/lib/sinatra.rb +0 -1
- data/lib/sinatra/base.rb +248 -269
- data/lib/sinatra/main.rb +3 -11
- data/lib/sinatra/tilt.rb +509 -0
- data/sinatra.gemspec +15 -49
- data/test/erubis_test.rb +82 -0
- data/test/extensions_test.rb +1 -1
- data/test/filter_test.rb +125 -3
- data/test/helpers_test.rb +59 -2
- data/test/mapped_error_test.rb +31 -0
- data/test/middleware_test.rb +1 -1
- data/test/request_test.rb +15 -0
- data/test/routing_test.rb +76 -0
- data/test/{options_test.rb → settings_test.rb} +46 -50
- data/test/static_test.rb +13 -0
- data/test/templates_test.rb +43 -10
- data/test/views/error.erubis +3 -0
- data/test/views/hello.erubis +1 -0
- data/test/views/layout2.erubis +2 -0
- metadata +61 -88
- 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 -237
- data/compat/helper.rb +0 -34
- 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 -18
- 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 -258
- data/lib/sinatra/test.rb +0 -129
- 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/render_backtrace_test.rb +0 -145
- data/test/test_test.rb +0 -155
data/sinatra.gemspec
CHANGED
@@ -3,13 +3,13 @@ Gem::Specification.new do |s|
|
|
3
3
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
4
4
|
|
5
5
|
s.name = 'sinatra'
|
6
|
-
s.version = '0.
|
7
|
-
s.date = '2010-
|
6
|
+
s.version = '1.0.a'
|
7
|
+
s.date = '2010-01-28'
|
8
8
|
|
9
9
|
s.description = "Classy web-development dressed in a DSL"
|
10
10
|
s.summary = "Classy web-development dressed in a DSL"
|
11
11
|
|
12
|
-
s.authors = ["Blake Mizerany"]
|
12
|
+
s.authors = ["Blake Mizerany", "Ryan Tomayko", "Simon Rozet"]
|
13
13
|
s.email = "sinatrarb@googlegroups.com"
|
14
14
|
|
15
15
|
# = MANIFEST =
|
@@ -17,60 +17,22 @@ Gem::Specification.new do |s|
|
|
17
17
|
AUTHORS
|
18
18
|
CHANGES
|
19
19
|
LICENSE
|
20
|
+
README.jp.rdoc
|
20
21
|
README.rdoc
|
21
22
|
Rakefile
|
22
|
-
compat/app_test.rb
|
23
|
-
compat/application_test.rb
|
24
|
-
compat/builder_test.rb
|
25
|
-
compat/compat_test.rb
|
26
|
-
compat/custom_error_test.rb
|
27
|
-
compat/erb_test.rb
|
28
|
-
compat/events_test.rb
|
29
|
-
compat/filter_test.rb
|
30
|
-
compat/haml_test.rb
|
31
|
-
compat/helper.rb
|
32
|
-
compat/mapped_error_test.rb
|
33
|
-
compat/pipeline_test.rb
|
34
|
-
compat/public/foo.xml
|
35
|
-
compat/sass_test.rb
|
36
|
-
compat/sessions_test.rb
|
37
|
-
compat/streaming_test.rb
|
38
|
-
compat/sym_params_test.rb
|
39
|
-
compat/template_test.rb
|
40
|
-
compat/use_in_file_templates_test.rb
|
41
|
-
compat/views/foo.builder
|
42
|
-
compat/views/foo.erb
|
43
|
-
compat/views/foo.haml
|
44
|
-
compat/views/foo.sass
|
45
|
-
compat/views/foo_layout.erb
|
46
|
-
compat/views/foo_layout.haml
|
47
|
-
compat/views/layout_test/foo.builder
|
48
|
-
compat/views/layout_test/foo.erb
|
49
|
-
compat/views/layout_test/foo.haml
|
50
|
-
compat/views/layout_test/foo.sass
|
51
|
-
compat/views/layout_test/layout.builder
|
52
|
-
compat/views/layout_test/layout.erb
|
53
|
-
compat/views/layout_test/layout.haml
|
54
|
-
compat/views/layout_test/layout.sass
|
55
|
-
compat/views/no_layout/no_layout.builder
|
56
|
-
compat/views/no_layout/no_layout.haml
|
57
23
|
lib/sinatra.rb
|
58
24
|
lib/sinatra/base.rb
|
59
|
-
lib/sinatra/compat.rb
|
60
25
|
lib/sinatra/images/404.png
|
61
26
|
lib/sinatra/images/500.png
|
62
27
|
lib/sinatra/main.rb
|
63
28
|
lib/sinatra/showexceptions.rb
|
64
|
-
lib/sinatra/
|
65
|
-
lib/sinatra/test/bacon.rb
|
66
|
-
lib/sinatra/test/rspec.rb
|
67
|
-
lib/sinatra/test/spec.rb
|
68
|
-
lib/sinatra/test/unit.rb
|
29
|
+
lib/sinatra/tilt.rb
|
69
30
|
sinatra.gemspec
|
70
31
|
test/base_test.rb
|
71
32
|
test/builder_test.rb
|
72
33
|
test/contest.rb
|
73
34
|
test/erb_test.rb
|
35
|
+
test/erubis_test.rb
|
74
36
|
test/extensions_test.rb
|
75
37
|
test/filter_test.rb
|
76
38
|
test/haml_test.rb
|
@@ -78,9 +40,7 @@ Gem::Specification.new do |s|
|
|
78
40
|
test/helpers_test.rb
|
79
41
|
test/mapped_error_test.rb
|
80
42
|
test/middleware_test.rb
|
81
|
-
test/options_test.rb
|
82
43
|
test/public/favicon.ico
|
83
|
-
test/render_backtrace_test.rb
|
84
44
|
test/request_test.rb
|
85
45
|
test/response_test.rb
|
86
46
|
test/result_test.rb
|
@@ -88,22 +48,25 @@ Gem::Specification.new do |s|
|
|
88
48
|
test/routing_test.rb
|
89
49
|
test/sass_test.rb
|
90
50
|
test/server_test.rb
|
51
|
+
test/settings_test.rb
|
91
52
|
test/sinatra_test.rb
|
92
53
|
test/static_test.rb
|
93
54
|
test/templates_test.rb
|
94
|
-
test/test_test.rb
|
95
55
|
test/views/error.builder
|
96
56
|
test/views/error.erb
|
57
|
+
test/views/error.erubis
|
97
58
|
test/views/error.haml
|
98
59
|
test/views/error.sass
|
99
60
|
test/views/foo/hello.test
|
100
61
|
test/views/hello.builder
|
101
62
|
test/views/hello.erb
|
63
|
+
test/views/hello.erubis
|
102
64
|
test/views/hello.haml
|
103
65
|
test/views/hello.sass
|
104
66
|
test/views/hello.test
|
105
67
|
test/views/layout2.builder
|
106
68
|
test/views/layout2.erb
|
69
|
+
test/views/layout2.erubis
|
107
70
|
test/views/layout2.haml
|
108
71
|
test/views/layout2.test
|
109
72
|
]
|
@@ -112,9 +75,12 @@ Gem::Specification.new do |s|
|
|
112
75
|
s.test_files = s.files.select {|path| path =~ /^test\/.*_test.rb/}
|
113
76
|
|
114
77
|
s.extra_rdoc_files = %w[README.rdoc LICENSE]
|
115
|
-
s.add_dependency 'rack', '>= 0
|
116
|
-
s.add_development_dependency 'shotgun', '>= 0.
|
78
|
+
s.add_dependency 'rack', '>= 1.0'
|
79
|
+
s.add_development_dependency 'shotgun', '>= 0.6', '< 1.0'
|
117
80
|
s.add_development_dependency 'rack-test', '>= 0.3.0'
|
81
|
+
s.add_development_dependency 'haml'
|
82
|
+
s.add_development_dependency 'builder'
|
83
|
+
s.add_development_dependency 'erubis'
|
118
84
|
|
119
85
|
s.has_rdoc = true
|
120
86
|
s.homepage = "http://sinatra.rubyforge.org"
|
data/test/erubis_test.rb
ADDED
@@ -0,0 +1,82 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/helper'
|
2
|
+
require 'erubis'
|
3
|
+
|
4
|
+
class ERubisTest < Test::Unit::TestCase
|
5
|
+
def erubis_app(&block)
|
6
|
+
mock_app {
|
7
|
+
set :views, File.dirname(__FILE__) + '/views'
|
8
|
+
get '/', &block
|
9
|
+
}
|
10
|
+
get '/'
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'renders inline ERubis strings' do
|
14
|
+
erubis_app { erubis '<%= 1 + 1 %>' }
|
15
|
+
assert ok?
|
16
|
+
assert_equal '2', body
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'renders .erubis files in views path' do
|
20
|
+
erubis_app { erubis :hello }
|
21
|
+
assert ok?
|
22
|
+
assert_equal "Hello World\n", body
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'takes a :locals option' do
|
26
|
+
erubis_app {
|
27
|
+
locals = {:foo => 'Bar'}
|
28
|
+
erubis '<%= foo %>', :locals => locals
|
29
|
+
}
|
30
|
+
assert ok?
|
31
|
+
assert_equal 'Bar', body
|
32
|
+
end
|
33
|
+
|
34
|
+
it "renders with inline layouts" do
|
35
|
+
mock_app {
|
36
|
+
layout { 'THIS. IS. <%= yield.upcase %>!' }
|
37
|
+
get('/') { erubis 'Sparta' }
|
38
|
+
}
|
39
|
+
get '/'
|
40
|
+
assert ok?
|
41
|
+
assert_equal 'THIS. IS. SPARTA!', body
|
42
|
+
end
|
43
|
+
|
44
|
+
it "renders with file layouts" do
|
45
|
+
erubis_app {
|
46
|
+
erubis 'Hello World', :layout => :layout2
|
47
|
+
}
|
48
|
+
assert ok?
|
49
|
+
assert_equal "ERubis Layout!\nHello World\n", body
|
50
|
+
end
|
51
|
+
|
52
|
+
it "renders erubis with blocks" do
|
53
|
+
mock_app {
|
54
|
+
def container
|
55
|
+
@_out_buf << "THIS."
|
56
|
+
yield
|
57
|
+
@_out_buf << "SPARTA!"
|
58
|
+
end
|
59
|
+
def is; "IS." end
|
60
|
+
get '/' do
|
61
|
+
erubis '<% container do %> <%= is %> <% end %>'
|
62
|
+
end
|
63
|
+
}
|
64
|
+
get '/'
|
65
|
+
assert ok?
|
66
|
+
assert_equal 'THIS. IS. SPARTA!', body
|
67
|
+
end
|
68
|
+
|
69
|
+
it "can be used in a nested fashion for partials and whatnot" do
|
70
|
+
mock_app {
|
71
|
+
template(:inner) { "<inner><%= 'hi' %></inner>" }
|
72
|
+
template(:outer) { "<outer><%= erubis :inner %></outer>" }
|
73
|
+
get '/' do
|
74
|
+
erubis :outer
|
75
|
+
end
|
76
|
+
}
|
77
|
+
|
78
|
+
get '/'
|
79
|
+
assert ok?
|
80
|
+
assert_equal '<outer><inner>hi</inner></outer>', body
|
81
|
+
end
|
82
|
+
end
|
data/test/extensions_test.rb
CHANGED
@@ -71,7 +71,7 @@ class ExtensionsTest < Test::Unit::TestCase
|
|
71
71
|
assert !Sinatra::Delegator.private_instance_methods.include?("quux")
|
72
72
|
end
|
73
73
|
|
74
|
-
it 'will extend the Sinatra::Application by default' do
|
74
|
+
it 'will extend the Sinatra::Application application by default' do
|
75
75
|
Sinatra.register BazExtensions
|
76
76
|
assert !Sinatra::Base.respond_to?(:baz)
|
77
77
|
assert Sinatra::Application.respond_to?(:baz)
|
data/test/filter_test.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/helper'
|
2
2
|
|
3
|
-
class
|
3
|
+
class BeforeFilterTest < Test::Unit::TestCase
|
4
4
|
it "executes filters in the order defined" do
|
5
5
|
count = 0
|
6
6
|
mock_app do
|
@@ -21,7 +21,7 @@ class FilterTest < Test::Unit::TestCase
|
|
21
21
|
assert_equal 'Hello World', body
|
22
22
|
end
|
23
23
|
|
24
|
-
it "
|
24
|
+
it "can modify the request" do
|
25
25
|
mock_app {
|
26
26
|
get('/foo') { 'foo' }
|
27
27
|
get('/bar') { 'bar' }
|
@@ -44,7 +44,7 @@ class FilterTest < Test::Unit::TestCase
|
|
44
44
|
assert_equal 'bar', body
|
45
45
|
end
|
46
46
|
|
47
|
-
it "allows redirects
|
47
|
+
it "allows redirects" do
|
48
48
|
mock_app {
|
49
49
|
before { redirect '/bar' }
|
50
50
|
get('/foo') do
|
@@ -96,4 +96,126 @@ class FilterTest < Test::Unit::TestCase
|
|
96
96
|
assert ok?
|
97
97
|
assert_equal 'cool', body
|
98
98
|
end
|
99
|
+
|
100
|
+
it "runs filters defined in superclasses" do
|
101
|
+
base = Class.new(Sinatra::Base)
|
102
|
+
base.before { @foo = 'hello from superclass' }
|
103
|
+
|
104
|
+
mock_app(base) {
|
105
|
+
get('/foo') { @foo }
|
106
|
+
}
|
107
|
+
|
108
|
+
get '/foo'
|
109
|
+
assert_equal 'hello from superclass', body
|
110
|
+
end
|
111
|
+
|
112
|
+
it 'does not run before filter when serving static files' do
|
113
|
+
ran_filter = false
|
114
|
+
mock_app {
|
115
|
+
before { ran_filter = true }
|
116
|
+
set :static, true
|
117
|
+
set :public, File.dirname(__FILE__)
|
118
|
+
}
|
119
|
+
get "/#{File.basename(__FILE__)}"
|
120
|
+
assert ok?
|
121
|
+
assert_equal File.read(__FILE__), body
|
122
|
+
assert !ran_filter
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
class AfterFilterTest < Test::Unit::TestCase
|
127
|
+
it "executes filters in the order defined" do
|
128
|
+
invoked = 0
|
129
|
+
mock_app do
|
130
|
+
before { invoked = 2 }
|
131
|
+
get('/') { invoked += 2 }
|
132
|
+
after { invoked *= 2 }
|
133
|
+
end
|
134
|
+
|
135
|
+
get '/'
|
136
|
+
assert ok?
|
137
|
+
|
138
|
+
assert_equal 8, invoked
|
139
|
+
end
|
140
|
+
|
141
|
+
it "executes filters in the order defined" do
|
142
|
+
count = 0
|
143
|
+
mock_app do
|
144
|
+
get('/') { 'Hello World' }
|
145
|
+
after {
|
146
|
+
assert_equal 0, count
|
147
|
+
count = 1
|
148
|
+
}
|
149
|
+
after {
|
150
|
+
assert_equal 1, count
|
151
|
+
count = 2
|
152
|
+
}
|
153
|
+
end
|
154
|
+
|
155
|
+
get '/'
|
156
|
+
assert ok?
|
157
|
+
assert_equal 2, count
|
158
|
+
assert_equal 'Hello World', body
|
159
|
+
end
|
160
|
+
|
161
|
+
it "allows redirects" do
|
162
|
+
mock_app {
|
163
|
+
get('/foo') { 'ORLY' }
|
164
|
+
after { redirect '/bar' }
|
165
|
+
}
|
166
|
+
|
167
|
+
get '/foo'
|
168
|
+
assert redirect?
|
169
|
+
assert_equal '/bar', response['Location']
|
170
|
+
assert_equal '', body
|
171
|
+
end
|
172
|
+
|
173
|
+
it "does not modify the response with its return value" do
|
174
|
+
mock_app {
|
175
|
+
get('/foo') { 'cool' }
|
176
|
+
after { 'Hello World!' }
|
177
|
+
}
|
178
|
+
|
179
|
+
get '/foo'
|
180
|
+
assert ok?
|
181
|
+
assert_equal 'cool', body
|
182
|
+
end
|
183
|
+
|
184
|
+
it "does modify the response with halt" do
|
185
|
+
mock_app {
|
186
|
+
get '/foo' do
|
187
|
+
"should not be returned"
|
188
|
+
end
|
189
|
+
after { halt 302, 'Hi' }
|
190
|
+
}
|
191
|
+
|
192
|
+
get '/foo'
|
193
|
+
assert_equal 302, response.status
|
194
|
+
assert_equal 'Hi', body
|
195
|
+
end
|
196
|
+
|
197
|
+
it "runs filters defined in superclasses" do
|
198
|
+
count = 2
|
199
|
+
base = Class.new(Sinatra::Base)
|
200
|
+
base.after { count *= 2 }
|
201
|
+
mock_app(base) {
|
202
|
+
get('/foo') { count += 2 }
|
203
|
+
}
|
204
|
+
|
205
|
+
get '/foo'
|
206
|
+
assert_equal 8, count
|
207
|
+
end
|
208
|
+
|
209
|
+
it 'does not run after filter when serving static files' do
|
210
|
+
ran_filter = false
|
211
|
+
mock_app {
|
212
|
+
after { ran_filter = true }
|
213
|
+
set :static, true
|
214
|
+
set :public, File.dirname(__FILE__)
|
215
|
+
}
|
216
|
+
get "/#{File.basename(__FILE__)}"
|
217
|
+
assert ok?
|
218
|
+
assert_equal File.read(__FILE__), body
|
219
|
+
assert !ran_filter
|
220
|
+
end
|
99
221
|
end
|
data/test/helpers_test.rb
CHANGED
@@ -142,6 +142,19 @@ class HelpersTest < Test::Unit::TestCase
|
|
142
142
|
assert_equal 404, status
|
143
143
|
assert_equal '', body
|
144
144
|
end
|
145
|
+
|
146
|
+
it 'does not set a X-Cascade header' do
|
147
|
+
mock_app {
|
148
|
+
get '/' do
|
149
|
+
not_found
|
150
|
+
fail 'not_found should halt'
|
151
|
+
end
|
152
|
+
}
|
153
|
+
|
154
|
+
get '/'
|
155
|
+
assert_equal 404, status
|
156
|
+
assert_equal nil, response.headers['X-Cascade']
|
157
|
+
end
|
145
158
|
end
|
146
159
|
|
147
160
|
describe 'headers' do
|
@@ -188,15 +201,22 @@ class HelpersTest < Test::Unit::TestCase
|
|
188
201
|
|
189
202
|
it 'creates a new session when none provided' do
|
190
203
|
mock_app {
|
204
|
+
enable :sessions
|
205
|
+
|
191
206
|
get '/' do
|
192
207
|
assert session.empty?
|
193
208
|
session[:foo] = 'bar'
|
194
|
-
'
|
209
|
+
redirect '/hi'
|
210
|
+
end
|
211
|
+
|
212
|
+
get '/hi' do
|
213
|
+
"hi #{session[:foo]}"
|
195
214
|
end
|
196
215
|
}
|
197
216
|
|
198
217
|
get '/'
|
199
|
-
|
218
|
+
follow_redirect!
|
219
|
+
assert_equal 'hi bar', body
|
200
220
|
end
|
201
221
|
end
|
202
222
|
|
@@ -365,6 +385,43 @@ class HelpersTest < Test::Unit::TestCase
|
|
365
385
|
end
|
366
386
|
end
|
367
387
|
|
388
|
+
describe 'cache_control' do
|
389
|
+
setup do
|
390
|
+
mock_app {
|
391
|
+
get '/' do
|
392
|
+
cache_control :public, :no_cache, :max_age => 60
|
393
|
+
'Hello World'
|
394
|
+
end
|
395
|
+
}
|
396
|
+
end
|
397
|
+
|
398
|
+
it 'sets the Cache-Control header' do
|
399
|
+
get '/'
|
400
|
+
assert_equal ['public', 'no-cache', 'max-age=60'], response['Cache-Control'].split(', ')
|
401
|
+
end
|
402
|
+
end
|
403
|
+
|
404
|
+
describe 'expires' do
|
405
|
+
setup do
|
406
|
+
mock_app {
|
407
|
+
get '/' do
|
408
|
+
expires 60, :public, :no_cache
|
409
|
+
'Hello World'
|
410
|
+
end
|
411
|
+
}
|
412
|
+
end
|
413
|
+
|
414
|
+
it 'sets the Cache-Control header' do
|
415
|
+
get '/'
|
416
|
+
assert_equal ['public', 'no-cache', 'max-age=60'], response['Cache-Control'].split(', ')
|
417
|
+
end
|
418
|
+
|
419
|
+
it 'sets the Expires header' do
|
420
|
+
get '/'
|
421
|
+
assert_not_nil response['Expires']
|
422
|
+
end
|
423
|
+
end
|
424
|
+
|
368
425
|
describe 'last_modified' do
|
369
426
|
setup do
|
370
427
|
now = Time.now
|