Skip to content

Commit

Permalink
Ensure deprecated validate methods are invoked when they are private [#…
Browse files Browse the repository at this point in the history
…3214 status:resolved]
  • Loading branch information
josevalim committed Jan 18, 2010
1 parent 38c2e46 commit 40c4a00
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
2 changes: 1 addition & 1 deletion activerecord/lib/active_record/callbacks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 18 additions & 1 deletion activerecord/test/cases/validations_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class ProtectedPerson < ActiveRecord::Base
class DeprecatedPerson < ActiveRecord::Base
set_table_name 'people'

protected
private

def validate
errors[:name] << "always invalid"
Expand Down Expand Up @@ -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.