From d38c8caa48a732d41c7402a5e71deece4e313559 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Mendon=C3=A7a=20Fran=C3=A7a?= Date: Wed, 26 Dec 2012 20:20:02 -0300 Subject: Revert "Fix `validates_presence_of` with `:allow_nil` or `:allow_blank` options." This reverts commit 93366c7c913bf0883f140fa782d3e198593477be. REASON: This is backward incompatible. Also this behavior is documented on the guides. --- activemodel/CHANGELOG.md | 5 ---- .../lib/active_model/validations/presence.rb | 6 ++-- .../cases/validations/presence_validation_test.rb | 34 ---------------------- 3 files changed, 3 insertions(+), 42 deletions(-) diff --git a/activemodel/CHANGELOG.md b/activemodel/CHANGELOG.md index 7dfc76ea8f..d98df4cb91 100644 --- a/activemodel/CHANGELOG.md +++ b/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* diff --git a/activemodel/lib/active_model/validations/presence.rb b/activemodel/lib/active_model/validations/presence.rb index 20a57e3c59..efd1372a6b 100644 --- a/activemodel/lib/active_model/validations/presence.rb +++ b/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 ActiveModel # if the validation should not occur (e.g. :unless => :skip_validation, # or :unless => Proc.new { |user| user.signup_step <= 2 }). The method, # proc or string should return or evaluate to a true or false value. - # * :strict - Specifies whether validation should be strict. + # * :strict - Specifies whether validation should be strict. # See ActiveModel::Validation#validates! for more information. def validates_presence_of(*attr_names) validates_with PresenceValidator, _merge_attributes(attr_names) diff --git a/activemodel/test/cases/validations/presence_validation_test.rb b/activemodel/test/cases/validations/presence_validation_test.rb index fbb008f9ff..510c13a7c3 100644 --- a/activemodel/test/cases/validations/presence_validation_test.rb +++ b/activemodel/test/cases/validations/presence_validation_test.rb @@ -70,38 +70,4 @@ class PresenceValidationTest < ActiveModel::TestCase 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 -- cgit v1.2.3