提交 9ed66648 编写于 作者: G Godfrey Chan

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
上级 0f156100
......@@ -6,8 +6,12 @@ module DynamicMatchers #:nodoc:
# 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
......
......@@ -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
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册