Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Spec and fix for #1721. #1722

Merged
merged 5 commits into from
Dec 21, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,3 @@ matrix:
- rvm: rbx-3

bundler_args: --without development

before_install: gem update --system

1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#### Fixes

* [#1710](https://github.com/ruby-grape/grape/pull/1710): Fix wrong transformation of empty Array in declared params - [@pablonahuelgomez](https://github.com/pablonahuelgomez).
* [#1722](https://github.com/ruby-grape/grape/pull/1722): Fix catch-all hiding multiple versions of an endpoint after the first definition - [@zherr](https://github.com/zherr).
* Your contribution here.

### 1.0.1 (9/8/2017)
Expand Down
2 changes: 2 additions & 0 deletions lib/grape/router.rb
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ def transaction(env)
) if neighbor && method == 'OPTIONS' && !cascade

route = match?(input, '*')
return neighbor.endpoint.call(env) if neighbor && cascade && route

if route
response = process_route(route, env)
return response if response && !(cascade = cascade?(response))
Expand Down
58 changes: 58 additions & 0 deletions spec/shared/versioning_examples.rb
Original file line number Diff line number Diff line change
Expand Up @@ -149,4 +149,62 @@
versioned_get '/api_version_with_version_param?version=1', 'v1', macro_options
expect(last_response.body).to eql '1'
end

context 'with catch-all' do
let(:options) { macro_options }
let(:v1) do
klass = Class.new(Grape::API)
klass.version 'v1', options
klass.get 'version' do
'v1'
end
klass
end
let(:v2) do
klass = Class.new(Grape::API)
klass.version 'v2', options
klass.get 'version' do
'v2'
end
klass
end
before do
subject.format :txt

subject.mount v1
subject.mount v2

subject.route :any, '*path' do
params[:path]
end
end

context 'v1' do
it 'finds endpoint' do
versioned_get '/version', 'v1', macro_options
expect(last_response.status).to eq(200)
expect(last_response.body).to eq('v1')
end

it 'finds catch all' do
versioned_get '/whatever', 'v1', macro_options
expect(last_response.status).to eq(200)
expect(last_response.body).to end_with 'whatever'
end
end

context 'v2' do
it 'finds endpoint' do
versioned_get '/version', 'v2', macro_options
expect(last_response.status).to eq(200)
expect(last_response.body).to eq('v2')
end

it 'finds catch all' do
versioned_get '/whatever', 'v2', macro_options
expect(last_response.status).to eq(200)
expect(last_response.body).to end_with 'whatever'
end
end
end
end