sinatra 0.9.4 → 0.9.5
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.
- data/AUTHORS +2 -0
- data/CHANGES +25 -0
- data/README.rdoc +39 -12
- data/Rakefile +1 -8
- data/compat/compat_test.rb +1 -1
- data/compat/haml_test.rb +1 -0
- data/compat/helper.rb +2 -1
- data/compat/sym_params_test.rb +0 -1
- data/lib/sinatra.rb +1 -1
- data/lib/sinatra/base.rb +92 -39
- data/lib/sinatra/compat.rb +4 -12
- data/lib/sinatra/main.rb +2 -1
- data/lib/sinatra/showexceptions.rb +13 -9
- data/lib/sinatra/test.rb +2 -1
- data/lib/sinatra/test/bacon.rb +1 -1
- data/lib/sinatra/test/rspec.rb +1 -1
- data/lib/sinatra/test/unit.rb +1 -1
- data/sinatra.gemspec +3 -3
- data/test/extensions_test.rb +8 -8
- data/test/helpers_test.rb +21 -8
- data/test/middleware_test.rb +1 -1
- data/test/options_test.rb +74 -59
- data/test/public/favicon.ico +0 -0
- data/test/render_backtrace_test.rb +1 -1
- data/test/templates_test.rb +4 -4
- data/test/test_test.rb +6 -3
- metadata +39 -18
- data/test/data/reload_app_file.rb +0 -3
data/AUTHORS
CHANGED
@@ -10,6 +10,8 @@ Sinatra would not be possible:
|
|
10
10
|
* Ryan Tomayko (rtomayko) for constantly fixing whitespace errors 60d5006
|
11
11
|
* Ezra Zygmuntowicz (ezmobius) for initial help and letting Blake steal
|
12
12
|
some of merbs internal code.
|
13
|
+
* Ari Lerner (http://xnot.org/) for his evangelism, spirit, and gumption
|
14
|
+
that got Sinatra recognized from Day 1.
|
13
15
|
* Christopher Schneid (cschneid) for The Book, the blog (gittr.com),
|
14
16
|
irclogger.com, and a bunch of useful patches.
|
15
17
|
* Markus Prinz (cypher) for patches over the years, caring about
|
data/CHANGES
CHANGED
@@ -1,3 +1,28 @@
|
|
1
|
+
= 0.9.5 / unreleased
|
2
|
+
|
3
|
+
* Fix use_in_file_templates! with jRuby on Windows.
|
4
|
+
|
5
|
+
* Fix sinatra/test to work with Rack > 1.0.1
|
6
|
+
|
7
|
+
* UI improvements to the show exception page.
|
8
|
+
|
9
|
+
* Slightly improved doc coverage.
|
10
|
+
|
11
|
+
* New 'settings' method gives access to options in both class and request
|
12
|
+
scopes. This replaces the 'options' method. (Chris Wanstrath)
|
13
|
+
|
14
|
+
* `Sinatra::Default` is obsolete; use `Sinatra::Base` instead.
|
15
|
+
`Sinatra::Base` acts more like `Sinatra::Default` in development mode.
|
16
|
+
For example, static file serving and sexy development error pages are
|
17
|
+
enabled by default.
|
18
|
+
|
19
|
+
* The `:methodoverride' option to enable/disable the POST _method hack is
|
20
|
+
obsolete; use `:method_override` instead.
|
21
|
+
|
22
|
+
* The 'media_type' helper method is deprecated. Use 'mime_type' instead.
|
23
|
+
|
24
|
+
* The 'mime' main and class method is deprecated. Use 'mime_type' instead.
|
25
|
+
|
1
26
|
= 0.9.4 / 2009-07-26
|
2
27
|
|
3
28
|
* The app_file and run options should be properly detected
|
data/README.rdoc
CHANGED
@@ -187,10 +187,9 @@ and overridden on an individual basis.
|
|
187
187
|
|
188
188
|
get '/stylesheet.css' do
|
189
189
|
content_type 'text/css', :charset => 'utf-8'
|
190
|
-
sass :stylesheet, :
|
190
|
+
sass :stylesheet, :style => :expanded # overridden
|
191
191
|
end
|
192
192
|
|
193
|
-
|
194
193
|
=== Inline Templates
|
195
194
|
|
196
195
|
get '/' do
|
@@ -219,7 +218,7 @@ Or, specify an explicit Hash of local variables:
|
|
219
218
|
This is typically used when rendering templates as partials from within
|
220
219
|
other templates.
|
221
220
|
|
222
|
-
===
|
221
|
+
=== Inline Templates
|
223
222
|
|
224
223
|
Templates may be defined at the end of the source file:
|
225
224
|
|
@@ -239,9 +238,9 @@ Templates may be defined at the end of the source file:
|
|
239
238
|
@@ index
|
240
239
|
%div.title Hello world!!!!!
|
241
240
|
|
242
|
-
NOTE:
|
243
|
-
are automatically loaded. Call
|
244
|
-
|
241
|
+
NOTE: Inline templates defined in the source file that requires sinatra
|
242
|
+
are automatically loaded. Call `enable :inline_templates` explicitly if you
|
243
|
+
have inline templates in other source files.
|
245
244
|
|
246
245
|
=== Named Templates
|
247
246
|
|
@@ -303,25 +302,33 @@ To immediately stop a request during a before filter or route use:
|
|
303
302
|
|
304
303
|
halt
|
305
304
|
|
306
|
-
You can also specify
|
305
|
+
You can also specify the status when halting ...
|
306
|
+
|
307
|
+
halt 410
|
308
|
+
|
309
|
+
Or the body ...
|
307
310
|
|
308
311
|
halt 'this will be the body'
|
309
312
|
|
310
|
-
Or
|
313
|
+
Or both ...
|
311
314
|
|
312
315
|
halt 401, 'go away!'
|
313
316
|
|
317
|
+
With headers ...
|
318
|
+
|
319
|
+
halt 402, {'Content-Type' => 'text/plain'}, 'revenge'
|
320
|
+
|
314
321
|
== Passing
|
315
322
|
|
316
323
|
A route can punt processing to the next matching route using <tt>pass</tt>:
|
317
324
|
|
318
325
|
get '/guess/:who' do
|
319
326
|
pass unless params[:who] == 'Frank'
|
320
|
-
|
327
|
+
'You got me!'
|
321
328
|
end
|
322
329
|
|
323
330
|
get '/guess/*' do
|
324
|
-
|
331
|
+
'You missed!'
|
325
332
|
end
|
326
333
|
|
327
334
|
The route block is immediately exited and control continues with the next
|
@@ -390,15 +397,35 @@ You get this:
|
|
390
397
|
|
391
398
|
So what happened was... something bad
|
392
399
|
|
400
|
+
Alternatively, you can install error handler for a status code:
|
401
|
+
|
402
|
+
error 403 do
|
403
|
+
'Access forbidden'
|
404
|
+
end
|
405
|
+
|
406
|
+
get '/secret' do
|
407
|
+
403
|
408
|
+
end
|
409
|
+
|
410
|
+
Or a range:
|
411
|
+
|
412
|
+
error 400..510 do
|
413
|
+
'Boom'
|
414
|
+
end
|
415
|
+
|
393
416
|
Sinatra installs special <tt>not_found</tt> and <tt>error</tt> handlers when
|
394
417
|
running under the development environment.
|
395
418
|
|
396
419
|
== Mime types
|
397
420
|
|
398
421
|
When using <tt>send_file</tt> or static files you may have mime types Sinatra
|
399
|
-
doesn't understand. Use +
|
422
|
+
doesn't understand. Use +mime_type+ to register them by file extension:
|
423
|
+
|
424
|
+
mime_type :foo, 'text/foo'
|
425
|
+
|
426
|
+
You can also use it with the +content_type+ helper:
|
400
427
|
|
401
|
-
|
428
|
+
content_type :foo
|
402
429
|
|
403
430
|
== Rack Middleware
|
404
431
|
|
data/Rakefile
CHANGED
@@ -35,14 +35,7 @@ end
|
|
35
35
|
|
36
36
|
# Load the gemspec using the same limitations as github
|
37
37
|
def spec
|
38
|
-
@spec ||=
|
39
|
-
begin
|
40
|
-
require 'rubygems/specification'
|
41
|
-
data = File.read('sinatra.gemspec')
|
42
|
-
spec = nil
|
43
|
-
Thread.new { spec = eval("$SAFE = 3\n#{data}") }.join
|
44
|
-
spec
|
45
|
-
end
|
38
|
+
@spec ||= eval(File.read('sinatra.gemspec'))
|
46
39
|
end
|
47
40
|
|
48
41
|
def package(ext='')
|
data/compat/compat_test.rb
CHANGED
data/compat/haml_test.rb
CHANGED
data/compat/helper.rb
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
require 'rubygems'
|
2
1
|
require 'mocha'
|
3
2
|
|
4
3
|
# disable warnings in compat specs.
|
@@ -23,11 +22,13 @@ module Sinatra::Test
|
|
23
22
|
end
|
24
23
|
|
25
24
|
class Test::Unit::TestCase
|
25
|
+
include Mocha::API
|
26
26
|
include Sinatra::Test
|
27
27
|
|
28
28
|
PASSTHROUGH_EXCEPTIONS = [] unless const_defined?(:PASSTHROUGH_EXCEPTIONS)
|
29
29
|
|
30
30
|
def setup
|
31
31
|
@app = lambda { |env| Sinatra::Application.call(env) }
|
32
|
+
mocha_teardown
|
32
33
|
end
|
33
34
|
end
|
data/compat/sym_params_test.rb
CHANGED
data/lib/sinatra.rb
CHANGED
data/lib/sinatra/base.rb
CHANGED
@@ -5,8 +5,16 @@ require 'rack'
|
|
5
5
|
require 'rack/builder'
|
6
6
|
require 'sinatra/showexceptions'
|
7
7
|
|
8
|
+
# Like Kernel#warn but outputs the location that triggered the warning.
|
9
|
+
def sinatra_warn(*message) #:nodoc:
|
10
|
+
line = caller.
|
11
|
+
detect { |line| line !~ /(?:lib\/sinatra\/|__DELEGATE__)/ }.
|
12
|
+
sub(/:in .*/, '')
|
13
|
+
warn "#{line}: warning: #{message.join(' ')}"
|
14
|
+
end
|
15
|
+
|
8
16
|
module Sinatra
|
9
|
-
VERSION = '0.9.
|
17
|
+
VERSION = '0.9.5'
|
10
18
|
|
11
19
|
# The request object. See Rack::Request for more info:
|
12
20
|
# http://rack.rubyforge.org/doc/classes/Rack/Request.html
|
@@ -104,20 +112,25 @@ module Sinatra
|
|
104
112
|
end
|
105
113
|
|
106
114
|
# Look up a media type by file extension in Rack's mime registry.
|
115
|
+
def mime_type(type)
|
116
|
+
Base.mime_type(type)
|
117
|
+
end
|
118
|
+
|
107
119
|
def media_type(type)
|
108
|
-
|
120
|
+
sinatra_warn "media_type is deprecated; use mime_type instead"
|
121
|
+
mime_type(type)
|
109
122
|
end
|
110
123
|
|
111
124
|
# Set the Content-Type of the response body given a media type or file
|
112
125
|
# extension.
|
113
126
|
def content_type(type, params={})
|
114
|
-
|
115
|
-
fail "Unknown media type: %p" % type if
|
127
|
+
mime_type = self.mime_type(type)
|
128
|
+
fail "Unknown media type: %p" % type if mime_type.nil?
|
116
129
|
if params.any?
|
117
130
|
params = params.collect { |kv| "%s=%s" % kv }.join(', ')
|
118
|
-
response['Content-Type'] = [
|
131
|
+
response['Content-Type'] = [mime_type, params].join(";")
|
119
132
|
else
|
120
|
-
response['Content-Type'] =
|
133
|
+
response['Content-Type'] = mime_type
|
121
134
|
end
|
122
135
|
end
|
123
136
|
|
@@ -136,8 +149,8 @@ module Sinatra
|
|
136
149
|
stat = File.stat(path)
|
137
150
|
last_modified stat.mtime
|
138
151
|
|
139
|
-
content_type
|
140
|
-
|
152
|
+
content_type mime_type(opts[:type]) ||
|
153
|
+
mime_type(File.extname(path)) ||
|
141
154
|
response['Content-Type'] ||
|
142
155
|
'application/octet-stream'
|
143
156
|
|
@@ -183,7 +196,7 @@ module Sinatra
|
|
183
196
|
|
184
197
|
# Set the response entity tag (HTTP 'ETag' header) and halt if conditional
|
185
198
|
# GET matches. The +value+ argument is an identifier that uniquely
|
186
|
-
# identifies the current version of the resource. The +
|
199
|
+
# identifies the current version of the resource. The +kind+ argument
|
187
200
|
# indicates whether the etag should be used as a :strong (default) or :weak
|
188
201
|
# cache validator.
|
189
202
|
#
|
@@ -341,7 +354,7 @@ module Sinatra
|
|
341
354
|
end
|
342
355
|
|
343
356
|
def require_warn(engine)
|
344
|
-
|
357
|
+
sinatra_warn "auto-require of #{engine} is deprecated; add require '#{engine}' to your app."
|
345
358
|
require engine.downcase
|
346
359
|
end
|
347
360
|
end
|
@@ -388,10 +401,11 @@ module Sinatra
|
|
388
401
|
[status, header, body]
|
389
402
|
end
|
390
403
|
|
391
|
-
# Access
|
392
|
-
def
|
404
|
+
# Access settings defined with Base.set.
|
405
|
+
def settings
|
393
406
|
self.class
|
394
407
|
end
|
408
|
+
alias_method :options, :settings
|
395
409
|
|
396
410
|
# Exit the current block, halts any further processing
|
397
411
|
# of the request, and returns the specified response.
|
@@ -671,15 +685,25 @@ module Sinatra
|
|
671
685
|
template name, &block
|
672
686
|
end
|
673
687
|
|
688
|
+
def use_in_file_templates!(file=nil)
|
689
|
+
sinatra_warn "use_in_file_templates! is deprecated; " \
|
690
|
+
"use enable :inline_templates instead"
|
691
|
+
set :inline_templates, file
|
692
|
+
end
|
693
|
+
|
674
694
|
# Load embeded templates from the file; uses the caller's __FILE__
|
675
695
|
# when no file is specified.
|
676
|
-
def
|
677
|
-
file
|
678
|
-
|
679
|
-
|
696
|
+
def inline_templates=(file=nil)
|
697
|
+
file = (file.nil? || file == true) ? caller_files.first : file
|
698
|
+
|
699
|
+
begin
|
700
|
+
app, data =
|
701
|
+
::IO.read(file).gsub("\r\n", "\n").split(/^__END__$/, 2)
|
702
|
+
rescue Errno::ENOENT
|
703
|
+
app, data = nil
|
704
|
+
end
|
680
705
|
|
681
706
|
if data
|
682
|
-
data.gsub!(/\r\n/, "\n")
|
683
707
|
lines = app.count("\n") + 1
|
684
708
|
template = nil
|
685
709
|
data.each_line do |line|
|
@@ -694,11 +718,17 @@ module Sinatra
|
|
694
718
|
end
|
695
719
|
end
|
696
720
|
|
697
|
-
#
|
698
|
-
def
|
721
|
+
# Lookup or register a mime type in Rack's mime registry.
|
722
|
+
def mime_type(type, value=nil)
|
699
723
|
return type if type.nil? || type.to_s.include?('/')
|
700
724
|
type = ".#{type}" unless type.to_s[0] == ?.
|
701
|
-
Rack::Mime.mime_type(type, nil)
|
725
|
+
return Rack::Mime.mime_type(type, nil) unless value
|
726
|
+
Rack::Mime::MIME_TYPES[type] = value
|
727
|
+
end
|
728
|
+
|
729
|
+
def media_type(type, value=nil)
|
730
|
+
sinatra_warn "media_type is deprecated; use mime_type instead"
|
731
|
+
mime_type(type, value)
|
702
732
|
end
|
703
733
|
|
704
734
|
# Define a before filter. Filters are run before all requests
|
@@ -733,7 +763,7 @@ module Sinatra
|
|
733
763
|
|
734
764
|
def provides(*types)
|
735
765
|
types = [types] unless types.kind_of? Array
|
736
|
-
types.map!{|t|
|
766
|
+
types.map!{|t| mime_type(t)}
|
737
767
|
|
738
768
|
condition {
|
739
769
|
matching_types = (request.accept & types)
|
@@ -886,7 +916,7 @@ module Sinatra
|
|
886
916
|
builder = Rack::Builder.new
|
887
917
|
builder.use Rack::Session::Cookie if sessions? && !test?
|
888
918
|
builder.use Rack::CommonLogger if logging?
|
889
|
-
builder.use Rack::MethodOverride if
|
919
|
+
builder.use Rack::MethodOverride if method_override?
|
890
920
|
builder.use ShowExceptions if show_exceptions?
|
891
921
|
|
892
922
|
@middleware.each { |c,a,b| builder.use(c, *a, &b) }
|
@@ -974,15 +1004,14 @@ module Sinatra
|
|
974
1004
|
end
|
975
1005
|
end
|
976
1006
|
|
977
|
-
set :
|
978
|
-
set :
|
1007
|
+
set :environment, (ENV['RACK_ENV'] || :development).to_sym
|
1008
|
+
set :raise_errors, Proc.new { !development? }
|
1009
|
+
set :dump_errors, Proc.new { development? }
|
1010
|
+
set :show_exceptions, Proc.new { development? }
|
979
1011
|
set :clean_trace, true
|
980
|
-
set :show_exceptions, false
|
981
1012
|
set :sessions, false
|
982
1013
|
set :logging, false
|
983
|
-
set :
|
984
|
-
set :static, false
|
985
|
-
set :environment, (ENV['RACK_ENV'] || :development).to_sym
|
1014
|
+
set :method_override, false
|
986
1015
|
|
987
1016
|
set :run, false
|
988
1017
|
set :server, %w[thin mongrel webrick]
|
@@ -993,8 +1022,14 @@ module Sinatra
|
|
993
1022
|
set :root, Proc.new { app_file && File.expand_path(File.dirname(app_file)) }
|
994
1023
|
set :views, Proc.new { root && File.join(root, 'views') }
|
995
1024
|
set :public, Proc.new { root && File.join(root, 'public') }
|
1025
|
+
set :static, Proc.new { self.public && File.exist?(self.public) }
|
996
1026
|
set :lock, false
|
997
1027
|
|
1028
|
+
class << self
|
1029
|
+
alias_method :methodoverride?, :method_override?
|
1030
|
+
alias_method :methodoverride=, :method_override=
|
1031
|
+
end
|
1032
|
+
|
998
1033
|
# static files route
|
999
1034
|
get(/.*[^\/]$/) do
|
1000
1035
|
pass unless options.static? && options.public?
|
@@ -1045,16 +1080,39 @@ module Sinatra
|
|
1045
1080
|
end
|
1046
1081
|
end
|
1047
1082
|
|
1048
|
-
#
|
1083
|
+
# Deprecated as base class for non-top-level apps. Subclass
|
1084
|
+
# Sinatra::Base instead and set options as needed.
|
1049
1085
|
class Default < Base
|
1050
1086
|
set :raise_errors, Proc.new { test? }
|
1051
|
-
set :show_exceptions, Proc.new { development? }
|
1052
1087
|
set :dump_errors, true
|
1053
1088
|
set :sessions, false
|
1054
1089
|
set :logging, Proc.new { ! test? }
|
1055
|
-
set :
|
1090
|
+
set :method_override, true
|
1091
|
+
set :run, Proc.new { ! test? }
|
1056
1092
|
set :static, true
|
1093
|
+
|
1094
|
+
def self.inherited(subclass)
|
1095
|
+
sinatra_warn 'Sinatra::Default is deprecated; ' \
|
1096
|
+
'subclass Sinatra::Base instead'
|
1097
|
+
super
|
1098
|
+
end
|
1099
|
+
end
|
1100
|
+
|
1101
|
+
# Execution context for classic style (top-level) applications. All
|
1102
|
+
# DSL methods executed on main are delegated to this class.
|
1103
|
+
#
|
1104
|
+
# The Application class should not be subclassed, unless you want to
|
1105
|
+
# inherit all settings, routes, handlers, and error pages from the
|
1106
|
+
# top-level. Subclassing Sinatra::Base is heavily recommended for
|
1107
|
+
# modular applications.
|
1108
|
+
class Application < Base
|
1109
|
+
set :raise_errors, Proc.new { test? }
|
1110
|
+
set :dump_errors, true
|
1111
|
+
set :sessions, false
|
1112
|
+
set :logging, Proc.new { ! test? }
|
1113
|
+
set :method_override, true
|
1057
1114
|
set :run, Proc.new { ! test? }
|
1115
|
+
set :static, true
|
1058
1116
|
|
1059
1117
|
def self.register(*extensions, &block) #:nodoc:
|
1060
1118
|
added_methods = extensions.map {|m| m.public_instance_methods }.flatten
|
@@ -1063,11 +1121,6 @@ module Sinatra
|
|
1063
1121
|
end
|
1064
1122
|
end
|
1065
1123
|
|
1066
|
-
# The top-level Application. All DSL methods executed on main are delegated
|
1067
|
-
# to this class.
|
1068
|
-
class Application < Default
|
1069
|
-
end
|
1070
|
-
|
1071
1124
|
# Sinatra delegation mixin. Mixing this module into an object causes all
|
1072
1125
|
# methods to be delegated to the Sinatra::Application class. Used primarily
|
1073
1126
|
# at the top-level.
|
@@ -1086,7 +1139,7 @@ module Sinatra
|
|
1086
1139
|
delegate :get, :put, :post, :delete, :head, :template, :layout, :before,
|
1087
1140
|
:error, :not_found, :configures, :configure, :set, :set_option,
|
1088
1141
|
:set_options, :enable, :disable, :use, :development?, :test?,
|
1089
|
-
:production?, :use_in_file_templates!, :helpers
|
1142
|
+
:production?, :use_in_file_templates!, :helpers, :mime_type
|
1090
1143
|
end
|
1091
1144
|
|
1092
1145
|
# Create a new Sinatra application. The block is evaluated in the new app's
|
@@ -1099,12 +1152,12 @@ module Sinatra
|
|
1099
1152
|
|
1100
1153
|
# Extend the top-level DSL with the modules provided.
|
1101
1154
|
def self.register(*extensions, &block)
|
1102
|
-
|
1155
|
+
Application.register(*extensions, &block)
|
1103
1156
|
end
|
1104
1157
|
|
1105
1158
|
# Include the helper modules provided in Sinatra's request context.
|
1106
1159
|
def self.helpers(*extensions, &block)
|
1107
|
-
|
1160
|
+
Application.helpers(*extensions, &block)
|
1108
1161
|
end
|
1109
1162
|
end
|
1110
1163
|
|
data/lib/sinatra/compat.rb
CHANGED
@@ -8,14 +8,6 @@ require 'ostruct'
|
|
8
8
|
require 'sinatra/base'
|
9
9
|
require 'sinatra/main'
|
10
10
|
|
11
|
-
# Like Kernel#warn but outputs the location that triggered the warning.
|
12
|
-
def sinatra_warn(*message) #:nodoc:
|
13
|
-
line = caller.
|
14
|
-
detect { |line| line !~ /(?:lib\/sinatra\/|__DELEGATE__)/ }.
|
15
|
-
sub(/:in .*/, '')
|
16
|
-
warn "#{line}: warning: #{message.join(' ')}"
|
17
|
-
end
|
18
|
-
|
19
11
|
# Rack now supports evented and swiftiplied mongrels through separate
|
20
12
|
# handler.
|
21
13
|
if ENV['SWIFT']
|
@@ -53,12 +45,12 @@ module Sinatra
|
|
53
45
|
module Compat #:nodoc:
|
54
46
|
end
|
55
47
|
|
56
|
-
# Make Sinatra::EventContext an alias for Sinatra::
|
48
|
+
# Make Sinatra::EventContext an alias for Sinatra::Application to unbreak plugins.
|
57
49
|
def self.const_missing(const_name) #:nodoc:
|
58
50
|
if const_name == :EventContext
|
59
|
-
const_set :EventContext, Sinatra::
|
60
|
-
sinatra_warn 'Sinatra::EventContext is deprecated; use Sinatra::
|
61
|
-
Sinatra::
|
51
|
+
const_set :EventContext, Sinatra::Application
|
52
|
+
sinatra_warn 'Sinatra::EventContext is deprecated; use Sinatra::Application instead.'
|
53
|
+
Sinatra::Application
|
62
54
|
else
|
63
55
|
super
|
64
56
|
end
|
data/lib/sinatra/main.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'sinatra/base'
|
2
2
|
|
3
3
|
module Sinatra
|
4
|
-
class
|
4
|
+
class Application < Base
|
5
5
|
|
6
6
|
# we assume that the first file that requires 'sinatra' is the
|
7
7
|
# app_file. all other path related options are calculated based
|
@@ -25,6 +25,7 @@ end
|
|
25
25
|
include Sinatra::Delegator
|
26
26
|
|
27
27
|
def mime(ext, type)
|
28
|
+
warn 'mime is deprecated; use mime_type instead.'
|
28
29
|
ext = ".#{ext}" unless ext.to_s[0] == ?.
|
29
30
|
Rack::Mime::MIME_TYPES[ext.to_s] = type
|
30
31
|
end
|
@@ -73,14 +73,14 @@ TEMPLATE = <<HTML
|
|
73
73
|
#explanation {font-size: 12px; color: #666666;
|
74
74
|
margin: 20px 0 0 100px;}
|
75
75
|
/* WRAP */
|
76
|
-
#wrap {width:
|
76
|
+
#wrap {width: 1000px; background: #FFFFFF; margin: 0 auto;
|
77
77
|
padding: 30px 50px 20px 50px;
|
78
78
|
border-left: 1px solid #DDDDDD;
|
79
79
|
border-right: 1px solid #DDDDDD;}
|
80
80
|
/* HEADER */
|
81
81
|
#header {margin: 0 auto 25px auto;}
|
82
82
|
#header img {float: left;}
|
83
|
-
#header #summary {float: left; margin: 12px 0 0 20px; width:
|
83
|
+
#header #summary {float: left; margin: 12px 0 0 20px; width:660px;
|
84
84
|
font-family: 'Lucida Grande', 'Lucida Sans Unicode';}
|
85
85
|
h1 {margin: 0; font-size: 36px; color: #981919;}
|
86
86
|
h2 {margin: 0; font-size: 22px; color: #333333;}
|
@@ -94,7 +94,7 @@ TEMPLATE = <<HTML
|
|
94
94
|
#get,
|
95
95
|
#post,
|
96
96
|
#cookies,
|
97
|
-
#rack {width:
|
97
|
+
#rack {width: 980px; margin: 0 auto 10px auto;}
|
98
98
|
p#nav {float: right; font-size: 14px;}
|
99
99
|
/* BACKTRACE */
|
100
100
|
a#expando {float: left; padding-left: 5px; color: #666666;
|
@@ -107,7 +107,7 @@ TEMPLATE = <<HTML
|
|
107
107
|
font-size: 12px; color: #333333;}
|
108
108
|
#backtrace ul {list-style-position: outside; border: 1px solid #E9E9E9;
|
109
109
|
border-bottom: 0;}
|
110
|
-
#backtrace ol {width:
|
110
|
+
#backtrace ol {width: 920px; margin-left: 50px;
|
111
111
|
font: 10px 'Lucida Console', monospace; color: #666666;}
|
112
112
|
#backtrace ol li {border: 0; border-left: 1px solid #E9E9E9;
|
113
113
|
padding: 2px 0;}
|
@@ -119,10 +119,11 @@ TEMPLATE = <<HTML
|
|
119
119
|
#backtrace.condensed .framework {display:none;}
|
120
120
|
/* REQUEST DATA */
|
121
121
|
p.no-data {padding-top: 2px; font-size: 12px; color: #666666;}
|
122
|
-
table.req {width:
|
122
|
+
table.req {width: 980px; text-align: left; font-size: 12px;
|
123
123
|
color: #666666; padding: 0; border-spacing: 0;
|
124
124
|
border: 1px solid #EEEEEE; border-bottom: 0;
|
125
|
-
border-left: 0;
|
125
|
+
border-left: 0;
|
126
|
+
clear:both}
|
126
127
|
table.req tr th {padding: 2px 10px; font-weight: bold;
|
127
128
|
background: #F7F7F7; border-bottom: 1px solid #EEEEEE;
|
128
129
|
border-left: 1px solid #EEEEEE;}
|
@@ -132,12 +133,15 @@ TEMPLATE = <<HTML
|
|
132
133
|
/* HIDE PRE/POST CODE AT START */
|
133
134
|
.pre-context,
|
134
135
|
.post-context {display: none;}
|
136
|
+
|
137
|
+
table td.code {width:750px}
|
138
|
+
table td.code div {width:750px;overflow:hidden}
|
135
139
|
</style>
|
136
140
|
</head>
|
137
141
|
<body>
|
138
142
|
<div id="wrap">
|
139
143
|
<div id="header">
|
140
|
-
<img src="/__sinatra__/500.png" alt="application error" />
|
144
|
+
<img src="/__sinatra__/500.png" alt="application error" height="161" width="313" />
|
141
145
|
<div id="summary">
|
142
146
|
<h1><strong><%=h exception.class %></strong> at <strong><%=h path %>
|
143
147
|
</strong></h1>
|
@@ -293,8 +297,8 @@ TEMPLATE = <<HTML
|
|
293
297
|
<div class="clear"></div>
|
294
298
|
</div> <!-- /RACK ENV -->
|
295
299
|
|
296
|
-
<p id="explanation">You're seeing this error because you
|
297
|
-
enabled the <code>show_exceptions</code>
|
300
|
+
<p id="explanation">You're seeing this error because you have
|
301
|
+
enabled the <code>show_exceptions</code> setting.</p>
|
298
302
|
</div> <!-- /WRAP -->
|
299
303
|
</body>
|
300
304
|
</html>
|
data/lib/sinatra/test.rb
CHANGED
@@ -7,7 +7,7 @@ module Sinatra
|
|
7
7
|
include Rack::Utils
|
8
8
|
|
9
9
|
def self.included(base)
|
10
|
-
Sinatra::
|
10
|
+
Sinatra::Application.set(:environment, :test)
|
11
11
|
end
|
12
12
|
|
13
13
|
attr_reader :app, :request, :response
|
@@ -30,6 +30,7 @@ for more information.
|
|
30
30
|
case
|
31
31
|
when body.respond_to?(:to_hash)
|
32
32
|
options.merge! body.delete(:env) if body.key?(:env)
|
33
|
+
options[:content_type] ||= 'application/x-www-form-urlencoded'
|
33
34
|
options[:input] = param_string(body)
|
34
35
|
when body.respond_to?(:to_str)
|
35
36
|
options[:input] = body
|
data/lib/sinatra/test/bacon.rb
CHANGED
data/lib/sinatra/test/rspec.rb
CHANGED
data/lib/sinatra/test/unit.rb
CHANGED
data/sinatra.gemspec
CHANGED
@@ -3,8 +3,8 @@ 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.9.
|
7
|
-
s.date = '
|
6
|
+
s.version = '0.9.5'
|
7
|
+
s.date = '2010-03-04'
|
8
8
|
|
9
9
|
s.description = "Classy web-development dressed in a DSL"
|
10
10
|
s.summary = "Classy web-development dressed in a DSL"
|
@@ -70,7 +70,6 @@ Gem::Specification.new do |s|
|
|
70
70
|
test/base_test.rb
|
71
71
|
test/builder_test.rb
|
72
72
|
test/contest.rb
|
73
|
-
test/data/reload_app_file.rb
|
74
73
|
test/erb_test.rb
|
75
74
|
test/extensions_test.rb
|
76
75
|
test/filter_test.rb
|
@@ -80,6 +79,7 @@ Gem::Specification.new do |s|
|
|
80
79
|
test/mapped_error_test.rb
|
81
80
|
test/middleware_test.rb
|
82
81
|
test/options_test.rb
|
82
|
+
test/public/favicon.ico
|
83
83
|
test/render_backtrace_test.rb
|
84
84
|
test/request_test.rb
|
85
85
|
test/response_test.rb
|
data/test/extensions_test.rb
CHANGED
@@ -35,9 +35,9 @@ class ExtensionsTest < Test::Unit::TestCase
|
|
35
35
|
Sinatra::Base.register FooExtensions
|
36
36
|
assert Sinatra::Base.respond_to?(:foo)
|
37
37
|
|
38
|
-
Sinatra::
|
39
|
-
assert Sinatra::
|
40
|
-
assert Sinatra::
|
38
|
+
Sinatra::Application.register BarExtensions
|
39
|
+
assert Sinatra::Application.respond_to?(:bar)
|
40
|
+
assert Sinatra::Application.respond_to?(:foo)
|
41
41
|
assert !Sinatra::Base.respond_to?(:bar)
|
42
42
|
end
|
43
43
|
|
@@ -48,8 +48,8 @@ class ExtensionsTest < Test::Unit::TestCase
|
|
48
48
|
assert Sinatra::Base.respond_to?(:im_in_ur_anonymous_module)
|
49
49
|
end
|
50
50
|
|
51
|
-
it 'will make sure any public methods added via
|
52
|
-
Sinatra::
|
51
|
+
it 'will make sure any public methods added via Application#register are delegated to Sinatra::Delegator' do
|
52
|
+
Sinatra::Application.register FooExtensions
|
53
53
|
assert Sinatra::Delegator.private_instance_methods.
|
54
54
|
map { |m| m.to_sym }.include?(:foo)
|
55
55
|
assert !Sinatra::Delegator.private_instance_methods.
|
@@ -57,7 +57,7 @@ class ExtensionsTest < Test::Unit::TestCase
|
|
57
57
|
end
|
58
58
|
|
59
59
|
it 'will handle special method names' do
|
60
|
-
Sinatra::
|
60
|
+
Sinatra::Application.register PainExtensions
|
61
61
|
assert Sinatra::Delegator.private_instance_methods.
|
62
62
|
map { |m| m.to_sym }.include?(:foo=)
|
63
63
|
assert Sinatra::Delegator.private_instance_methods.
|
@@ -71,10 +71,10 @@ 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::
|
74
|
+
it 'will extend the Sinatra::Application by default' do
|
75
75
|
Sinatra.register BazExtensions
|
76
76
|
assert !Sinatra::Base.respond_to?(:baz)
|
77
|
-
assert Sinatra::
|
77
|
+
assert Sinatra::Application.respond_to?(:baz)
|
78
78
|
end
|
79
79
|
|
80
80
|
module BizzleExtension
|
data/test/helpers_test.rb
CHANGED
@@ -200,29 +200,42 @@ class HelpersTest < Test::Unit::TestCase
|
|
200
200
|
end
|
201
201
|
end
|
202
202
|
|
203
|
-
describe '
|
203
|
+
describe 'mime_type' do
|
204
204
|
include Sinatra::Helpers
|
205
205
|
|
206
|
-
it "looks up
|
206
|
+
it "looks up mime types in Rack's MIME registry" do
|
207
207
|
Rack::Mime::MIME_TYPES['.foo'] = 'application/foo'
|
208
|
-
assert_equal 'application/foo',
|
209
|
-
assert_equal 'application/foo',
|
210
|
-
assert_equal 'application/foo',
|
208
|
+
assert_equal 'application/foo', mime_type('foo')
|
209
|
+
assert_equal 'application/foo', mime_type('.foo')
|
210
|
+
assert_equal 'application/foo', mime_type(:foo)
|
211
211
|
end
|
212
212
|
|
213
213
|
it 'returns nil when given nil' do
|
214
|
-
assert
|
214
|
+
assert mime_type(nil).nil?
|
215
215
|
end
|
216
216
|
|
217
217
|
it 'returns nil when media type not registered' do
|
218
|
-
assert
|
218
|
+
assert mime_type(:bizzle).nil?
|
219
219
|
end
|
220
220
|
|
221
221
|
it 'returns the argument when given a media type string' do
|
222
|
-
assert_equal 'text/plain',
|
222
|
+
assert_equal 'text/plain', mime_type('text/plain')
|
223
223
|
end
|
224
224
|
end
|
225
225
|
|
226
|
+
test 'Base.mime_type registers mime type' do
|
227
|
+
mock_app {
|
228
|
+
mime_type :foo, 'application/foo'
|
229
|
+
|
230
|
+
get '/' do
|
231
|
+
"foo is #{mime_type(:foo)}"
|
232
|
+
end
|
233
|
+
}
|
234
|
+
|
235
|
+
get '/'
|
236
|
+
assert_equal 'foo is application/foo', body
|
237
|
+
end
|
238
|
+
|
226
239
|
describe 'content_type' do
|
227
240
|
it 'sets the Content-Type header' do
|
228
241
|
mock_app {
|
data/test/middleware_test.rb
CHANGED
@@ -2,7 +2,7 @@ require File.dirname(__FILE__) + '/helper'
|
|
2
2
|
|
3
3
|
class MiddlewareTest < Test::Unit::TestCase
|
4
4
|
setup do
|
5
|
-
@app = mock_app(Sinatra::
|
5
|
+
@app = mock_app(Sinatra::Base) {
|
6
6
|
get '/*' do
|
7
7
|
response.headers['X-Tests'] = env['test.ran'].
|
8
8
|
map { |n| n.split('::').last }.
|
data/test/options_test.rb
CHANGED
@@ -3,9 +3,9 @@ require File.dirname(__FILE__) + '/helper'
|
|
3
3
|
class OptionsTest < Test::Unit::TestCase
|
4
4
|
setup do
|
5
5
|
@base = Sinatra.new(Sinatra::Base)
|
6
|
-
@
|
6
|
+
@application = Sinatra.new(Sinatra::Application)
|
7
7
|
@base.set :environment, :development
|
8
|
-
@
|
8
|
+
@application.set :environment, :development
|
9
9
|
end
|
10
10
|
|
11
11
|
it 'sets options to literal values' do
|
@@ -110,8 +110,8 @@ class OptionsTest < Test::Unit::TestCase
|
|
110
110
|
assert @base.clean_trace?
|
111
111
|
end
|
112
112
|
|
113
|
-
it 'is enabled on
|
114
|
-
assert @
|
113
|
+
it 'is enabled on Application' do
|
114
|
+
assert @application.clean_trace?
|
115
115
|
end
|
116
116
|
|
117
117
|
it 'does nothing when disabled' do
|
@@ -152,58 +152,61 @@ class OptionsTest < Test::Unit::TestCase
|
|
152
152
|
assert ! @base.run?
|
153
153
|
end
|
154
154
|
|
155
|
-
it 'is enabled on
|
156
|
-
@
|
157
|
-
assert @
|
158
|
-
assert @
|
155
|
+
it 'is enabled on Application when not in test environment' do
|
156
|
+
@application.set :environment, :development
|
157
|
+
assert @application.development?
|
158
|
+
assert @application.run?
|
159
159
|
|
160
|
-
@
|
161
|
-
assert @
|
160
|
+
@application.set :environment, :development
|
161
|
+
assert @application.run?
|
162
162
|
end
|
163
163
|
|
164
164
|
# TODO: it 'is enabled when $0 == app_file'
|
165
165
|
end
|
166
166
|
|
167
167
|
describe 'raise_errors' do
|
168
|
-
it 'is enabled on Base' do
|
168
|
+
it 'is enabled on Base except under development' do
|
169
|
+
@base.environment = :test
|
169
170
|
assert @base.raise_errors?
|
171
|
+
@base.environment = :development
|
172
|
+
assert !@base.raise_errors?
|
170
173
|
end
|
171
174
|
|
172
|
-
it 'is enabled on
|
173
|
-
@
|
174
|
-
assert @
|
175
|
-
assert ! @
|
175
|
+
it 'is enabled on Application only in test' do
|
176
|
+
@application.set(:environment, :development)
|
177
|
+
assert @application.development?
|
178
|
+
assert ! @application.raise_errors?
|
176
179
|
|
177
|
-
@
|
178
|
-
assert ! @
|
180
|
+
@application.set(:environment, :production)
|
181
|
+
assert ! @application.raise_errors?
|
179
182
|
|
180
|
-
@
|
181
|
-
assert @
|
183
|
+
@application.set(:environment, :test)
|
184
|
+
assert @application.raise_errors?
|
182
185
|
end
|
183
186
|
end
|
184
187
|
|
185
188
|
describe 'show_exceptions' do
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
189
|
+
it 'is disabled on Base except under development' do
|
190
|
+
@base.environment = :test
|
191
|
+
assert ! @base.show_exceptions?
|
192
|
+
@base.environment = :development
|
193
|
+
assert @base.show_exceptions?
|
191
194
|
end
|
192
195
|
|
193
|
-
it 'is enabled on
|
196
|
+
it 'is enabled on Application only in development' do
|
194
197
|
@base.set(:environment, :development)
|
195
|
-
assert @
|
196
|
-
assert @
|
198
|
+
assert @application.development?
|
199
|
+
assert @application.show_exceptions?
|
197
200
|
|
198
|
-
@
|
199
|
-
assert ! @
|
201
|
+
@application.set(:environment, :test)
|
202
|
+
assert ! @application.show_exceptions?
|
200
203
|
|
201
204
|
@base.set(:environment, :production)
|
202
205
|
assert ! @base.show_exceptions?
|
203
206
|
end
|
204
207
|
|
205
208
|
it 'returns a friendly 500' do
|
206
|
-
klass = Sinatra.new(Sinatra::
|
209
|
+
klass = Sinatra.new(Sinatra::Application)
|
207
210
|
mock_app(klass) {
|
208
211
|
enable :show_exceptions
|
209
212
|
|
@@ -215,21 +218,24 @@ class OptionsTest < Test::Unit::TestCase
|
|
215
218
|
get '/'
|
216
219
|
assert_equal 500, status
|
217
220
|
assert body.include?("StandardError")
|
218
|
-
assert body.include?("<code>show_exceptions</code>
|
221
|
+
assert body.include?("<code>show_exceptions</code> setting")
|
219
222
|
end
|
220
223
|
end
|
221
224
|
|
222
225
|
describe 'dump_errors' do
|
223
|
-
it 'is disabled on Base' do
|
226
|
+
it 'is disabled on Base except in development' do
|
227
|
+
@base.environment = :test
|
224
228
|
assert ! @base.dump_errors?
|
229
|
+
@base.environment = :development
|
230
|
+
assert @base.dump_errors?
|
225
231
|
end
|
226
232
|
|
227
|
-
it 'is enabled on
|
228
|
-
assert @
|
233
|
+
it 'is enabled on Application' do
|
234
|
+
assert @application.dump_errors?
|
229
235
|
end
|
230
236
|
|
231
237
|
it 'dumps exception with backtrace to rack.errors' do
|
232
|
-
klass = Sinatra.new(Sinatra::
|
238
|
+
klass = Sinatra.new(Sinatra::Application)
|
233
239
|
|
234
240
|
mock_app(klass) {
|
235
241
|
disable :raise_errors
|
@@ -256,8 +262,8 @@ class OptionsTest < Test::Unit::TestCase
|
|
256
262
|
assert ! @base.sessions?
|
257
263
|
end
|
258
264
|
|
259
|
-
it 'is disabled on
|
260
|
-
assert ! @
|
265
|
+
it 'is disabled on Application' do
|
266
|
+
assert ! @application.sessions?
|
261
267
|
end
|
262
268
|
|
263
269
|
# TODO: it 'uses Rack::Session::Cookie when enabled' do
|
@@ -268,99 +274,108 @@ class OptionsTest < Test::Unit::TestCase
|
|
268
274
|
assert ! @base.logging?
|
269
275
|
end
|
270
276
|
|
271
|
-
it 'is enabled on
|
272
|
-
assert @
|
277
|
+
it 'is enabled on Application when not in test environment' do
|
278
|
+
assert @application.logging?
|
273
279
|
|
274
|
-
@
|
275
|
-
assert ! @
|
280
|
+
@application.set :environment, :test
|
281
|
+
assert ! @application.logging
|
276
282
|
end
|
277
283
|
|
278
284
|
# TODO: it 'uses Rack::CommonLogger when enabled' do
|
279
285
|
end
|
280
286
|
|
281
287
|
describe 'static' do
|
282
|
-
it 'is disabled on Base' do
|
288
|
+
it 'is disabled on Base by Application' do
|
283
289
|
assert ! @base.static?
|
284
290
|
end
|
285
291
|
|
286
|
-
it 'is enabled on
|
287
|
-
|
292
|
+
it 'is enabled on Base when public is set and exists' do
|
293
|
+
@base.set :environment, :development
|
294
|
+
@base.set :public, File.dirname(__FILE__)
|
295
|
+
assert @base.static?
|
296
|
+
end
|
297
|
+
|
298
|
+
it 'is enabled on Base when root is set and root/public exists' do
|
299
|
+
@base.set :environment, :development
|
300
|
+
@base.set :root, File.dirname(__FILE__)
|
301
|
+
assert @base.static?
|
288
302
|
end
|
289
303
|
|
290
|
-
|
291
|
-
|
304
|
+
it 'is enabled on Application' do
|
305
|
+
assert @application.static?
|
306
|
+
end
|
292
307
|
end
|
293
308
|
|
294
309
|
describe 'host' do
|
295
310
|
it 'defaults to 0.0.0.0' do
|
296
311
|
assert_equal '0.0.0.0', @base.host
|
297
|
-
assert_equal '0.0.0.0', @
|
312
|
+
assert_equal '0.0.0.0', @application.host
|
298
313
|
end
|
299
314
|
end
|
300
315
|
|
301
316
|
describe 'port' do
|
302
317
|
it 'defaults to 4567' do
|
303
318
|
assert_equal 4567, @base.port
|
304
|
-
assert_equal 4567, @
|
319
|
+
assert_equal 4567, @application.port
|
305
320
|
end
|
306
321
|
end
|
307
322
|
|
308
323
|
describe 'server' do
|
309
324
|
it 'is one of thin, mongrel, webrick' do
|
310
325
|
assert_equal %w[thin mongrel webrick], @base.server
|
311
|
-
assert_equal %w[thin mongrel webrick], @
|
326
|
+
assert_equal %w[thin mongrel webrick], @application.server
|
312
327
|
end
|
313
328
|
end
|
314
329
|
|
315
330
|
describe 'app_file' do
|
316
331
|
it 'is nil' do
|
317
332
|
assert @base.app_file.nil?
|
318
|
-
assert @
|
333
|
+
assert @application.app_file.nil?
|
319
334
|
end
|
320
335
|
end
|
321
336
|
|
322
337
|
describe 'root' do
|
323
338
|
it 'is nil if app_file is not set' do
|
324
339
|
assert @base.root.nil?
|
325
|
-
assert @
|
340
|
+
assert @application.root.nil?
|
326
341
|
end
|
327
342
|
|
328
343
|
it 'is equal to the expanded basename of app_file' do
|
329
344
|
@base.app_file = __FILE__
|
330
345
|
assert_equal File.expand_path(File.dirname(__FILE__)), @base.root
|
331
346
|
|
332
|
-
@
|
333
|
-
assert_equal File.expand_path(File.dirname(__FILE__)), @
|
347
|
+
@application.app_file = __FILE__
|
348
|
+
assert_equal File.expand_path(File.dirname(__FILE__)), @application.root
|
334
349
|
end
|
335
350
|
end
|
336
351
|
|
337
352
|
describe 'views' do
|
338
353
|
it 'is nil if root is not set' do
|
339
354
|
assert @base.views.nil?
|
340
|
-
assert @
|
355
|
+
assert @application.views.nil?
|
341
356
|
end
|
342
357
|
|
343
358
|
it 'is set to root joined with views/' do
|
344
359
|
@base.root = File.dirname(__FILE__)
|
345
360
|
assert_equal File.dirname(__FILE__) + "/views", @base.views
|
346
361
|
|
347
|
-
@
|
348
|
-
assert_equal File.dirname(__FILE__) + "/views", @
|
362
|
+
@application.root = File.dirname(__FILE__)
|
363
|
+
assert_equal File.dirname(__FILE__) + "/views", @application.views
|
349
364
|
end
|
350
365
|
end
|
351
366
|
|
352
367
|
describe 'public' do
|
353
368
|
it 'is nil if root is not set' do
|
354
369
|
assert @base.public.nil?
|
355
|
-
assert @
|
370
|
+
assert @application.public.nil?
|
356
371
|
end
|
357
372
|
|
358
373
|
it 'is set to root joined with public/' do
|
359
374
|
@base.root = File.dirname(__FILE__)
|
360
375
|
assert_equal File.dirname(__FILE__) + "/public", @base.public
|
361
376
|
|
362
|
-
@
|
363
|
-
assert_equal File.dirname(__FILE__) + "/public", @
|
377
|
+
@application.root = File.dirname(__FILE__)
|
378
|
+
assert_equal File.dirname(__FILE__) + "/public", @application.public
|
364
379
|
end
|
365
380
|
end
|
366
381
|
|
File without changes
|
data/test/templates_test.rb
CHANGED
@@ -68,9 +68,9 @@ class TemplatesTest < Test::Unit::TestCase
|
|
68
68
|
assert_equal "Layout 3!\nHello World!\n", body
|
69
69
|
end
|
70
70
|
|
71
|
-
it 'loads templates from source file with
|
71
|
+
it 'loads templates from source file with inline templates' do
|
72
72
|
mock_app {
|
73
|
-
|
73
|
+
enable :inline_templates
|
74
74
|
}
|
75
75
|
assert_equal "this is foo\n\n", @app.templates[:foo][:template]
|
76
76
|
assert_equal "X\n= yield\nX\n", @app.templates[:layout][:template]
|
@@ -82,10 +82,10 @@ class TemplatesTest < Test::Unit::TestCase
|
|
82
82
|
assert_equal "from another views directory\n", body
|
83
83
|
end
|
84
84
|
|
85
|
-
test '
|
85
|
+
test 'inline_templates simply ignores IO errors' do
|
86
86
|
assert_nothing_raised {
|
87
87
|
mock_app {
|
88
|
-
|
88
|
+
set :inline_templates, '/foo/bar'
|
89
89
|
}
|
90
90
|
}
|
91
91
|
|
data/test/test_test.rb
CHANGED
@@ -65,6 +65,9 @@ class TestTest < Test::Unit::TestCase
|
|
65
65
|
it 'allows to specify params' do
|
66
66
|
get '/', :foo => 'bar'
|
67
67
|
assert_equal 'bar', request_params['foo']
|
68
|
+
|
69
|
+
post '/', :foo => 'bar'
|
70
|
+
assert_equal 'bar', request_params['foo']
|
68
71
|
end
|
69
72
|
|
70
73
|
it 'supports nested params' do
|
@@ -111,7 +114,7 @@ class TestTest < Test::Unit::TestCase
|
|
111
114
|
end
|
112
115
|
|
113
116
|
it 'allow to test session easily' do
|
114
|
-
app = mock_app(Sinatra::
|
117
|
+
app = mock_app(Sinatra::Base) {
|
115
118
|
get '/' do
|
116
119
|
session['foo'] = 'bar'
|
117
120
|
200
|
@@ -139,9 +142,9 @@ class TestTest < Test::Unit::TestCase
|
|
139
142
|
end
|
140
143
|
|
141
144
|
it 'sets the environment to :test on include' do
|
142
|
-
Sinatra::
|
145
|
+
Sinatra::Application.set(:environment, :production)
|
143
146
|
Class.new { include Sinatra::Test }
|
144
|
-
assert_equal :test, Sinatra::
|
147
|
+
assert_equal :test, Sinatra::Application.environment
|
145
148
|
end
|
146
149
|
|
147
150
|
def test_TestHarness
|
metadata
CHANGED
@@ -1,7 +1,12 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sinatra
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 9
|
8
|
+
- 5
|
9
|
+
version: 0.9.5
|
5
10
|
platform: ruby
|
6
11
|
authors:
|
7
12
|
- Blake Mizerany
|
@@ -9,42 +14,56 @@ autorequire:
|
|
9
14
|
bindir: bin
|
10
15
|
cert_chain: []
|
11
16
|
|
12
|
-
date:
|
17
|
+
date: 2010-03-04 00:00:00 -08:00
|
13
18
|
default_executable:
|
14
19
|
dependencies:
|
15
20
|
- !ruby/object:Gem::Dependency
|
16
21
|
name: rack
|
17
|
-
|
18
|
-
|
19
|
-
version_requirements: !ruby/object:Gem::Requirement
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
20
24
|
requirements:
|
21
25
|
- - ">="
|
22
26
|
- !ruby/object:Gem::Version
|
27
|
+
segments:
|
28
|
+
- 0
|
29
|
+
- 9
|
30
|
+
- 1
|
23
31
|
version: 0.9.1
|
24
|
-
|
32
|
+
type: :runtime
|
33
|
+
version_requirements: *id001
|
25
34
|
- !ruby/object:Gem::Dependency
|
26
35
|
name: shotgun
|
27
|
-
|
28
|
-
|
29
|
-
version_requirements: !ruby/object:Gem::Requirement
|
36
|
+
prerelease: false
|
37
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
30
38
|
requirements:
|
31
39
|
- - ">="
|
32
40
|
- !ruby/object:Gem::Version
|
41
|
+
segments:
|
42
|
+
- 0
|
43
|
+
- 2
|
33
44
|
version: "0.2"
|
34
45
|
- - <
|
35
46
|
- !ruby/object:Gem::Version
|
47
|
+
segments:
|
48
|
+
- 1
|
49
|
+
- 0
|
36
50
|
version: "1.0"
|
37
|
-
|
51
|
+
type: :development
|
52
|
+
version_requirements: *id002
|
38
53
|
- !ruby/object:Gem::Dependency
|
39
54
|
name: rack-test
|
40
|
-
|
41
|
-
|
42
|
-
version_requirements: !ruby/object:Gem::Requirement
|
55
|
+
prerelease: false
|
56
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
43
57
|
requirements:
|
44
58
|
- - ">="
|
45
59
|
- !ruby/object:Gem::Version
|
60
|
+
segments:
|
61
|
+
- 0
|
62
|
+
- 3
|
63
|
+
- 0
|
46
64
|
version: 0.3.0
|
47
|
-
|
65
|
+
type: :development
|
66
|
+
version_requirements: *id003
|
48
67
|
description: Classy web-development dressed in a DSL
|
49
68
|
email: sinatrarb@googlegroups.com
|
50
69
|
executables: []
|
@@ -111,7 +130,6 @@ files:
|
|
111
130
|
- test/base_test.rb
|
112
131
|
- test/builder_test.rb
|
113
132
|
- test/contest.rb
|
114
|
-
- test/data/reload_app_file.rb
|
115
133
|
- test/erb_test.rb
|
116
134
|
- test/extensions_test.rb
|
117
135
|
- test/filter_test.rb
|
@@ -121,6 +139,7 @@ files:
|
|
121
139
|
- test/mapped_error_test.rb
|
122
140
|
- test/middleware_test.rb
|
123
141
|
- test/options_test.rb
|
142
|
+
- test/public/favicon.ico
|
124
143
|
- test/render_backtrace_test.rb
|
125
144
|
- test/request_test.rb
|
126
145
|
- test/response_test.rb
|
@@ -165,18 +184,20 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
165
184
|
requirements:
|
166
185
|
- - ">="
|
167
186
|
- !ruby/object:Gem::Version
|
187
|
+
segments:
|
188
|
+
- 0
|
168
189
|
version: "0"
|
169
|
-
version:
|
170
190
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
171
191
|
requirements:
|
172
192
|
- - ">="
|
173
193
|
- !ruby/object:Gem::Version
|
194
|
+
segments:
|
195
|
+
- 0
|
174
196
|
version: "0"
|
175
|
-
version:
|
176
197
|
requirements: []
|
177
198
|
|
178
199
|
rubyforge_project: sinatra
|
179
|
-
rubygems_version: 1.3.
|
200
|
+
rubygems_version: 1.3.6
|
180
201
|
signing_key:
|
181
202
|
specification_version: 2
|
182
203
|
summary: Classy web-development dressed in a DSL
|