Skip to content

Commit

Permalink
Merge pull request #1249 from namusyaka/fix-1245
Browse files Browse the repository at this point in the history
Don't fail even if invalid type value is provided
  • Loading branch information
dm1try committed Jan 19, 2016
2 parents 73dfad6 + ee107af commit 6505486
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

* [#1216](https://github.com/ruby-grape/grape/pull/1142): Fix JSON error response when calling `error!` with non-Strings - [@jrforrest](https://github.com/jrforrest).
* [#1225](https://github.com/ruby-grape/grape/pull/1225): Fix `given` with nested params not returning correct declared params - [@JanStevens](https://github.com/JanStevens).
* [#1249](https://github.com/ruby-grape/grape/pull/1249): Don't fail even if invalid type value is passed to default validator - [@namusyaka](https://github.com/namusyaka).

0.14.0 (12/07/2015)
===================
Expand Down
2 changes: 1 addition & 1 deletion lib/grape/validations/validators/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def validate!(params)

attrs = AttributesIterator.new(self, @scope, params)
attrs.each do |resource_params, attr_name|
if resource_params[attr_name].nil?
if resource_params.is_a?(Hash) && resource_params[attr_name].nil?
validate_param!(attr_name, resource_params)
end
end
Expand Down
6 changes: 6 additions & 0 deletions spec/grape/validations/validators/default_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,12 @@ def app
expect(last_response.status).to eq(201)
expect(last_response.body).to eq({ optional_hash_without_default: nil }.to_json)
end

it 'does not fail even if invalid params is passed to default validator' do
expect { post '/optional_hash_without_default', optional_hash_without_default: '5678' }.not_to raise_error
expect(last_response.status).to eq(400)
expect(last_response.body).to eq({ error: 'optional_hash_without_default is invalid' }.to_json)
end
end

context 'optional hash with default value includes optional param with default value' do
Expand Down

0 comments on commit 6505486

Please sign in to comment.