Skip to content

Commit

Permalink
Fix infinite recursive call when mounting endpoint with common ancestor
Browse files Browse the repository at this point in the history
Parent and child classes were pointing to the same inheritable setting
creating an infinite loop when retrieving values.
  • Loading branch information
jkowens committed Jan 4, 2018
1 parent fda88b5 commit 2859ea4
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
8 changes: 4 additions & 4 deletions lib/grape/dsl/settings.rb
Original file line number Diff line number Diff line change
Expand Up @@ -168,10 +168,10 @@ def within_namespace(&_block)
# Builds the current class :inheritable_setting. If available, it returns the superclass's :inheritable_setting.
# Otherwise, a clean :inheritable_setting is returned.
def build_top_level_setting
if defined?(superclass) && superclass.respond_to?(:inheritable_setting) && superclass != Grape::API
superclass.inheritable_setting
else
Grape::Util::InheritableSetting.new
Grape::Util::InheritableSetting.new.tap do |setting|
if defined?(superclass) && superclass.respond_to?(:inheritable_setting) && superclass != Grape::API
setting.inherit_from superclass.inheritable_setting
end
end
end
end
Expand Down
12 changes: 9 additions & 3 deletions spec/grape/loading_spec.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
require 'spec_helper'

describe Grape::API do
let(:jobs_api) do
let(:base_api) do
Class.new(Grape::API) do
format :json
end
end

let(:jobs_api) do
Class.new(base_api) do
namespace :one do
namespace :two do
namespace :three do
Expand All @@ -18,15 +24,15 @@

let(:combined_api) do
JobsApi = jobs_api
Class.new(Grape::API) do
Class.new(base_api) do
version :v1, using: :accept_version_header, cascade: true
mount JobsApi
end
end

subject do
CombinedApi = combined_api
Class.new(Grape::API) do
Class.new(base_api) do
format :json
mount CombinedApi => '/'
end
Expand Down

0 comments on commit 2859ea4

Please sign in to comment.