diff options
| author | Gibheer <gibheer@gmail.com> | 2012-11-29 20:02:28 +0100 | 
|---|---|---|
| committer | Gibheer <gibheer@gmail.com> | 2012-11-29 20:02:28 +0100 | 
| commit | c6623d47df647cfd719d1b1d64d056184d55d080 (patch) | |
| tree | 021edbbd45a383ca199478e41ea386429ab31cfd | |
| parent | 849a6f34ca0ddf93cbbc0a2c95c9c93917545730 (diff) | |
added custom parameters in the router
| -rw-r--r-- | lib/zero/router.rb | 2 | ||||
| -rw-r--r-- | spec/unit/router/call_spec.rb | 23 | 
2 files changed, 19 insertions, 6 deletions
| diff --git a/lib/zero/router.rb b/lib/zero/router.rb index befb171..9ec3b4b 100644 --- a/lib/zero/router.rb +++ b/lib/zero/router.rb @@ -52,7 +52,7 @@ module Zero          match = route.match(request.path)          if match            match.names.each_index do |i| -            request.update_param(match.names[i], match.captures[i]) +            request.params[match.names[i]] = match.captures[i]            end            return target.call(request.env)          end diff --git a/spec/unit/router/call_spec.rb b/spec/unit/router/call_spec.rb index c242dbd..b7cf315 100644 --- a/spec/unit/router/call_spec.rb +++ b/spec/unit/router/call_spec.rb @@ -9,34 +9,47 @@ describe Zero::Router, '#call' do    end    let(:app) { SpecApp } -  shared_examples_for "a sample app" do +  shared_examples_for 'a sample app' do      it "returns a response" do        subject.call(env).to_a[2].should eq(result)      end    end -  context "with a single route" do +  context 'with a single route' do      let(:routes) {{ '/' => app }}      let(:env) { EnvGenerator.get('/') }      it_behaves_like "a sample app"    end -  context "with multiple routes" do +  context 'with multiple router' do      let(:routes) {{ '/foo' => app, '/wrong' => wrong_app }}      let(:env) { EnvGenerator.get('/foo') }      it_behaves_like "a sample app"    end -  context "with nested routes" do +  context 'with nested routes' do      let(:routes) {{ '/' => wrong_app, '/foo' => app, '/foo/bar' => wrong_app }}      let(:env) { EnvGenerator.get('/foo') }      it_behaves_like "a sample app"    end -  context "with a route not found" do +  context 'with a route not found' do      let(:routes) {{ '/foo' => wrong_app, '/foo/bar/baz' => app }}      let(:env) { EnvGenerator.get('/foo/bar') }      let(:result) { ['Not found!'] }      it_behaves_like "a sample app"    end + +  context 'with parameters' do +    let(:routes) {{ '/foo/:id' => app }} +    let(:env) { EnvGenerator.get('/foo/bar') } +    let(:app) do +      lambda do |env| +        [200, {}, [Zero::Request.create(env).params['id']]] +      end +    end +    let(:result) { ['bar'] } + +    it_behaves_like 'a sample app' +  end  end | 
