Skip to content
Browse files

Revert "Fix `validates_presence_of` with `:allow_nil` or `:allow_blan…

…k` options."

This reverts commit 93366c7.

REASON: This is backward incompatible. Also this behavior is documented
on the guides.
  • Loading branch information...
1 parent 93366c7 commit d38c8caa48a732d41c7402a5e71deece4e313559 @rafaelfranca rafaelfranca committed Dec 26, 2012
View
5 activemodel/CHANGELOG.md
@@ -1,10 +1,5 @@
## Rails 3.2.10 (unreleased) ##
-* Fix `validates_presence_of` with `:allow_nil` or `:allow_blank` options.
- Fixes #8621.
-
- *Colin Kelley and Rafael Mendonça França*
-
* Specify type of singular association during serialization *Steve Klabnik*
View
6 activemodel/lib/active_model/validations/presence.rb
@@ -4,8 +4,8 @@ module ActiveModel
# == Active Model Presence Validator
module Validations
class PresenceValidator < EachValidator
- def validate_each(record, attr_name, value)
- record.errors.add(attr_name, :blank, options) if value.blank?
+ def validate(record)
+ record.errors.add_on_blank(attributes, options)
end
end
@@ -39,7 +39,7 @@ module HelperMethods
# if the validation should not occur (e.g. <tt>:unless => :skip_validation</tt>,
# or <tt>:unless => Proc.new { |user| user.signup_step <= 2 }</tt>). The method,
# proc or string should return or evaluate to a true or false value.
- # * <tt>:strict</tt> - Specifies whether validation should be strict.
+ # * <tt>:strict</tt> - Specifies whether validation should be strict.
# See <tt>ActiveModel::Validation#validates!</tt> for more information.
def validates_presence_of(*attr_names)
validates_with PresenceValidator, _merge_attributes(attr_names)
View
34 activemodel/test/cases/validations/presence_validation_test.rb
@@ -70,38 +70,4 @@ def test_validates_presence_of_for_ruby_class_with_custom_reader
p[:karma] = "Cold"
assert p.valid?
end
-
- def test_validates_presence_of_with_allow_nil_option
- Topic.validates_presence_of(:title, :allow_nil => true)
-
- t = Topic.new(:title => "something")
- assert t.valid?
-
- t.title = ""
- assert t.invalid?
- assert_equal ["can't be blank"], t.errors[:title]
-
- t.title = " "
- assert t.invalid?
- assert_equal ["can't be blank"], t.errors[:title]
-
- t.title = nil
- assert t.valid?
- end
-
- def test_validates_presence_of_with_allow_blank_option
- Topic.validates_presence_of(:title, :allow_blank => true)
-
- t = Topic.new(:title => "something")
- assert t.valid?
-
- t.title = ""
- assert t.valid?
-
- t.title = " "
- assert t.valid?
-
- t.title = nil
- assert t.valid?
- end
end

0 comments on commit d38c8ca

Please sign in to comment.
Something went wrong with that request. Please try again.