提交 1ee9e3fa 编写于 作者: E Eloy Duran 提交者: Pratik Naik

Fix ActiveRecord::NamedScope::Scope#respond_to? [#818 state:resolved]

Signed-off-by: NPratik Naik <pratiknaik@gmail.com>
上级 282b4202
......@@ -103,7 +103,7 @@ class Scope
attr_reader :proxy_scope, :proxy_options
[].methods.each do |m|
unless m =~ /(^__|^nil\?|^send|^object_id$|class|extend|find|count|sum|average|maximum|minimum|paginate|first|last|empty?|any?)/
unless m =~ /(^__|^nil\?|^send|^object_id$|class|extend|find|count|sum|average|maximum|minimum|paginate|first|last|empty?|any?|respond_to?)/
delegate m, :to => :proxy_found
end
end
......@@ -140,6 +140,10 @@ def empty?
@found ? @found.empty? : count.zero?
end
def respond_to?(method)
super || @proxy_scope.respond_to?(method)
end
def any?
if block_given?
proxy_found.any? { |*block_args| yield(*block_args) }
......
......@@ -45,6 +45,12 @@ def test_delegates_finds_and_calculations_to_the_base_class
assert_equal Topic.average(:replies_count), Topic.base.average(:replies_count)
end
def test_scope_should_respond_to_own_methods_and_methods_of_the_proxy
assert Topic.approved.respond_to?(:proxy_found)
assert Topic.approved.respond_to?(:count)
assert Topic.approved.respond_to?(:length)
end
def test_subclasses_inherit_scopes
assert Topic.scopes.include?(:base)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册