Skip to content

Commit

Permalink
Fix #196: root requests don't work with prefix.
Browse files Browse the repository at this point in the history
  • Loading branch information
dblock committed Jan 5, 2013
1 parent e0d48ad commit 25f8ec0
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* [#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).
* [#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).
* Your contribution here.

0.2.3 (24/12/2012)
Expand Down
5 changes: 3 additions & 2 deletions lib/grape/endpoint.rb
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def prepare_routes

def prepare_path(path)
parts = []
parts << settings[:root_prefix] if settings[:root_prefix]
parts << settings[:root_prefix].to_s.split("/") if settings[:root_prefix]

uses_path_versioning = settings[:version] && settings[:version_options][:using] == :path
namespace_is_empty = namespace && (namespace.to_s =~ /^\s*$/ || namespace.to_s == '/')
Expand All @@ -119,11 +119,12 @@ def prepare_path(path)
parts << ':version' if uses_path_versioning
if !uses_path_versioning || (!namespace_is_empty || !path_is_empty)
parts << namespace.to_s if namespace
parts << path.to_s if path && '/' != path
parts << path.to_s if path
format_suffix = '(.:format)'
else
format_suffix = '(/.:format)'
end
parts = parts.flatten.select { |part| part != '/' }
Rack::Mount::Utils.normalize_path(parts.join('/') + format_suffix)
end

Expand Down
12 changes: 12 additions & 0 deletions spec/grape/api_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,17 @@
def app; subject end

describe '.prefix' do

it 'routes root through with the prefix' do
subject.prefix 'awesome/sauce'
subject.get do
"Hello there."
end

get 'awesome/sauce/'
last_response.body.should eql "Hello there."
end

it 'routes through with the prefix' do
subject.prefix 'awesome/sauce'
subject.get :hello do
Expand All @@ -19,6 +30,7 @@ def app; subject end
get '/hello'
last_response.status.should eql 404
end

end

describe '.version' do
Expand Down

0 comments on commit 25f8ec0

Please sign in to comment.