diff options
author | José Valim <jose.valim@gmail.com> | 2010-01-18 09:56:36 +0100 |
---|---|---|
committer | José Valim <jose.valim@gmail.com> | 2010-01-18 09:56:36 +0100 |
commit | 40c4a0036a690b2e0e3157520f1851efc77fbef7 (patch) | |
tree | d50d7d308bf0dd96d9041983b94a7ba26eeb81a4 /activerecord | |
parent | 38c2e4687f70f67faf29ff4d50b10d8c21349769 (diff) | |
download | rails-40c4a0036a690b2e0e3157520f1851efc77fbef7.tar.gz rails-40c4a0036a690b2e0e3157520f1851efc77fbef7.tar.bz2 rails-40c4a0036a690b2e0e3157520f1851efc77fbef7.zip |
Ensure deprecated validate methods are invoked when they are private [#3214 status:resolved]
Diffstat (limited to 'activerecord')
-rw-r--r-- | activerecord/lib/active_record/callbacks.rb | 2 | ||||
-rw-r--r-- | activerecord/test/cases/validations_test.rb | 19 |
2 files changed, 19 insertions, 2 deletions
diff --git a/activerecord/lib/active_record/callbacks.rb b/activerecord/lib/active_record/callbacks.rb index aecde5848c..1128286f2b 100644 --- a/activerecord/lib/active_record/callbacks.rb +++ b/activerecord/lib/active_record/callbacks.rb @@ -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 diff --git a/activerecord/test/cases/validations_test.rb b/activerecord/test/cases/validations_test.rb index 8314f880be..5aac0229cd 100644 --- a/activerecord/test/cases/validations_test.rb +++ b/activerecord/test/cases/validations_test.rb @@ -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 |