From 425b97d0547f8ac00e10dc64ced648edd4217609 Mon Sep 17 00:00:00 2001 From: Sean Moon Date: Wed, 29 May 2013 18:18:42 +0900 Subject: [PATCH] Fix #383: Inherit settings correctly when performing nested mounts --- lib/grape/api.rb | 7 +++++++ spec/grape/api_spec.rb | 17 +++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/lib/grape/api.rb b/lib/grape/api.rb index bd6164a029..f129be6cb3 100644 --- a/lib/grape/api.rb +++ b/lib/grape/api.rb @@ -304,6 +304,13 @@ def mount(mounts) app_settings.set :mount_path, mount_path app.inherit_settings(app_settings) end + if app.respond_to?(:endpoints, true) # nested mounts + app.endpoints.each do |endpoint| + if endpoint.options[:app].respond_to?(:inherit_settings, true) + endpoint.options[:app].inherit_settings(settings.clone) + end + end + end endpoints << Grape::Endpoint.new(settings.clone, { :method => :any, :path => path, diff --git a/spec/grape/api_spec.rb b/spec/grape/api_spec.rb index 1e56d98738..46329fe537 100644 --- a/spec/grape/api_spec.rb +++ b/spec/grape/api_spec.rb @@ -1720,6 +1720,23 @@ def self.call(object, env) last_response.body.should == 'yo' end + it 'applies the settings to nested mounted apis' do + subject.version 'v1', :using => :path + + subject.namespace :cool do + inner_app = Class.new(Grape::API) + inner_app.get('/awesome') do + "yo" + end + app = Class.new(Grape::API) + app.mount inner_app + mount app + end + + get '/v1/cool/awesome' + last_response.body.should == 'yo' + end + it 'inherits rescues even when some defined by mounted' do subject.rescue_from :all do |e| rack_response("rescued from #{e.message}", 202)