aboutsummaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorGibheer <gibheer@gmail.com>2013-09-09 15:45:59 +0200
committerGibheer <gibheer@gmail.com>2013-09-09 15:45:59 +0200
commitdefb7703c69d1e4f756254723d50997fb8dc63da (patch)
tree80f05c0b34c5a2c0ecf75111970e6505f8c72694 /spec
parentc55441f99065d1ff9efeb7d46f5e5c14b0b3232a (diff)
sort routes for more specific results
This change sorts the routes to get the most specific routes first and avoid hitting a route which is not the most specific match. With this the regex to extract variables is made more strict to avoid matching half of the URI.
Diffstat (limited to 'spec')
-rw-r--r--spec/unit/zero/router/call_spec.rb31
1 files changed, 31 insertions, 0 deletions
diff --git a/spec/unit/zero/router/call_spec.rb b/spec/unit/zero/router/call_spec.rb
index 683eca8..923b747 100644
--- a/spec/unit/zero/router/call_spec.rb
+++ b/spec/unit/zero/router/call_spec.rb
@@ -44,6 +44,22 @@ describe Zero::Router, '#call' do
it_behaves_like "a sample app"
end
+ context 'with nested variable routes' do
+ let(:routes) do
+ { '/' => wrong_app, '/foo/:id' => app, '/foo/:id/bar' => wrong_app }
+ end
+ let(:env) { EnvGenerator.get('/foo/23') }
+ it_behaves_like "a sample app"
+ end
+
+ context 'with nested routes and variable in the middle' do
+ let(:routes) do
+ { '/' => wrong_app, '/foo/:id' => wrong_app, '/foo/:id/bar' => app }
+ end
+ let(:env) { EnvGenerator.get('/foo/23/bar') }
+ it_behaves_like "a sample app"
+ end
+
context 'with a route not found' do
let(:routes) {{ '/foo' => wrong_app, '/foo/bar/baz' => app }}
let(:env) { EnvGenerator.get('/foo/bar') }
@@ -72,4 +88,19 @@ describe Zero::Router, '#call' do
it_behaves_like 'a sample app'
end
+
+ context 'with parameters and nested routes' do
+ let(:routes) do
+ { '/' => wrong_app, '/foo/:id' => app, '/foo/:id/bar' => wrong_app }
+ end
+ let(:env) { EnvGenerator.get('/foo/bar') }
+ let(:app) do
+ lambda do |env|
+ [200, content_type, [Zero::Request.new(env).params['id']]]
+ end
+ end
+ let(:result) { ['bar'] }
+
+ it_behaves_like "a sample app"
+ end
end