Skip to content

Commit a711cab

Browse files
ipkesdblock
authored andcommitted
Fix: allow_blank false for Time attributes with valid values causes NoMethodError.
1 parent 783ece4 commit a711cab

File tree

3 files changed

+7
-1
lines changed

3 files changed

+7
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#### Fixes
1111

1212
* [#1365](https://github.com/ruby-grape/grape/pull/1365): Fix finding exception handler in error middleware - [@ktimothy](https://github.com/ktimothy).
13+
* [#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).
1314

1415
0.16.2 (4/12/2016)
1516
==================

lib/grape/validations/validators/allow_blank.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def validate_param!(attr_name, params)
2020

2121
return unless should_validate
2222

23-
return if value == false || value.present?
23+
return if false == value || value.present?
2424

2525
raise Grape::Exceptions::Validation, params: [@scope.full_name(attr_name)], message: message(:blank)
2626
end

spec/grape/validations/validators/allow_blank_spec.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -488,6 +488,11 @@ def app
488488
get '/disallow_boolean_blank', val: false
489489
expect(last_response.status).to eq(200)
490490
end
491+
492+
it 'accepts value when time allow_blank' do
493+
get '/disallow_datetime_blank', val: Time.now
494+
expect(last_response.status).to eq(200)
495+
end
491496
end
492497

493498
context 'in an optional group' do

0 commit comments

Comments
 (0)