1
0
Fork 0
mirror of https://github.com/sinatra/sinatra synced 2023-03-27 23:18:01 -04:00

Merge branch 'master' into tilt-1.3

This commit is contained in:
Konstantin Haase 2011-04-17 14:47:37 +02:00
commit 6ad90f55e5
16 changed files with 100 additions and 33 deletions

View file

@ -1,3 +1,4 @@
--readme README.rdoc
--title 'Sinatra API Documentation'
--charset utf-8
'lib/**/*.rb' - '*.rdoc'

10
CHANGES
View file

@ -21,11 +21,21 @@
* Added `request.accept?` and `request.preferred_type` to ease dealing with
`Accept` headers. (Konstantin Haase)
= 1.2.4 / Not Yet Released
* Sinatra::Application (classic style) does not use a session secret in
development mode, so sessions are not invalidated after every request when
using Shotgun. (Konstantin Haase)
* The request object was shared between multiple Sinatra instances in the
same middleware chain. This caused issues if any non-sinatra routing
happend in-between two of those instances. The caching was reverted. See
GH#239 for more infos. (Konstantin Haase)
* Fixes issues where the top level DSL was interfering with method_missing
proxies. This issue surfaced when Rails 3 was used with older Sass versions
and Sinatra >= 1.2.0. (Konstantin Haase)
= 1.2.3 / 2011-04-13
* This release is compatible with Tilt 1.3, it will still work with Tilt 1.2.2,

View file

@ -921,8 +921,8 @@ Manchmal entspricht +pass+ nicht den Anforderungen, wenn das Ergebnis einer
anderen Route gefordert wird. Um das zu erreichen, lässt sich +call+ nutzen:
get '/foo' do
status, headers, body = call request.env.merge("PATH_INFO" => '/bar')
[status, body.upcase]
status, headers, body = call env.merge("PATH_INFO" => '/bar')
[status, headers, body.map(&:upcase)]
end
get '/bar' do
@ -1401,7 +1401,7 @@ Routen-Block oder in einem Filter geworfen wurde. Die Exception kann über die
Benutzerdefinierte Fehler:
error MeinFehler do
'Au weia, ' + request.env['sinatra.error'].message
'Au weia, ' + env['sinatra.error'].message
end
Dann, wenn das passiert:

View file

@ -896,8 +896,8 @@ Cuando querés obtener el resultado de la llamada a una ruta, +pass+ no te va a
servir. Para lograr esto, podés usar +call+:
get '/foo' do
status, headers, body = call request.env.merge("PATH_INFO" => '/bar')
[status, body.upcase]
status, headers, body = call env.merge("PATH_INFO" => '/bar')
[status, headers, body.map(&:upcase)]
end
get '/bar' do
@ -1414,7 +1414,7 @@ obtener de la variable Rack <tt>sinatra.error</tt>:
Errores personalizados:
error MiErrorPersonalizado do
'Lo que pasó fue...' request.env['sinatra.error'].message
'Lo que pasó fue...' + env['sinatra.error'].message
end
Entonces, si pasa esto:

View file

@ -925,8 +925,8 @@ souhaitez obtenir le résultat d'une autre route. Pour cela, utilisez
simplement +call+ :
get '/foo' do
status, headers, body = call request.env.merge("PATH_INFO" => '/bar')
[status, body.upcase]
status, headers, body = call env.merge("PATH_INFO" => '/bar')
[status, headers, body.map(&:upcase)]
end
get '/bar' do
@ -1457,7 +1457,7 @@ variable Rack <tt>sinatra.error</tt>:
Erreur sur mesure:
error MonErreurSurMesure do
'Donc il est arrivé ceci...' + request.env['sinatra.error'].message
'Donc il est arrivé ceci...' + env['sinatra.error'].message
end
Donc si ceci arrive:

View file

@ -399,7 +399,7 @@ előszűrő kivételt vált ki. A kivétel objektum lehívható a
Egyéni hibakezelés:
error MyCustomError do
'Szóval az van, hogy...' + request.env['sinatra.error'].message
'Szóval az van, hogy...' + env['sinatra.error'].message
end
És amikor fellép:

