make respond-with play nice with namespace

This commit is contained in:
Konstantin Haase 2011-03-26 00:22:19 +01:00
parent 503250fd67
commit 31cdac9d0e
3 changed files with 20 additions and 1 deletions

View File

@ -66,6 +66,11 @@ module Sinatra
[*codes].each { |c| errors[c] = block }
end
def respond_to(*args)
return @conditions[:provides] || base.respond_to if args.empty?
@conditions[:provides] = args
end
private
def app

View File

@ -108,7 +108,7 @@ module Sinatra
result
end
def respond_to(*formats, &block)
def respond_to(*formats)
if formats.any?
@respond_to ||= []
@respond_to.concat formats

View File

@ -262,5 +262,19 @@ describe Sinatra::RespondWith do
req('/b', :html).should_not be_ok
req('/b', :json).should be_ok
end
it 'plays well with namespaces' do
respond_app do
register Sinatra::Namespace
namespace '/a' do
respond_to :json
get { 'json' }
end
get('/b') { 'anything' }
end
req('/a', :html).should_not be_ok
req('/b', :html).should be_ok
end
end
end