Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nested mount points don't inherit parent declared params #1050

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions spec/grape/endpoint_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,43 @@ def app
end
end

describe '#declared; from a nested mounted endpoint' do
before do
mounted = Class.new(Grape::API)
mounted.namespace :another do
params do
requires :mount_space, type: Integer
end
route_param :mount_space do
get do
{
params: params,
declared_params: declared(params)
}
end
end
end

subject.format :json
subject.namespace :something do
params do
requires :id, type: Integer
end
resource ':id' do
mount mounted
end
end
end

it 'can access parent attributes' do
get '/something/123/another/456'
expect(last_response.status).to eq 200
json = JSON.parse(last_response.body, symbolize_names: true)
expect(json[:declared_params][:id]).to eq 123
expect(json[:declared_params][:mount_space]).to eq 456
end
end

describe '#params' do
it 'is available to the caller' do
subject.get('/hey') do
Expand Down