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

Add support for scoped parameters in extra_params #96

Closed
jsmestad opened this issue Oct 8, 2013 · 2 comments
Closed

Add support for scoped parameters in extra_params #96

jsmestad opened this issue Oct 8, 2013 · 2 comments

Comments

@jsmestad
Copy link
Contributor

jsmestad commented Oct 8, 2013

Background

Testing for missing values on a PUT request, it would be nice to have the following supported via extra_params with a example_request.

put '/users' do
  parameter :first_name, 'Users first name', scope: :user
  parameter :last_name, 'Users last name', scope: :user

  example_request 'with attributes', user: { first_name: 'John' } do
    status.should == 200
  end

  example_request 'without set attributes' do
    status.should == 422
  end
end

Currently this function is not "additive" but instead it overrides the entire user key with a new value. I am not sure if you want to use a different DSL for doing this sort of operation (like allowing some form of lets inside example_request blocks or a different syntax for specifying additive versus overwriting parameters).

Let me know what approach you'd like, as I am eager to contribute back to this awesome project!

@oestrich
Copy link
Contributor

So this should work but might not work how you expect.

put '/users' do
  parameter :first_name, 'Users first name', scope: :user
  parameter :last_name, 'Users last name', scope: :user

  example_request 'with attributes', first_name: 'John' do
    # first name will be scoped inside user by #params
    params.should == { :user => { :first_name => 'John' } }
    status.should == 200
  end
end

If we can think of a way to make this more how you would expect it to work I'd definitely accept it.

@oestrich
Copy link
Contributor

Closing because I think this was fixed with #182

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants