Skip to content

Commit

Permalink
Fix: header-based versioning with use of prefix.
Browse files Browse the repository at this point in the history
  • Loading branch information
dblock committed Jan 5, 2013
1 parent 3c1e695 commit 548ceb4
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
* [#302](/~https://github.com/intridea/grape/pull/302): Fix: removed redundant `autoload` entries - [@ugisozols](/~https://github.com/ugisozols).
* [#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).
* Your contribution here.

0.2.3 (24/12/2012)
Expand Down
2 changes: 1 addition & 1 deletion lib/grape/endpoint.rb
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ def build_middleware

b.use Rack::Auth::Basic, settings[:auth][:realm], &settings[:auth][:proc] if settings[:auth] && settings[:auth][:type] == :http_basic
b.use Rack::Auth::Digest::MD5, settings[:auth][:realm], settings[:auth][:opaque], &settings[:auth][:proc] if settings[:auth] && settings[:auth][:type] == :http_digest
b.use Grape::Middleware::Prefixer, :prefix => settings[:root_prefix] if settings[:root_prefix]
b.use Grape::Middleware::Prefixer, :prefix => settings[:root_prefix] if settings[:root_prefix] && settings[:version] && settings[:version_options][:using] == :path

if settings[:version]
b.use Grape::Middleware::Versioner.using(settings[:version_options][:using]), {
Expand Down
1 change: 0 additions & 1 deletion spec/grape/api_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ def app; subject end
end
end
end

describe '.version using param' do
it_should_behave_like 'versioning' do
let(:macro_options) do
Expand Down
11 changes: 6 additions & 5 deletions spec/shared/versioning_examples.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
end

context 'with a prefix' do
it 'allows the same endpoint to be implemented' do
it 'allows the same endpoint to be implemented' do
subject.prefix 'api'
subject.version 'v2', macro_options
subject.get 'version' do
Expand All @@ -92,12 +92,13 @@
end
end

versioned_get '/api/version', 'v2', macro_options
last_response.status.should == 200
last_response.body.should == 'v2'
versioned_get '/api/version', 'v1', macro_options
versioned_get '/version', 'v1', macro_options.merge(:prefix => subject.prefix)
last_response.status.should == 200
last_response.body.should == 'version v1'

versioned_get '/version', 'v2', macro_options.merge(:prefix => subject.prefix)
last_response.status.should == 200
last_response.body.should == 'v2'
end
end
end
Expand Down

0 comments on commit 548ceb4

Please sign in to comment.