From b44cd8d2d21f4fac457347f7b1ef8c4fe7416f04 Mon Sep 17 00:00:00 2001 From: dblock Date: Sat, 5 Jan 2013 16:05:48 -0500 Subject: [PATCH] Fix #174: the value of PATH_INFO is no longer modified during request. --- CHANGELOG.markdown | 2 +- lib/grape/middleware/versioner/path.rb | 2 +- spec/grape/endpoint_spec.rb | 28 ++++++++++++++++++++++++++ 3 files changed, 30 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.markdown b/CHANGELOG.markdown index ab90c189a2..a4b7d4a7a2 100644 --- a/CHANGELOG.markdown +++ b/CHANGELOG.markdown @@ -12,7 +12,7 @@ * [#172](https://github.com/intridea/grape/issues/172): Fix: MultiJson deprecated methods warnings - [@dblock](https://github.com/dblock). * [#293](https://github.com/intridea/grape/pull/293): Added options to `cookies.delete`, enables passing a path - [@inst](https://github.com/inst). * [#133](https://github.com/intridea/grape/issues/133): Fix: header-based versioning with use of `prefix` - [@seanmoon](https://github.com/seanmoon), [@dblock](https://github.com/dblock). -* [#133](https://github.com/intridea/grape/issues/133): The value of `env['PATH_INFO']` is no longer altered with `path` versioning - [@dblock](https://github.com/dblock). +* [#174](https://github.com/intridea/grape/issues/174): The value of `env['PATH_INFO']` is no longer altered with `path` versioning - [@dblock](https://github.com/dblock). * [#280](https://github.com/intridea/grape/issues/280): Fix: grouped parameters mangled in `route_params` hash - [@marcusg](https://github.com/marcusg), [@dblock](https://github.com/dblock). * [#304](https://github.com/intridea/grape/issues/304): Fix: `present x, :with => Entity` returns class references with `format :json` - [@dblock](https://github.com/dblock). * [#196](https://github.com/intridea/grape/issues/196): Fix: root requests don't work with `prefix` - [@dblock](https://github.com/dblock). diff --git a/lib/grape/middleware/versioner/path.rb b/lib/grape/middleware/versioner/path.rb index 939100c81d..a5739ae70f 100644 --- a/lib/grape/middleware/versioner/path.rb +++ b/lib/grape/middleware/versioner/path.rb @@ -24,7 +24,7 @@ def default_options end def before - path = env['PATH_INFO'] + path = env['PATH_INFO'].dup if prefix && path.index(prefix) == 0 path.sub!(prefix, '') diff --git a/spec/grape/endpoint_spec.rb b/spec/grape/endpoint_spec.rb index 596f7d83d1..340263bca4 100644 --- a/spec/grape/endpoint_spec.rb +++ b/spec/grape/endpoint_spec.rb @@ -579,4 +579,32 @@ def initialize(id) end end end + + context 'request' do + it 'should be set to the url requested' do + subject.get('/url') do + request.url + end + get '/url' + last_response.body.should == "http://example.org/url" + end + it 'should include version' do + subject.version 'v1', :using => :path + subject.get('/url') do + request.url + end + get '/v1/url' + last_response.body.should == "http://example.org/v1/url" + end + it 'should include prefix' do + subject.version 'v1', :using => :path + subject.prefix 'api' + subject.get('/url') do + request.url + end + get '/api/v1/url' + last_response.body.should == "http://example.org/api/v1/url" + end + end + end