Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

A route can be redfined

This may need some clean-up
  • Loading branch information...
commit 67906d391dae0336f6bcfff3550d67934986e59b 1 parent 641965b
Blake Mizerany bmizerany authored
Showing with 25 additions and 0 deletions.
  1. +2 −0  lib/sinatra/base.rb
  2. +23 −0 test/base_test.rb
2  lib/sinatra/base.rb
View
@@ -554,6 +554,8 @@ def route(method, path, opts={}, &block)
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)
23 test/base_test.rb
View
@@ -46,4 +46,27 @@
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
Please sign in to comment.
Something went wrong with that request. Please try again.