View file

@ -713,7 +713,7 @@ body部を指定することもできます ...
エラーをカスタマイズする場合は、
error MyCustomError do
'エラーメッセージ...' + request.env['sinatra.error'].message
'エラーメッセージ...' + env['sinatra.error'].message
end
と書いておいて,下記のように呼び出します。

View file

@ -431,7 +431,7 @@ Rack <tt>sinatra.error</tt>:
Erros customizados:
error MeuErroCustomizado do
'Então que aconteceu foi...' + request.env['sinatra.error'].message
'Então que aconteceu foi...' + env['sinatra.error'].message
end
Então, se isso acontecer:

View file

@ -430,7 +430,7 @@ Rack <tt>sinatra.error</tt>:
Erros personalizados:
error MeuErroPersonalizado do
'O que aconteceu foi...' + request.env['sinatra.error'].message
'O que aconteceu foi...' + env['sinatra.error'].message
end
Então, se isso acontecer:

View file

@ -852,8 +852,8 @@ Sometimes +pass+ is not what you want, instead you would like to get the result
of calling another route. Simply use +call+ to achieve this:
get '/foo' do
status, headers, body = call request.env.merge("PATH_INFO" => '/bar')
[status, body.upcase]
status, headers, body = call env.merge("PATH_INFO" => '/bar')
[status, headers, body.map(&:upcase)]
end
get '/bar' do
@ -1349,7 +1349,7 @@ block or a filter. The exception object can be obtained from the
Custom errors:
error MyCustomError do
'So what happened was...' + request.env['sinatra.error'].message
'So what happened was...' + env['sinatra.error'].message
end
Then, if this happens:

View file

@ -871,8 +871,8 @@ Thin - это более производительный и функциона
вызова другого обработчика маршрута. В таком случае просто используйте +call+:
get '/foo' do
status, headers, body = call request.env.merge("PATH_INFO" => '/bar')
[status, body.upcase]
status, headers, body = call env.merge("PATH_INFO" => '/bar')
[status, headers, body.map(&:upcase)]
end
get '/bar' do
@ -1362,7 +1362,7 @@ Thin - это более производительный и функциона
Частные ошибки:
error MyCustomError do
'So what happened was...' + request.env['sinatra.error'].message
'So what happened was...' + env['sinatra.error'].message
end
Тогда, если это произошло:

View file

@ -856,8 +856,8 @@ Session被用来在请求之间保持状态。如果被激活每一个用户
。简单的使用 +call+ 可以做到这一点:
get '/foo' do
status, headers, body = call request.env.merge("PATH_INFO" => '/bar')
[status, body.upcase]
status, headers, body = call env.merge("PATH_INFO" => '/bar')
[status, headers, body.map(&:upcase)]
end
get '/bar' do
@ -1327,7 +1327,7 @@ Sinatra会自动处理range请求。
自定义错误:
error MyCustomError do
'So what happened was...' + request.env['sinatra.error'].message
'So what happened was...' + env['sinatra.error'].message
end
那么,当这个发生的时候:

View file

