Skip to content

Commit f5e26bc

Browse files
committed
Merge pull request rails#6517 from purcell/validates-false-value
Don't enable validations when passing false hash values to ActiveModel.validates
2 parents 5acb10d + b3ccd7b commit f5e26bc

File tree

3 files changed

+8
-0
lines changed

3 files changed

+8
-0
lines changed

activemodel/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
## Rails 4.0.0 (unreleased) ##
22

3+
* Passing false hash values to `validates` will no longer enable the corresponding validators *Steve Purcell*
4+
35
* `ConfirmationValidator` error messages will attach to `:#{attribute}_confirmation` instead of `attribute` *Brian Cardarella*
46

57
* Added ActiveModel::Model, a mixin to make Ruby objects work with AP out of box *Guillermo Iguaran*

activemodel/lib/active_model/validations/validates.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ def validates(*attributes)
8888
defaults.merge!(:attributes => attributes)
8989

9090
validations.each do |key, options|
91+
next unless options
9192
key = "#{key.to_s.camelize}Validator"
9293

9394
begin

activemodel/test/cases/validations_test.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,11 @@ def test_validates_with_bang
330330
end
331331
end
332332

333+
def test_validates_with_false_hash_value
334+
Topic.validates :title, :presence => false
335+
assert Topic.new.valid?
336+
end
337+
333338
def test_strict_validation_error_message
334339
Topic.validates :title, :strict => true, :presence => true
335340

0 commit comments

Comments
 (0)