From 40c4a0036a690b2e0e3157520f1851efc77fbef7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Mon, 18 Jan 2010 09:56:36 +0100 Subject: Ensure deprecated validate methods are invoked when they are private [#3214 status:resolved] --- activerecord/lib/active_record/callbacks.rb | 2 +- activerecord/test/cases/validations_test.rb | 19 ++++++++++++++++++- 2 files changed, 19 insertions(+), 2 deletions(-) (limited to 'activerecord') 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 -- cgit v1.2.3