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

fix bug when validating within array parameters #495

Closed
wants to merge 2 commits into from

Conversation

asross
Copy link
Contributor

@asross asross commented Oct 26, 2013

#333 introduced functionality to validate arrays. The case it was tested against is this:

params do
  group :tags do
    requires :name
  end
end

{ tags: [name: "ruby", name: "python"] } will pass validation, and { tags: [foo: "bar"] } will fail with a 400.

However, if you have a more complicated case, where you have new parameter scopes within each element of the array, grape throws an ArgumentError because ParamsScope#params expects to be receiving a hash (and #should_validate? also behaves unexpectedly). E.g.:

params do
  group :cats do
     requires :name
     group :owner do
        requires :name
     end
  end
end

You will get a 500 rather than a validation error or success when you try to submit:

{ 
  cats: [
    { name: 'Garfield', owner: { name: 'Arbuckle' } }, 
    { ...more cats... }
  ]
}

This pull request fixes that issue (although I'm not entirely happy with the deep nesting in #params) and, more importantly, adds a bunch of tests.

@dblock
Copy link
Member

dblock commented Oct 26, 2013

Check Travis, there're a few Rubocop violations (style). Update CHANGELOG. Amend/squash the PR with the changes, please. Thx.

So that `params([{ :foo => :baz }, { :foo => :bat }])` for `@element=:foo` returns `[:baz, :bat]` instead of an ArgumentError.
@dblock
Copy link
Member

dblock commented Oct 28, 2013

Merged via 3ce41ef.

@dblock dblock closed this Oct 28, 2013
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

Successfully merging this pull request may close these issues.

None yet

2 participants