Skip to content

Commit

Permalink
Fixes issue by checking if there's a base is there at all (#1946)
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolashopin authored and dblock committed Dec 17, 2019
1 parent d30b780 commit c7f0ac2
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 2 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

#### Fixes

* Your contribution here.
* [#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).

### 1.2.5 (2019/12/01)

Expand Down
2 changes: 1 addition & 1 deletion lib/grape/api/instance.rb
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def evaluate_as_instance_with_configuration(block, lazy: false)
self.configuration = value_for_configuration
response
end
if base_instance? && lazy
if base && base_instance? && lazy
lazy_block
else
lazy_block.evaluate_from(configuration)
Expand Down
48 changes: 48 additions & 0 deletions spec/grape/api/instance_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# frozen_string_literal: true

require 'spec_helper'
require 'shared/versioning_examples'

describe Grape::API::Instance do
subject(:an_instance) do
Class.new(Grape::API::Instance) do
namespace :some_namespace do
get 'some_endpoint' do
'success'
end
end
end
end

let(:root_api) do
to_mount = an_instance
Class.new(Grape::API) do
mount to_mount
end
end

def app
root_api
end

context 'when an instance is mounted on the root' do
it 'can call the instance endpoint' do
get '/some_namespace/some_endpoint'
expect(last_response.body).to eq 'success'
end
end

context 'when an instance is the root' do
let(:root_api) do
to_mount = an_instance
Class.new(Grape::API::Instance) do
mount to_mount
end
end

it 'can call the instance endpoint' do
get '/some_namespace/some_endpoint'
expect(last_response.body).to eq 'success'
end
end
end

0 comments on commit c7f0ac2

Please # to comment.