Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #6517 from purcell/validates-false-value

Don't enable validations when passing false hash values to ActiveModel.validates
  • Loading branch information...
commit f5e26bcb1a9a44b763d4d9ff117705312d1c650f 2 parents 5acb10d + b3ccd7b
@josevalim josevalim authored
View
2  activemodel/CHANGELOG.md
@@ -1,5 +1,7 @@
## Rails 4.0.0 (unreleased) ##
+* Passing false hash values to `validates` will no longer enable the corresponding validators *Steve Purcell*
+
* `ConfirmationValidator` error messages will attach to `:#{attribute}_confirmation` instead of `attribute` *Brian Cardarella*
* Added ActiveModel::Model, a mixin to make Ruby objects work with AP out of box *Guillermo Iguaran*
View
1  activemodel/lib/active_model/validations/validates.rb
@@ -88,6 +88,7 @@ def validates(*attributes)
defaults.merge!(:attributes => attributes)
validations.each do |key, options|
+ next unless options
key = "#{key.to_s.camelize}Validator"
begin
View
5 activemodel/test/cases/validations_test.rb
@@ -330,6 +330,11 @@ def test_validates_with_bang
end
end
+ def test_validates_with_false_hash_value
+ Topic.validates :title, :presence => false
+ assert Topic.new.valid?
+ end
+
def test_strict_validation_error_message
Topic.validates :title, :strict => true, :presence => true
Please sign in to comment.
Something went wrong with that request. Please try again.