Skip to content

Commit 41cd761

Browse files
nicolashopinbasjanssen
authored andcommitted
Fixes issue by checking if there's a base is there at all (ruby-grape#1946)
1 parent aaccdb1 commit 41cd761

File tree

3 files changed

+50
-2
lines changed

3 files changed

+50
-2
lines changed

CHANGELOG.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
#### Fixes
1515

16-
* Your contribution here.
16+
* [#1931](https://github.com/ruby-grape/grape/pull/1946): Fixes issue when using namespaces in `Grape::API::Instance` mounted directly - [@myxoh](https://github.com/myxoh).
1717

1818
### 1.2.5 (2019/12/01)
1919

lib/grape/api/instance.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ def evaluate_as_instance_with_configuration(block, lazy: false)
121121
self.configuration = value_for_configuration
122122
response
123123
end
124-
if base_instance? && lazy
124+
if base && base_instance? && lazy
125125
lazy_block
126126
else
127127
lazy_block.evaluate_from(configuration)

spec/grape/api/instance_spec.rb

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# frozen_string_literal: true
2+
3+
require 'spec_helper'
4+
require 'shared/versioning_examples'
5+
6+
describe Grape::API::Instance do
7+
subject(:an_instance) do
8+
Class.new(Grape::API::Instance) do
9+
namespace :some_namespace do
10+
get 'some_endpoint' do
11+
'success'
12+
end
13+
end
14+
end
15+
end
16+
17+
let(:root_api) do
18+
to_mount = an_instance
19+
Class.new(Grape::API) do
20+
mount to_mount
21+
end
22+
end
23+
24+
def app
25+
root_api
26+
end
27+
28+
context 'when an instance is mounted on the root' do
29+
it 'can call the instance endpoint' do
30+
get '/some_namespace/some_endpoint'
31+
expect(last_response.body).to eq 'success'
32+
end
33+
end
34+
35+
context 'when an instance is the root' do
36+
let(:root_api) do
37+
to_mount = an_instance
38+
Class.new(Grape::API::Instance) do
39+
mount to_mount
40+
end
41+
end
42+
43+
it 'can call the instance endpoint' do
44+
get '/some_namespace/some_endpoint'
45+
expect(last_response.body).to eq 'success'
46+
end
47+
end
48+
end

0 commit comments

Comments
 (0)