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

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

Signed-off-by: Pratik Naik <pratiknaik@gmail.com>
This commit is contained in:
Eloy Duran 2008-08-13 13:36:39 +02:00 committed by Pratik Naik
parent 282b420213
commit 1ee9e3fa5c
2 changed files with 11 additions and 1 deletions

View file

@ -103,7 +103,7 @@ module ActiveRecord
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 @@ module ActiveRecord
@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) }

View file

@ -45,6 +45,12 @@ class NamedScopeTest < ActiveRecord::TestCase
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)