Skip to content

Commit

Permalink
Fix: #394 - Path version no longer overwrites a parameter.
Browse files Browse the repository at this point in the history
  • Loading branch information
Tom Mornini authored and dblock committed Apr 29, 2013
1 parent 833fbc0 commit c065f33
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Next Release
* [#376](https://github.com/intridea/grape/pull/376): Added `route_param`, syntax sugar for quick declaration of route parameters - [@mbleigh](https://github.com/mbleigh).
* [#347](https://github.com/intridea/grape/issues/347): Fix: handling non-hash body params - [@paulnicholon](https://github.com/paulnicholson).
* [#392](https://github.com/intridea/grape/pull/392): Extracedt headers and params from `Endpoint` to `Grape::Request` - [@niedhui](https://github.com/niedhui).
* [#394](https://github.com/intridea/grape/pull/394): Path version no longer overwrites a `version` parameter - [@tmornini](https://github.com/tmornini).
* Your contribution here.

0.4.1 (4/1/2013)
Expand Down
13 changes: 10 additions & 3 deletions lib/grape/http/request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,16 @@ module Grape
class Request < Rack::Request

def params
@env['grape.request.params'] ||= Hashie::Mash.new.
deep_merge(super).
deep_merge(env['rack.routing_args'] || {})
@env['grape.request.params'] ||= begin
params = Hashie::Mash.new(super)
if env['rack.routing_args']
args = env['rack.routing_args'].dup
# preserve version from query string parameters
args.delete(:version)
params.deep_merge!(args)
end
params
end
end

def headers
Expand Down
14 changes: 13 additions & 1 deletion spec/shared/versioning_examples.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

it 'adds the prefix before the API version' do
subject.format :txt
subject.prefix 'api'
subject.prefix 'api'
subject.version 'v1', macro_options
subject.get :hello do
"Version: #{request.env['api.version']}"
Expand Down Expand Up @@ -106,4 +106,16 @@
end
end
end

it 'does not overwrite version parameter with API version' do
subject.format :txt
subject.version 'v1', macro_options
subject.params { requires :version }
subject.get :api_version_with_version_param do
params[:version]
end
versioned_get '/api_version_with_version_param?version=1', 'v1', macro_options
last_response.body.should eql '1'
end

end

0 comments on commit c065f33

Please sign in to comment.