intridea/grape — pull request #495 by asross (2013-10-26 15:29:45+00:00)
Title: fix bug when validating within array parameters

https://github.com/intridea/grape/pull/333 introduced functionality to validate arrays. The case it was tested against is this:

```ruby
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.:

```ruby
params do
group :cat_owners do
requires :name
group :cat do
requires :name
end
end
end
```

You will get a 500 rather than a validation error or success when you try to submit:
```
{
cat_owners: [
{ name: 'Arbuckle', cat: { name: 'Garfield' } },
{ ...more cat owners... }
]
}
```

This pull request fixes that issue (although I'm not entirely happy with how nested the `params` method has gotten) and, more importantly, adds a bunch of tests.