Ensure deprecated validate methods are invoked when they are private [#3214 status:resolved]
This commit is contained in:
parent
38c2e4687f
commit
40c4a0036a
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user