intridea/grape — pull request #821 by rebelact (2014-11-23 11:05:24+00:00)
Title: fix passing string value when hash is expected

This is a pr based on the findings in #818. Basically if you have

````ruby
params do
requires :user, :type => Hash do
requires :address, allow_blank: false, type: String
end
end

post :hello do
{ "hello" => "world" }
end
````

You can make the following request:

````bash
curl -X POST -H "Content-Type: application/json" -d '{"user":"xyz"}' http://localhost:9292/hello
````

which will lead to the following exception:

````ruby
127.0.0.1 - - "POST /hello HTTP/1.1" 201 17 0.0760
TypeError: no implicit conversion of Symbol into Integer
~/.rvm/gems/ruby-2.1.1/bundler/gems/grape-2302e2644e50/lib/grape/validations/validators/allow_blank.rb:7:in `[]'
~/.rvm/gems/ruby-2.1.1/bundler/gems/grape-2302e2644e50/lib/grape/validations/validators/allow_blank.rb:7:in `validate_param!'
~/.rvm/gems/ruby-2.1.1/bundler/gems/grape-2302e2644e50/lib/grape/validations/validators/base.rb:17:in `block in validate!'
~/.rvm/gems/ruby-2.1.1/bundler/gems/grape-2302e2644e50/lib/grape/validations/attributes_iterator.rb:15:in `block (2 levels) in each'
~/.rvm/gems/ruby-2.1.1/bundler/gems/grape-2302e2644e50/lib/grape/validations/attributes_iterator.rb:14:in `each'
~/.rvm/gems/ruby-2.1.1/bundler/gems/grape-2302e2644e50/lib/grape/validations/attributes_iterator.rb:14:in `block in each'
~/.rvm/gems/ruby-2.1.1/bundler/gems/grape-2302e2644e50/lib/grape/validations/attributes_iterator.rb:13:in `each'
~/.rvm/gems/ruby-2.1.1/bundler/gems/grape-2302e2644e50/lib/grape/validations/attributes_iterator.rb:13:in `each'
~/.rvm/gems/ruby-2.1.1/bundler/gems/grape-2302e2644e50/lib/grape/validations/validators/base.rb:15:in `validate!'
~/.rvm/gems/ruby-2.1.1/bundler/gems/grape-2302e2644e50/lib/grape/endpoint.rb:231:in `block in run'
~/.rvm/gems/ruby-2.1.1/bundler/gems/grape-2302e2644e50/lib/grape/endpoint.rb:229:in `each'
~/.rvm/gems/ruby-2.1.1/bundler/gems/grape-2302e2644e50/lib/grape/endpoint.rb:229:in `run'
~/.rvm/gems/ruby-2.1.1/bundler/gems/grape-2302e2644e50/lib/grape/endpoint.rb:191:in `block in call!'
~/.rvm/gems/ruby-2.1.1/bundler/gems/grape-2302e2644e50/lib/grape/middleware/base.rb:24:in `call'
~/.rvm/gems/ruby-2.1.1/bundler/gems/grape-2302e2644e50/lib/grape/middleware/base.rb:24:in `call!'
~/.rvm/gems/ruby-2.1.1/bundler/gems/grape-2302e2644e50/lib/grape/middleware/base.rb:18:in `call'
~/.rvm/gems/ruby-2.1.1/bundler/gems/grape-2302e2644e50/lib/grape/middleware/error.rb:27:in `block in call!'
~/.rvm/gems/ruby-2.1.1/bundler/gems/grape-2302e2644e50/lib/grape/middleware/error.rb:26:in `catch'
~/.rvm/gems/ruby-2.1.1/bundler/gems/grape-2302e2644e50/lib/grape/middleware/error.rb:26:in `call!'
~/.rvm/gems/ruby-2.1.1/bundler/gems/grape-2302e2644e50/lib/grape/middleware/base.rb:18:in `call'
~/.rvm/gems/ruby-2.1.1/gems/rack-1.5.2/lib/rack/head.rb:11:in `call'
~/.rvm/gems/ruby-2.1.1/gems/rack-1.5.2/lib/rack/builder.rb:138:in `call'
~/.rvm/gems/ruby-2.1.1/bundler/gems/grape-2302e2644e50/lib/grape/endpoint.rb:192:in `call!'
~/.rvm/gems/ruby-2.1.1/bundler/gems/grape-2302e2644e50/lib/grape/endpoint.rb:180:in `call'
~/.rvm/gems/ruby-2.1.1/gems/rack-mount-0.8.3/lib/rack/mount/route_set.rb:152:in `block in call'
~/.rvm/gems/ruby-2.1.1/gems/rack-mount-0.8.3/lib/rack/mount/code_generation.rb:96:in `block in recognize'
~/.rvm/gems/ruby-2.1.1/gems/rack-mount-0.8.3/lib/rack/mount/code_generation.rb:68:in `optimized_each'
~/.rvm/gems/ruby-2.1.1/gems/rack-mount-0.8.3/lib/rack/mount/code_generation.rb:95:in `recognize'
~/.rvm/gems/ruby-2.1.1/gems/rack-mount-0.8.3/lib/rack/mount/route_set.rb:141:in `call'
~/.rvm/gems/ruby-2.1.1/bundler/gems/grape-2302e2644e50/lib/grape/api.rb:104:in `call'
~/.rvm/gems/ruby-2.1.1/bundler/gems/grape-2302e2644e50/lib/grape/api.rb:33:in `call!'
~/.rvm/gems/ruby-2.1.1/bundler/gems/grape-2302e2644e50/lib/grape/api.rb:29:in `call'
~/.rvm/gems/ruby-2.1.1/gems/rack-1.5.2/lib/rack/cascade.rb:33:in `block in call'
~/.rvm/gems/ruby-2.1.1/gems/rack-1.5.2/lib/rack/cascade.rb:24:in `each'
~/.rvm/gems/ruby-2.1.1/gems/rack-1.5.2/lib/rack/cascade.rb:24:in `call'
~/.rvm/gems/ruby-2.1.1/gems/rack-1.5.2/lib/rack/lint.rb:49:in `_call'
~/.rvm/gems/ruby-2.1.1/gems/rack-1.5.2/lib/rack/lint.rb:37:in `call'
~/.rvm/gems/ruby-2.1.1/gems/rack-1.5.2/lib/rack/showexceptions.rb:24:in `call'
~/.rvm/gems/ruby-2.1.1/gems/rack-1.5.2/lib/rack/commonlogger.rb:33:in `call'
~/.rvm/gems/ruby-2.1.1/gems/sinatra-1.4.5/lib/sinatra/base.rb:217:in `call'
~/.rvm/gems/ruby-2.1.1/gems/rack-1.5.2/lib/rack/chunked.rb:43:in `call'
~/.rvm/gems/ruby-2.1.1/gems/rack-1.5.2/lib/rack/content_length.rb:14:in `call'
~/.rvm/gems/ruby-2.1.1/gems/rack-1.5.2/lib/rack/handler/webrick.rb:60:in `service'
~/.rvm/rubies/ruby-2.1.1/lib/ruby/2.1.0/webrick/httpserver.rb:138:in `service'
~/.rvm/rubies/ruby-2.1.1/lib/ruby/2.1.0/webrick/httpserver.rb:94:in `run'
~/.rvm/rubies/ruby-2.1.1/lib/ruby/2.1.0/webrick/server.rb:295:in `block in start_thread~/
````