From 544f3b57c955275c4e452d62e8a410584c9560f4 Mon Sep 17 00:00:00 2001 From: Evan Owen Date: Mon, 25 Jun 2012 16:43:28 -0700 Subject: [PATCH 1/2] Fix multi-method routes to append '(.:format)' only once 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 --- lib/grape/endpoint.rb | 3 +-- spec/grape/api_spec.rb | 4 ++++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/grape/endpoint.rb b/lib/grape/endpoint.rb index cbd318f458..3ec4ad3eb0 100644 --- a/lib/grape/endpoint.rb +++ b/lib/grape/endpoint.rb @@ -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 diff --git a/spec/grape/api_spec.rb b/spec/grape/api_spec.rb index 486b4b6ef4..78e9bc0f02 100644 --- a/spec/grape/api_spec.rb +++ b/spec/grape/api_spec.rb @@ -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' From 74feb879fc17aa63613f500e8b86b87fd72f9f53 Mon Sep 17 00:00:00 2001 From: Evan Owen Date: Tue, 26 Jun 2012 10:27:39 -0700 Subject: [PATCH 2/2] Added #188 to CHANGELOG --- CHANGELOG.markdown | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.markdown b/CHANGELOG.markdown index e17c4a01ad..6c9ab82e73 100644 --- a/CHANGELOG.markdown +++ b/CHANGELOG.markdown @@ -1,6 +1,7 @@ Next Release ============ +* [#188](https://github.com/intridea/grape/pull/188): Fix: multi-method routes should append '(.:format)' only once - [@kainosnoema](https://github.com/kainosnoema). * [#64](https://github.com/intridea/grape/issues/64), [#180](https://github.com/intridea/grape/pull/180): Added support to get request bodies as parameters - [@bobbytables](https://github.com/bobbytables). * [#175](https://github.com/intridea/grape/pull/175): Added support for API versioning based on a request parameter - [@jackcasey](https://github.com/jackcasey). * [#168](https://github.com/intridea/grape/pull/168): Fix: Formatter can parse symbol keys in the headers hash - [@netmask](https://github.com/netmask).