Undeprecate headers helper method [#125]

This commit is contained in:
Ryan Tomayko 2009-03-02 15:22:30 -08:00
parent 9af37724e0
commit 4fc9cb8b65
3 changed files with 40 additions and 6 deletions

View File

@ -100,6 +100,12 @@ module Sinatra
error 404, body
end
# Set multiple response headers with Hash.
def headers(hash=nil)
response.headers.merge! hash if hash
response.headers
end
# Access the underlying Rack session.
def session
env['rack.session'] ||= {}
@ -379,7 +385,7 @@ module Sinatra
status, headers, body = @app.call(@request.env)
@response.status = status
@response.body = body
headers.each { |k, v| @response[k] = v }
@response.headers.merge! headers
nil
end

View File

@ -87,12 +87,10 @@ module Sinatra
end
# Deprecated. Use: response['Header-Name']
def headers(header=nil)
sinatra_warn "The 'headers' method is deprecated; use 'response' instead."
response.headers.merge!(header) if header
response.headers
def header(header=nil)
sinatra_warn "The 'header' method is deprecated; use 'headers' instead."
headers(header)
end
alias :header :headers
# Deprecated. Use: halt
def stop(*args, &block)

View File

@ -140,6 +140,36 @@ describe 'Helpers#not_found' do
end
end
describe 'Helpers#headers' do
it 'sets headers on the response object when given a Hash' do
mock_app {
get '/' do
headers 'X-Foo' => 'bar', 'X-Baz' => 'bling'
'kthx'
end
}
get '/'
assert ok?
assert_equal 'bar', response['X-Foo']
assert_equal 'bling', response['X-Baz']
assert_equal 'kthx', body
end
it 'returns the response headers hash when no hash provided' do
mock_app {
get '/' do
headers['X-Foo'] = 'bar'
'kthx'
end
}
get '/'
assert ok?
assert_equal 'bar', response['X-Foo']
end
end
describe 'Helpers#session' do
it 'uses the existing rack.session' do
mock_app {