Skip to content
This repository has been archived by the owner on Mar 9, 2023. It is now read-only.

Commit

Permalink
Fix ruby-grape#383: Inherit settings correctly when performing nested…
Browse files Browse the repository at this point in the history
… mounts
  • Loading branch information
seanmoon committed May 29, 2013
1 parent dce96e1 commit 425b97d
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
7 changes: 7 additions & 0 deletions lib/grape/api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
17 changes: 17 additions & 0 deletions spec/grape/api_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 425b97d

Please sign in to comment.