Skip to content
This repository
Browse code

Relation should respond to class methods

  • Loading branch information...
commit 4afd9702fe111a5cbaa0d9572e7661c90b188d49 1 parent ee8c006
Pratik authored January 22, 2010
2  activerecord/lib/active_record/relation.rb
@@ -32,7 +32,7 @@ def create!(*args, &block)
32 32
     end
33 33
 
34 34
     def respond_to?(method, include_private = false)
35  
-      return true if arel.respond_to?(method, include_private) || Array.method_defined?(method)
  35
+      return true if arel.respond_to?(method, include_private) || Array.method_defined?(method) || @klass.respond_to?(method, include_private)
36 36
 
37 37
       if match = DynamicFinderMatch.match(method)
38 38
         return true if @klass.send(:all_attributes_exists?, match.attribute_names)
5  activerecord/test/cases/relations_test.rb
@@ -164,6 +164,11 @@ def test_respond_to_dynamic_finders
164 164
     end
165 165
   end
166 166
 
  167
+  def test_respond_to_class_methods_and_named_scopes
  168
+    assert DeveloperOrderedBySalary.scoped.respond_to?(:all_ordered_by_name)
  169
+    assert Topic.scoped.respond_to?(:by_lifo)
  170
+  end
  171
+
167 172
   def test_find_with_readonly_option
168 173
     Developer.scoped.each { |d| assert !d.readonly? }
169 174
     Developer.scoped.readonly.each { |d| assert d.readonly? }

0 notes on commit 4afd970

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