mirror of
https://github.com/sinatra/sinatra
synced 2023-03-27 23:18:01 -04:00
let use_code default to false, remove warning. fixes #497
This commit is contained in:
parent
6ec5234517
commit
97e1bd2c80
3 changed files with 28 additions and 7 deletions
6
CHANGES
6
CHANGES
|
@ -10,9 +10,9 @@
|
|||
* The `provides` condition now respects an earlier set content type.
|
||||
(Konstantin Haase)
|
||||
|
||||
* Exception#code is only used when :use_code is enabled and displays a warning.
|
||||
Moreover, it will be ignored if the value is not between 400 and 599. You
|
||||
should use Exception#http_status instead. (Konstantin Haase)
|
||||
* Exception#code is only used when :use_code is enabled. Moreover, it will
|
||||
be ignored if the value is not between 400 and 599. You should use
|
||||
Exception#http_status instead. (Konstantin Haase)
|
||||
|
||||
* Status, headers and body will be set correctly in an after filter when using
|
||||
halt in a before filter or route. (Konstantin Haase)
|
||||
|
|
|
@ -960,9 +960,6 @@ module Sinatra
|
|||
status(boom.http_status)
|
||||
elsif settings.use_code? and boom.respond_to? :code and boom.code.between? 400, 599
|
||||
status(boom.code)
|
||||
warn "Using #{boom.class}#code (#{status}) for setting status code. This is deprecated. " \
|
||||
"Use #http_status instead. If this happens unintentional, please \`disable :use_code\`" \
|
||||
" in your application."
|
||||
else
|
||||
status(500)
|
||||
end
|
||||
|
@ -1588,7 +1585,7 @@ module Sinatra
|
|||
set :logging, false
|
||||
set :protection, true
|
||||
set :method_override, false
|
||||
set :use_code, true
|
||||
set :use_code, false
|
||||
set :default_encoding, "utf-8"
|
||||
set :add_charset, %w[javascript xml xhtml+xml json].map { |t| "application/#{t}" }
|
||||
settings.add_charset << /^text\//
|
||||
|
|
|
@ -14,6 +14,10 @@ class FooStatusOutOfRangeError < RuntimeError
|
|||
def code; 4000 end
|
||||
end
|
||||
|
||||
class FooWithCode < RuntimeError
|
||||
def code; 419 end
|
||||
end
|
||||
|
||||
class FirstError < RuntimeError; end
|
||||
class SecondError < RuntimeError; end
|
||||
|
||||
|
@ -200,9 +204,29 @@ class MappedErrorTest < Test::Unit::TestCase
|
|||
assert_equal 'Foo!', body
|
||||
end
|
||||
|
||||
it 'does not use Exception#code by default' do
|
||||
mock_app do
|
||||
set :raise_errors, false
|
||||
get('/') { raise FooWithCode }
|
||||
end
|
||||
get '/'
|
||||
assert_equal 500, status
|
||||
end
|
||||
|
||||
it 'uses Exception#code if use_code is enabled' do
|
||||
mock_app do
|
||||
set :raise_errors, false
|
||||
set :use_code, true
|
||||
get('/') { raise FooWithCode }
|
||||
end
|
||||
get '/'
|
||||
assert_equal 419, status
|
||||
end
|
||||
|
||||
it 'does not rely on Exception#code for invalid codes' do
|
||||
mock_app do
|
||||
set :raise_errors, false
|
||||
set :use_code, true
|
||||
get('/') { raise FooStatusOutOfRangeError }
|
||||
end
|
||||
get '/'
|
||||
|
|
Loading…
Reference in a new issue