Skip to content

Commit

Permalink
Fix multi-method routes to append '(.:format)' only once
Browse files Browse the repository at this point in the history
Because the same path string is used for each loop when the routes
are being built, appending the string using `<<` modifies the original,
causing multiple '(.:format)' strings to be appended. This fixes the
behavior, resulting in the proper path output.

Signed-off-by: Evan Owen <kainosnoema@gmail.com>
  • Loading branch information
kainosnoema committed Jun 25, 2012
1 parent f8d280b commit 544f3b5
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
3 changes: 1 addition & 2 deletions lib/grape/endpoint.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,7 @@ def prepare_path(path)
parts << ':version' if settings[:version] && settings[:version_options][:using] == :path
parts << namespace.to_s if namespace
parts << path.to_s if path && '/' != path
parts.last << '(.:format)'
Rack::Mount::Utils.normalize_path(parts.join('/'))
Rack::Mount::Utils.normalize_path(parts.join('/') + '(.:format)')
end

def namespace
Expand Down
4 changes: 4 additions & 0 deletions spec/grape/api_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,10 @@ def app; subject end
"hiya"
end

subject.endpoints.first.routes.each do |route|
route.route_path.should eql '/abc(.:format)'
end

get '/abc'
last_response.body.should eql 'hiya'
post '/abc'
Expand Down

0 comments on commit 544f3b5

Please sign in to comment.