Skip to content
Browse files

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

Signed-off-by: Pratik Naik <pratiknaik@gmail.com>
  • Loading branch information...
1 parent b6ad9a7 commit 56dc039138ea2410a347de4d916b6120442fae3c @alloy alloy committed with tarmo Aug 13, 2008
Showing with 11 additions and 1 deletion.
  1. +5 −1 activerecord/lib/active_record/named_scope.rb
  2. +6 −0 activerecord/test/cases/named_scope_test.rb
View
6 activerecord/lib/active_record/named_scope.rb
@@ -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
@@ -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
View
6 activerecord/test/cases/named_scope_test.rb
@@ -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)

0 comments on commit 56dc039

Please sign in to comment.
Something went wrong with that request. Please try again.