Permalink
Browse files

Ensure deprecated validate methods are invoked when they are private [#…

…3214 status:resolved]
  • Loading branch information...
1 parent 38c2e46 commit 40c4a0036a690b2e0e3157520f1851efc77fbef7 @josevalim josevalim committed Jan 18, 2010
Showing with 19 additions and 2 deletions.
  1. +1 −1 activerecord/lib/active_record/callbacks.rb
  2. +18 −1 activerecord/test/cases/validations_test.rb
@@ -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

0 comments on commit 40c4a00

Please sign in to comment.