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

Calling declared(params) from child namespace fails to include parent namespace defined params #503

Closed
wants to merge 7 commits into from
Closed
Changes from 1 commit
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
29 changes: 29 additions & 0 deletions spec/grape/endpoint_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,35 @@ def app
end
end

describe '#declared; call from child namespace' do
it 'should include params defined in the parent namespace' do
subject.namespace :something do
params do
requires :id, type: Integer
end
resource ':id' do
params do
requires :foo
optional :bar
end
get do
params[:id].should == 123
params[:foo].should == 'test'
params[:extra].should == 'hello'

declared(params).key?(:foo).should == true
declared(params).key?(:bar).should == true
declared(params).key?(:id).should == true
""
end
end
end

get '/something/123', foo: 'test', extra: 'hello'
last_response.status.should == 200
end
end

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is certainly a good way to write a test, but generally I'm trying to put test conditions in the test itself. Mind rewriting it with say something like this:

get do
 {
    params: params,
    declared_params: declared(params)
 }.as_json
end

...

get ...
json = JSON.parse(last_response)
json[:params][:id].should == 123
json[:declared_params].keys.should include :foo # rather than == true, or at least use be_true

Thanks.

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