File tree Expand file tree Collapse file tree 2 files changed +52
-1
lines changed
Expand file tree Collapse file tree 2 files changed +52
-1
lines changed Original file line number Diff line number Diff line change @@ -188,6 +188,11 @@ def http_digest(options = {}, &block)
188188 def mount ( mounts )
189189 mounts . each_pair do |app , path |
190190 next unless app . respond_to? ( :call )
191+
192+ if app . is_a? ( Class ) && app < Grape ::API
193+ app . inherit ( settings_stack )
194+ end
195+
191196 route_set . add_route ( app ,
192197 path_info : compile_path ( path , false )
193198 )
@@ -357,7 +362,12 @@ def build_endpoint(&block)
357362 def inherited ( subclass )
358363 subclass . reset!
359364 end
360-
365+
366+ def inherit ( other_stack )
367+ settings_stack . unshift *other_stack
368+ raise settings_stack . inspect
369+ end
370+
361371 def route_set
362372 @route_set ||= Rack ::Mount ::RouteSet . new
363373 end
Original file line number Diff line number Diff line change @@ -778,5 +778,46 @@ class CommunicationError < RuntimeError; end
778778 last_response . body . should == 'MOUNTED'
779779 end
780780 end
781+
782+ context 'with another Grape API' do
783+ class ExampleProtectedAPI < Grape ::API
784+ get '/protected' do
785+ "YOU'RE IN!"
786+ end
787+ end
788+
789+ class ExampleV1API < Grape ::API
790+ get "/old" do
791+ "YOU'RE OLD! #{ version } "
792+ end
793+ end
794+
795+ before do
796+ subject . scope :v1 do
797+ version :v1
798+ mount ExampleV1API => '/'
799+ end
800+
801+ subject . scope :authenticated do
802+ before do
803+ error! ( "Not Authorized" , 401 ) unless params [ :authorized ] == 'true'
804+ end
805+ mount ExampleProtectedAPI => '/private'
806+ end
807+ end
808+
809+ it 'should be able to access the old API namespaced properly' do
810+ get '/v1/old'
811+ last_response . body . should == "YOU'RE OLD! v1"
812+ end
813+
814+ it 'should run before filters that are inherited' do
815+ get '/private/protected'
816+ last_response . status . should == 401
817+ get '/private/protected?authorized=true'
818+ last_response . status . should == 200
819+ last_response . body . should == "YOU'RE IN!"
820+ end
821+ end
781822 end
782823end
You can’t perform that action at this time.
0 commit comments