public
Description: Ruby on Rails
Homepage: http://rubyonrails.org
Clone URL: git://github.com/rails/rails.git
Fix ActiveRecord::NamedScope::Scope#respond_to? [#818 state:resolved]

Signed-off-by: Pratik Naik <pratiknaik@gmail.com>
alloy (author)
Wed Aug 13 04:36:39 -0700 2008
lifo (committer)
Wed Aug 13 05:04:42 -0700 2008
commit  1ee9e3fa5c924bef4aba3d53796f48f5badbd06f
tree    92664231bee7c307ab3bb431b226d0cc98a13dac
parent  282b42021306f73d4cc8f8a06713da9a55ed044b
...
103
104
105
106
 
107
108
109
...
140
141
142
 
 
 
 
143
144
145
...
103
104
105
 
106
107
108
109
...
140
141
142
143
144
145
146
147
148
149
0
@@ -103,7 +103,7 @@ module ActiveRecord
0
       attr_reader :proxy_scope, :proxy_options
0
 
0
       [].methods.each do |m|
0
-        unless m =~ /(^__|^nil\?|^send|^object_id$|class|extend|find|count|sum|average|maximum|minimum|paginate|first|last|empty?|any?)/
0
+        unless m =~ /(^__|^nil\?|^send|^object_id$|class|extend|find|count|sum|average|maximum|minimum|paginate|first|last|empty?|any?|respond_to?)/
0
           delegate m, :to => :proxy_found
0
         end
0
       end
0
@@ -140,6 +140,10 @@ module ActiveRecord
0
         @found ? @found.empty? : count.zero?
0
       end
0
 
0
+      def respond_to?(method)
0
+        super || @proxy_scope.respond_to?(method)
0
+      end
0
+
0
       def any?
0
         if block_given?
0
           proxy_found.any? { |*block_args| yield(*block_args) }
...
45
46
47
 
 
 
 
 
 
48
49
50
...
45
46
47
48
49
50
51
52
53
54
55
56
0
@@ -45,6 +45,12 @@ class NamedScopeTest < ActiveRecord::TestCase
0
     assert_equal Topic.average(:replies_count), Topic.base.average(:replies_count)
0
   end
0
 
0
+  def test_scope_should_respond_to_own_methods_and_methods_of_the_proxy
0
+    assert Topic.approved.respond_to?(:proxy_found)
0
+    assert Topic.approved.respond_to?(:count)
0
+    assert Topic.approved.respond_to?(:length)
0
+  end
0
+
0
   def test_subclasses_inherit_scopes
0
     assert Topic.scopes.include?(:base)
0
 

Comments