Skip to content
Browse files

returns block body if body is never called

  • Loading branch information...
1 parent 49da7fc commit 0302501212ff22b9c511ae920884467639f8d548 blake.mizerany@gmail.com committed Sep 12, 2007
Showing with 17 additions and 5 deletions.
  1. +2 −2 examples/calendar/calendar.rb
  2. +3 −2 lib/sinatra/event.rb
  3. +11 −0 test/sinatra/dispatcher_test.rb
  4. +1 −1 test/sinatra/event_test.rb
View
4 examples/calendar/calendar.rb
@@ -2,6 +2,6 @@
require 'sinatra'
get '/' do
- format.html {p "here, b"}
- p "hi"
+ format.html { body 'blake' }
+ format.xml { body 'test' }
end
View
5 lib/sinatra/event.rb
@@ -59,7 +59,7 @@ def status(value = nil)
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 @@ def attend(request)
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
View
11 test/sinatra/dispatcher_test.rb
@@ -56,5 +56,16 @@
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
View
2 test/sinatra/event_test.rb
@@ -33,5 +33,5 @@
Sinatra::EventManager.expects(:not_found)
Sinatra::EventManager.determine_event(:get, '/asdfsasd')
end
-
+
end

0 comments on commit 0302501

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