Skip to content

Commit

Permalink
A route can be redfined
Browse files Browse the repository at this point in the history
This may need some clean-up
  • Loading branch information
bmizerany committed Jan 9, 2009
1 parent 641965b commit 67906d3
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/sinatra/base.rb
Expand Up @@ -554,6 +554,8 @@ def route(method, path, opts={}, &block)
pattern, keys = compile(path) pattern, keys = compile(path)
conditions, @conditions = @conditions, [] conditions, @conditions = @conditions, []
method_name = "route { #{method} #{path} }" method_name = "route { #{method} #{path} }"
nmethods = instance_methods.grep(rx = /#{Regexp.escape(method_name)}/).size
method_name += " [#{nmethods}]"


define_method(method_name, &block) define_method(method_name, &block)


Expand Down
23 changes: 23 additions & 0 deletions test/base_test.rb
Expand Up @@ -46,4 +46,27 @@
response.should.be.ok response.should.be.ok
response.body.should.equal 'Goodbye World' response.body.should.equal 'Goodbye World'
end 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 end

0 comments on commit 67906d3

Please sign in to comment.