Deprecated add_on_boundary_breaking (use validates_length_of instead) (closes #6292) [BobSilva]

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@5255 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
David Heinemeier Hansson 2006-10-09 01:42:09 +00:00
parent cb0837a2b7
commit 9fd88d7939
4 changed files with 16 additions and 18 deletions

View File

@ -1,5 +1,7 @@
*SVN* *SVN*
* Deprecated add_on_boundary_breaking (use validates_length_of instead) #6292 [BobSilva]
* The has_many create method works with polymorphic associations. #6361 [Dan Peterson] * The has_many create method works with polymorphic associations. #6361 [Dan Peterson]
* MySQL: introduce Mysql::Result#all_hashes to support further optimization. #5581 [Stefan Kaes] * MySQL: introduce Mysql::Result#all_hashes to support further optimization. #5581 [Stefan Kaes]

View File

@ -87,6 +87,7 @@ module ActiveRecord
end end
alias :add_on_boundry_breaking :add_on_boundary_breaking alias :add_on_boundry_breaking :add_on_boundary_breaking
deprecate :add_on_boundary_breaking, :add_on_boundry_breaking
# Returns true if the specified +attribute+ has errors associated with it. # Returns true if the specified +attribute+ has errors associated with it.
def invalid?(attribute) def invalid?(attribute)

View File

@ -21,11 +21,7 @@ module MyApplication
class Developer < ActiveRecord::Base class Developer < ActiveRecord::Base
has_and_belongs_to_many :projects has_and_belongs_to_many :projects
validates_length_of :name, :within => (3..20)
protected
def validate
errors.add_on_boundary_breaking("name", 3..20)
end
end end
class Project < ActiveRecord::Base class Project < ActiveRecord::Base

View File

@ -165,19 +165,6 @@ class ValidationsTest < Test::Unit::TestCase
perform = false perform = false
end end
def test_errors_on_boundary_breaking
developer = Developer.new("name" => "xs")
assert !developer.save
assert_equal "is too short (minimum is 3 characters)", developer.errors.on("name")
developer.name = "All too very long for this boundary, it really is"
assert !developer.save
assert_equal "is too long (maximum is 20 characters)", developer.errors.on("name")
developer.name = "Just right"
assert developer.save
end
def test_no_title_confirmation def test_no_title_confirmation
Topic.validates_confirmation_of(:title) Topic.validates_confirmation_of(:title)
@ -626,6 +613,18 @@ class ValidationsTest < Test::Unit::TestCase
assert_equal 'tu est trops petit hombre 10', t.errors['title'] assert_equal 'tu est trops petit hombre 10', t.errors['title']
end end
def test_add_on_boundary_breaking_is_deprecated
t = Topic.new('title' => 'noreplies', 'content' => 'whatever')
class << t
def validate
errors.add_on_boundary_breaking('title', 1..6)
end
end
assert_deprecated 'add_on_boundary_breaking' do
assert !t.valid?
end
end
def test_validates_size_of_association def test_validates_size_of_association
assert_nothing_raised { Topic.validates_size_of :replies, :minimum => 1 } assert_nothing_raised { Topic.validates_size_of :replies, :minimum => 1 }