Ensure deprecated validate methods are invoked when they are private [#3214 status:resolved]

This commit is contained in:
José Valim 2010-01-18 09:56:36 +01:00
parent 38c2e4687f
commit 40c4a0036a
2 changed files with 19 additions and 2 deletions

@ -291,7 +291,7 @@ def destroy_with_callbacks #:nodoc:
end
def deprecated_callback_method(symbol) #:nodoc:
if respond_to?(symbol)
if respond_to?(symbol, true)
ActiveSupport::Deprecation.warn("Overwriting #{symbol} in your models has been deprecated, please use Base##{symbol} :method_name instead")
send(symbol)
end

@ -19,7 +19,7 @@ class ProtectedPerson < ActiveRecord::Base
class DeprecatedPerson < ActiveRecord::Base
set_table_name 'people'
protected
private
def validate
errors[:name] << "always invalid"
@ -161,4 +161,21 @@ def test_validates_acceptance_of_as_database_column
topic = Topic.create("author_name" => "Dan Brown")
assert_equal "Dan Brown", topic["author_name"]
end
def test_validate_is_deprecated_on_create
p = DeprecatedPerson.new
assert_deprecated do
assert !p.valid?
end
assert_equal ["always invalid", "invalid on create"], p.errors[:name]
end
def test_validate_is_deprecated_on_update
p = DeprecatedPerson.new(:first_name => "David")
assert p.save(:validate => false)
assert_deprecated do
assert !p.valid?
end
assert_equal ["always invalid", "invalid on update"], p.errors[:name]
end
end