diff --git a/activemodel/CHANGELOG.md b/activemodel/CHANGELOG.md index 789cff06734f6db7de608dcb90c6058ad23c4345..eb34edb91b9f5184100b109e16b9fc8ab3bdb9cb 100644 --- a/activemodel/CHANGELOG.md +++ b/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* diff --git a/activemodel/lib/active_model/validations/validates.rb b/activemodel/lib/active_model/validations/validates.rb index d94c4e3f4feff9be72e2f8d63276e2cb6669ae71..6c13d2b4a20027b166fec25c7e2b7b34bc28cb0e 100644 --- a/activemodel/lib/active_model/validations/validates.rb +++ b/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 diff --git a/activemodel/test/cases/validations_test.rb b/activemodel/test/cases/validations_test.rb index 1f5023bf765ba18c87e3c20bb0aaaa7f7e676bc5..8ea9745fbfaced6a7347459860fe484b1d9606d0 100644 --- a/activemodel/test/cases/validations_test.rb +++ b/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