1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Fixed a bug in AR::Base#respond_to?

Before:

  >> ActiveRecord::Base.respond_to?(:find_by_something)
  NoMethodError: undefined method `abstract_class?' for Object:Class

After:

  >> ActiveRecord::Base.respond_to?(:find_by_something)
  => false
This commit is contained in:
Godfrey Chan 2014-01-24 18:05:33 -08:00
parent 0f156100a2
commit 9ed66648b5
2 changed files with 11 additions and 2 deletions

View file

@ -6,8 +6,12 @@ module ActiveRecord
# then we can remove the indirection.
def respond_to?(name, include_private = false)
match = Method.match(self, name)
match && match.valid? || super
if self == Base
super
else
match = Method.match(self, name)
match && match.valid? || super
end
end
private

View file

@ -5,6 +5,11 @@ class FinderRespondToTest < ActiveRecord::TestCase
fixtures :topics
def test_should_preserve_normal_respond_to_behaviour_on_base
assert_respond_to ActiveRecord::Base, :new
assert !ActiveRecord::Base.respond_to?(:find_by_something)
end
def test_should_preserve_normal_respond_to_behaviour_and_respond_to_newly_added_method
class << Topic; self; end.send(:define_method, :method_added_for_finder_respond_to_test) { }
assert_respond_to Topic, :method_added_for_finder_respond_to_test