Skip to content

Commit

Permalink
Fix ActiveRecord::NamedScope::Scope#respond_to? [#818 state:resolved]
Browse files Browse the repository at this point in the history
Signed-off-by: Pratik Naik <pratiknaik@gmail.com>
  • Loading branch information
alloy authored and tarmo committed Aug 24, 2008
1 parent b6ad9a7 commit 56dc039
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
6 changes: 5 additions & 1 deletion activerecord/lib/active_record/named_scope.rb
Expand Up @@ -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?)/
unless m =~ /(^__|^nil\?|^send|^object_id$|class|extend|find|count|sum|average|maximum|minimum|paginate|first|last|empty?|respond_to?)/
delegate m, :to => :proxy_found
end
end
Expand Down Expand Up @@ -140,6 +140,10 @@ def empty?
@found ? @found.empty? : count.zero?
end

def respond_to?(method)
super || @proxy_scope.respond_to?(method)
end

protected
def proxy_found
@found || load_found
Expand Down
6 changes: 6 additions & 0 deletions activerecord/test/cases/named_scope_test.rb
Expand Up @@ -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)

Expand Down

0 comments on commit 56dc039

Please sign in to comment.