mirror of
https://github.com/sinatra/sinatra
synced 2023-03-27 23:18:01 -04:00
returns block body if body is never called
This commit is contained in:
parent
49da7fc4c7
commit
0302501212
4 changed files with 17 additions and 5 deletions
|
@ -2,6 +2,6 @@ $LOAD_PATH.unshift File.dirname(__FILE__) + '/../../lib/'
|
|||
require 'sinatra'
|
||||
|
||||
get '/' do
|
||||
format.html {p "here, b"}
|
||||
p "hi"
|
||||
format.html { body 'blake' }
|
||||
format.xml { body 'test' }
|
||||
end
|
||||
|
|
|
@ -59,7 +59,7 @@ module Sinatra
|
|||
def body(value = nil, &block)
|
||||
@body = value if value
|
||||
@body = block.call if block
|
||||
@body || ''
|
||||
@body
|
||||
end
|
||||
|
||||
def error(value = nil)
|
||||
|
@ -121,7 +121,8 @@ module Sinatra
|
|||
request.params.merge!(path.extract_params(request.path_info))
|
||||
context = EventContext.new(request)
|
||||
begin
|
||||
context.instance_eval(&@block) if @block
|
||||
result = context.instance_eval(&@block) if @block
|
||||
context.body context.body || result || ''
|
||||
rescue => e
|
||||
context.error e
|
||||
end
|
||||
|
|
|
@ -56,5 +56,16 @@ describe "When a dispatcher receives a request" do
|
|||
get_it '/blake'
|
||||
Sinatra::EventManager.events.size.should.equal 0
|
||||
end
|
||||
|
||||
it "should return blocks result if body not called" do
|
||||
event = Sinatra::Event.new(:get, '/return_block') do
|
||||
'no body called'
|
||||
end
|
||||
|
||||
get_it '/return_block'
|
||||
|
||||
status.should.equal 200
|
||||
html.should.equal 'no body called'
|
||||
end
|
||||
|
||||
end
|
|
@ -33,5 +33,5 @@ describe "Event" do
|
|||
Sinatra::EventManager.expects(:not_found)
|
||||
Sinatra::EventManager.determine_event(:get, '/asdfsasd')
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue