mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Ensure deprecated validate methods are invoked when they are private [#3214 status:resolved]
This commit is contained in:
parent
38c2e4687f
commit
40c4a0036a
2 changed files with 19 additions and 2 deletions
|
@ -291,7 +291,7 @@ module ActiveRecord
|
|||
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 @@ end
|
|||
class DeprecatedPerson < ActiveRecord::Base
|
||||
set_table_name 'people'
|
||||
|
||||
protected
|
||||
private
|
||||
|
||||
def validate
|
||||
errors[:name] << "always invalid"
|
||||
|
@ -161,4 +161,21 @@ class ValidationsTest < ActiveRecord::TestCase
|
|||
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 a new issue