Skip to content

Commit 63a03e5

Browse files
authored
Spec and fix for #1721. (#1722)
* Failing spec for #1721. * Fix for #1721 - Defining a catch-all after multiple versions of an endpoint hide endpoints after the first definition * De-duplicate router logic. * Fix: build, remove bundler update.
1 parent 95484d5 commit 63a03e5

File tree

4 files changed

+61
-3
lines changed

4 files changed

+61
-3
lines changed

.travis.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,3 @@ matrix:
5656
- rvm: rbx-3
5757

5858
bundler_args: --without development
59-
60-
before_install: gem update --system
61-

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#### Fixes
1111

1212
* [#1710](https://github.com/ruby-grape/grape/pull/1710): Fix wrong transformation of empty Array in declared params - [@pablonahuelgomez](https://github.com/pablonahuelgomez).
13+
* [#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).
1314
* Your contribution here.
1415

1516
### 1.0.1 (9/8/2017)

lib/grape/router.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,8 @@ def transaction(env)
104104
) if neighbor && method == 'OPTIONS' && !cascade
105105

106106
route = match?(input, '*')
107+
return neighbor.endpoint.call(env) if neighbor && cascade && route
108+
107109
if route
108110
response = process_route(route, env)
109111
return response if response && !(cascade = cascade?(response))

spec/shared/versioning_examples.rb

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,4 +149,62 @@
149149
versioned_get '/api_version_with_version_param?version=1', 'v1', macro_options
150150
expect(last_response.body).to eql '1'
151151
end
152+
153+
context 'with catch-all' do
154+
let(:options) { macro_options }
155+
let(:v1) do
156+
klass = Class.new(Grape::API)
157+
klass.version 'v1', options
158+
klass.get 'version' do
159+
'v1'
160+
end
161+
klass
162+
end
163+
let(:v2) do
164+
klass = Class.new(Grape::API)
165+
klass.version 'v2', options
166+
klass.get 'version' do
167+
'v2'
168+
end
169+
klass
170+
end
171+
before do
172+
subject.format :txt
173+
174+
subject.mount v1
175+
subject.mount v2
176+
177+
subject.route :any, '*path' do
178+
params[:path]
179+
end
180+
end
181+
182+
context 'v1' do
183+
it 'finds endpoint' do
184+
versioned_get '/version', 'v1', macro_options
185+
expect(last_response.status).to eq(200)
186+
expect(last_response.body).to eq('v1')
187+
end
188+
189+
it 'finds catch all' do
190+
versioned_get '/whatever', 'v1', macro_options
191+
expect(last_response.status).to eq(200)
192+
expect(last_response.body).to end_with 'whatever'
193+
end
194+
end
195+
196+
context 'v2' do
197+
it 'finds endpoint' do
198+
versioned_get '/version', 'v2', macro_options
199+
expect(last_response.status).to eq(200)
200+
expect(last_response.body).to eq('v2')
201+
end
202+
203+
it 'finds catch all' do
204+
versioned_get '/whatever', 'v2', macro_options
205+
expect(last_response.status).to eq(200)
206+
expect(last_response.body).to end_with 'whatever'
207+
end
208+
end
209+
end
152210
end

0 commit comments

Comments
 (0)