@ -362,7 +362,7 @@ module Sinatra
time = time_for time
response['Last-Modified'] = time.httpdate
# compare based on seconds since epoch
halt 304 if Time.httpdate(request.env['HTTP_IF_MODIFIED_SINCE']).to_i >= time.to_i
halt 304 if Time.httpdate(env['HTTP_IF_MODIFIED_SINCE']).to_i >= time.to_i
rescue ArgumentError
end
@ -698,7 +698,7 @@ module Sinatra
# Forward the request to the downstream app -- middleware only.
def forward
fail "downstream app not set" unless @app.respond_to? :call
status, headers, body = @app.call(@request.env)
status, headers, body = @app.call env
@response.status = status
@response.body = body
@response.headers.merge! headers
@ -950,14 +950,15 @@ module Sinatra
# Sets an option to the given value. If the value is a proc,
# the proc will be called every time the option is accessed.
def set(option, value=self, &block)
raise ArgumentError if block && value != self
def set(option, value = (not_set = true), &block)
raise ArgumentError if block and !not_set
value = block if block
if value.kind_of?(Proc)
metadef(option, &value)
metadef("#{option}?") { !!__send__(option) }
metadef("#{option}=") { |val| metadef(option, &Proc.new{val}) }
elsif value == self && option.respond_to?(:each)
elsif not_set
raise ArgumentError unless option.respond_to?(:each)
option.each { |k,v| set(k, v) }
elsif respond_to?("#{option}=")
__send__ "#{option}=", value
@ -1495,6 +1496,7 @@ module Sinatra
methods.each do |method_name|
eval <<-RUBY, binding, '(__DELEGATE__)', 1
def #{method_name}(*args, &b)
return super if respond_to? #{method_name.inspect}
::Sinatra::Delegator.target.send(#{method_name.inspect}, *args, &b)
end
private #{method_name.inspect}

View file

@ -100,13 +100,33 @@ class DelegatorTest < Test::Unit::TestCase
assert_equal app.last_call, ["helpers", mixin.to_s ]
end
it "registers helpers with the delegation target" do
app, mixin = mirror, Module.new
Sinatra.use mixin
assert_equal app.last_call, ["use", mixin.to_s ]
end
it "should work with method_missing proxies for options" do
mixin = Module.new do
def respond_to?(method, *)
method.to_sym == :options or super
end
def method_missing(method, *args, &block)
return super unless method.to_sym == :options
{:some => :option}
end
end
value = nil
mirror do
extend mixin
value = options
end
assert_equal({:some => :option}, value)
end
delegates 'get'
delegates 'patch'
delegates 'put'

View file

@ -686,10 +686,10 @@ class RoutingTest < Test::Unit::TestCase
it "filters by accept header" do
mock_app {
get '/', :provides => :xml do
request.env['HTTP_ACCEPT']
env['HTTP_ACCEPT']
end
get '/foo', :provides => :html do
request.env['HTTP_ACCEPT']
env['HTTP_ACCEPT']
end
}
@ -714,7 +714,7 @@ class RoutingTest < Test::Unit::TestCase
mock_app {
get '/', :provides => types do
request.env['HTTP_ACCEPT']
env['HTTP_ACCEPT']
end
}
@ -729,7 +729,7 @@ class RoutingTest < Test::Unit::TestCase
it 'degrades gracefully when optional accept header is not provided' do
mock_app {
get '/', :provides => :xml do
request.env['HTTP_ACCEPT']
env['HTTP_ACCEPT']
end
get '/' do
'default'
@ -1043,8 +1043,24 @@ class RoutingTest < Test::Unit::TestCase
assert not_found?
end
it 'allows using call to fire another request internally' do
mock_app do
get '/foo' do
status, headers, body = call env.merge("PATH_INFO" => '/bar')
[status, headers, body.map(&:upcase)]
end
it 'is plays well with other routing middleware' do
get '/bar' do
"bar"
end
end
get '/foo'
assert ok?
assert_body "BAR"
end
it 'plays well with other routing middleware' do
middleware = Sinatra.new
inner_app = Sinatra.new { get('/foo') { 'hello' } }
builder = Rack::Builder.new do

View file

@ -34,6 +34,24 @@ class SettingsTest < Test::Unit::TestCase
assert !@base.respond_to?(:fiz)
end
it 'raises an error without value and block' do
assert_raise(ArgumentError) { @base.set(:fiz) }
assert !@base.respond_to?(:fiz)
end
it 'allows setting a value to the app class' do
@base.set :base, @base
assert @base.respond_to?(:base)
assert_equal @base, @base.base
end
it 'raises an error with the app class as value and a block' do
assert_raise ArgumentError do
@base.set(:fiz, @base) { 'baz' }
end
assert !@base.respond_to?(:fiz)
end
it "sets multiple settings with a Hash" do
@base.set :foo => 1234,
:bar => 'Hello World',