A route can be redfined

This may need some clean-up
This commit is contained in:
Blake Mizerany 2009-01-08 18:35:00 -08:00
parent 641965b274
commit 67906d391d
2 changed files with 25 additions and 0 deletions

View File

@ -554,6 +554,8 @@ module Sinatra
pattern, keys = compile(path)
conditions, @conditions = @conditions, []
method_name = "route { #{method} #{path} }"
nmethods = instance_methods.grep(rx = /#{Regexp.escape(method_name)}/).size
method_name += " [#{nmethods}]"
define_method(method_name, &block)

View File

@ -46,4 +46,27 @@ describe 'Sinatra::Base' do
response.should.be.ok
response.body.should.equal 'Goodbye World'
end
it 'can take multiple definitions of a route' do
app = mock_app {
user_agent /Foo/
get '/foo' do
'foo'
end
get '/foo' do
'not foo'
end
}
request = Rack::MockRequest.new(app)
response = request.get('/foo', 'HTTP_USER_AGENT' => 'Foo')
response.should.be.ok
response.body.should.equal 'foo'
request = Rack::MockRequest.new(app)
response = request.get('/foo')
response.should.be.ok
response.body.should.equal 'not foo'
end
end