Skip to content
Browse files

Merge branch 'master' into tilt-1.3

  • Loading branch information...
2 parents 397708b + 59e8698 commit 6ad90f55e566eafd4aa7e9d40a02b087df5a3b08 @rkh rkh committed Apr 17, 2011
Showing with 100 additions and 33 deletions.
  1. +1 −0 .yardopts
  2. +10 −0 CHANGES
  3. +3 −3 README.de.rdoc
  4. +3 −3 README.es.rdoc
  5. +3 −3 README.fr.rdoc
  6. +1 −1 README.hu.rdoc
  7. +1 −1 README.jp.rdoc
  8. +1 −1 README.pt-br.rdoc
  9. +1 −1 README.pt-pt.rdoc
  10. +3 −3 README.rdoc
  11. +3 −3 README.ru.rdoc
  12. +3 −3 README.zh.rdoc
  13. +7 −5 lib/sinatra/base.rb
  14. +21 −1 test/delegator_test.rb
  15. +21 −5 test/routing_test.rb
  16. +18 −0 test/settings_test.rb
View
1 .yardopts
@@ -1,3 +1,4 @@
--readme README.rdoc
--title 'Sinatra API Documentation'
+--charset utf-8
'lib/**/*.rb' - '*.rdoc'
View
10 CHANGES
@@ -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
6 README.de.rdoc
@@ -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
6 README.es.rdoc
@@ -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
6 README.fr.rdoc
@@ -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
2 README.hu.rdoc
@@ -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
2 README.jp.rdoc
@@ -713,7 +713,7 @@ body部を指定することもできます ...
エラーをカスタマイズする場合は、
error MyCustomError do
- 'エラーメッセージ...' + request.env['sinatra.error'].message
+ 'エラーメッセージ...' + env['sinatra.error'].message
end
と書いておいて,下記のように呼び出します。
View
2 README.pt-br.rdoc
@@ -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
2 README.pt-pt.rdoc
@@ -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
6 README.rdoc
@@ -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
6 README.ru.rdoc
@@ -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
6 README.zh.rdoc
@@ -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
12 lib/sinatra/base.rb
@@ -362,7 +362,7 @@ def last_modified(time)
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 @@ def pass(&block)
# 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 @@ def middleware
# 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 @@ def self.delegate(*methods)
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
22 test/delegator_test.rb
@@ -100,13 +100,33 @@ def target
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
26 test/routing_test.rb
@@ -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 @@ def authorize(username, password)
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
+
+ get '/bar' do
+ "bar"
+ end
+ end
+
+ get '/foo'
+ assert ok?
+ assert_body "BAR"
+ end
- it 'is plays well with other routing middleware' do
+ it 'plays well with other routing middleware' do
middleware = Sinatra.new
inner_app = Sinatra.new { get('/foo') { 'hello' } }
builder = Rack::Builder.new do
View
18 test/settings_test.rb
@@ -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',

0 comments on commit 6ad90f5

Please sign in to comment.
Something went wrong with that request. Please try again.