From 0f8111eba4e4e5380f8163261346b32cd0aa7a01 Mon Sep 17 00:00:00 2001 From: Nicolas Date: Tue, 17 Dec 2019 18:56:25 +0000 Subject: [PATCH 1/3] Fixes issue by checking that a base is there at all --- lib/grape/api/instance.rb | 2 +- spec/grape/api/instance_spec.rb | 48 +++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 spec/grape/api/instance_spec.rb diff --git a/lib/grape/api/instance.rb b/lib/grape/api/instance.rb index 8efa5568a4..03358fd791 100644 --- a/lib/grape/api/instance.rb +++ b/lib/grape/api/instance.rb @@ -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) diff --git a/spec/grape/api/instance_spec.rb b/spec/grape/api/instance_spec.rb new file mode 100644 index 0000000000..6de77c51e1 --- /dev/null +++ b/spec/grape/api/instance_spec.rb @@ -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 From a4505dacd3e8e5c3eddeaa442b854f888d06997c Mon Sep 17 00:00:00 2001 From: Nicolas Date: Tue, 17 Dec 2019 19:00:33 +0000 Subject: [PATCH 2/3] Adds changelog explaining fix --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d9f353a234..ee85e118b1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) From b22edfc055e963a0ad68fac11b23d188e876eb0b Mon Sep 17 00:00:00 2001 From: Nicolas Date: Tue, 17 Dec 2019 19:35:01 +0000 Subject: [PATCH 3/3] Fixes changelog --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ee85e118b1..95b77a5dd7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,7 +13,7 @@ #### Fixes -* [#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) +* [#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)