make respond-with play nice with namespace
This commit is contained in:
parent
503250fd67
commit
31cdac9d0e
|
@ -66,6 +66,11 @@ module Sinatra
|
||||||
[*codes].each { |c| errors[c] = block }
|
[*codes].each { |c| errors[c] = block }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def respond_to(*args)
|
||||||
|
return @conditions[:provides] || base.respond_to if args.empty?
|
||||||
|
@conditions[:provides] = args
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def app
|
def app
|
||||||
|
|
|
@ -108,7 +108,7 @@ module Sinatra
|
||||||
result
|
result
|
||||||
end
|
end
|
||||||
|
|
||||||
def respond_to(*formats, &block)
|
def respond_to(*formats)
|
||||||
if formats.any?
|
if formats.any?
|
||||||
@respond_to ||= []
|
@respond_to ||= []
|
||||||
@respond_to.concat formats
|
@respond_to.concat formats
|
||||||
|
|
|
@ -262,5 +262,19 @@ describe Sinatra::RespondWith do
|
||||||
req('/b', :html).should_not be_ok
|
req('/b', :html).should_not be_ok
|
||||||
req('/b', :json).should be_ok
|
req('/b', :json).should be_ok
|
||||||
end
|
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
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue