-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Open
Labels
Description
If I mount UsersAPI
under /v1
namespace, this namespace gets propagated into the mounted class.
This causes a problem if same class is mounted more than once.
Reproduce:
# frozen_string_literal: true
require 'bundler/inline'
gemfile(true) do
source 'https://rubygems.org'
gem 'grape'
gem 'rack'
gem 'minitest'
gem 'rack-test'
end
require 'minitest/autorun'
require 'rack/test'
require 'grape'
class GrapeAPIBugTest < Minitest::Test
include Rack::Test::Methods
class UsersAPI < Grape::API
format :json
get "/users" do
present :users, []
end
end
class RootAPI < Grape::API
format :json
namespace "/v1" do
mount UsersAPI
end
end
def test_nested_route_via_root_api
env = Rack::MockRequest.env_for("/v1/users")
status, _, body = RootAPI.call(env)
assert_equal '{"users":[]}', body.join
assert_equal 200, status
end
def test_direct_users_api
env = Rack::MockRequest.env_for("/users")
status, _, body = UsersAPI.call(env)
assert_equal '{"users":[]}', body.join
assert_equal 200, status
end
end