Skip to content

Commit

Permalink
Fix: allow_blank false for Time attributes with valid values causes N…
Browse files Browse the repository at this point in the history
…oMethodError.
  • Loading branch information
ipkes authored and dblock committed May 2, 2016
1 parent 783ece4 commit a711cab
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#### Fixes

* [#1365](https://github.com/ruby-grape/grape/pull/1365): Fix finding exception handler in error middleware - [@ktimothy](https://github.com/ktimothy).
* [#1380](https://github.com/ruby-grape/grape/pull/1380): Fix `allow_blank: false` for `Time` attributes with valid values causes `NoMethodError` - [@ipkes](https://github.com/ipkes).

0.16.2 (4/12/2016)
==================
Expand Down
2 changes: 1 addition & 1 deletion lib/grape/validations/validators/allow_blank.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def validate_param!(attr_name, params)

return unless should_validate

return if value == false || value.present?
return if false == value || value.present?

raise Grape::Exceptions::Validation, params: [@scope.full_name(attr_name)], message: message(:blank)
end
Expand Down
5 changes: 5 additions & 0 deletions spec/grape/validations/validators/allow_blank_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,11 @@ def app
get '/disallow_boolean_blank', val: false
expect(last_response.status).to eq(200)
end

it 'accepts value when time allow_blank' do
get '/disallow_datetime_blank', val: Time.now
expect(last_response.status).to eq(200)
end
end

context 'in an optional group' do
Expand Down

0 comments on commit a711cab

Please sign in to comment.