Skip to content

Commit

Permalink
Fix #383: Inherit settings correctly when performing nested mounts
Browse files Browse the repository at this point in the history
  • Loading branch information
seanmoon committed May 30, 2013
1 parent dce96e1 commit 78ee4fe
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Next Release
* [#407](https://github.com/intridea/grape/issues/407): Specifying `default_format` will also set the default POST/PUT data parser to the given format - [@dblock](https://github.com/dblock).
* [#241](https://github.com/intridea/grape/issues/241): Present with multiple entities using an optional Symbol - [@niedhui](https://github.com/niedhui).
* [#412](https://github.com/intridea/grape/issues/412): Fix: specifying `content_type` will also override the selection of the data formatter - [@dblock](https://github.com/dblock).
* [#383](https://github.com/intridea/grape/issues/383): Fix: Mounted APIs not inheriting settings (such as before/after filters) properly [@seanmoon](https://github.com/seanmoon).
* Your contribution here.

0.4.1 (4/1/2013)
Expand Down
5 changes: 4 additions & 1 deletion lib/grape/api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,10 @@ def inherited(subclass)

def inherit_settings(other_stack)
settings.prepend other_stack
endpoints.each{|e| e.settings.prepend(other_stack)}
endpoints.each do |e|
e.settings.prepend(other_stack)
e.options[:app].inherit_settings(other_stack) if e.options[:app].respond_to?(:inherit_settings, true)
end
end
end

Expand Down
18 changes: 18 additions & 0 deletions spec/grape/api_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1720,6 +1720,24 @@ 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 78ee4fe

Please sign in to comment.