From 4afd9702fe111a5cbaa0d9572e7661c90b188d49 Mon Sep 17 00:00:00 2001 From: Pratik Naik Date: Fri, 22 Jan 2010 20:14:37 +0530 Subject: Relation should respond to class methods --- activerecord/lib/active_record/relation.rb | 2 +- activerecord/test/cases/relations_test.rb | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) (limited to 'activerecord') diff --git a/activerecord/lib/active_record/relation.rb b/activerecord/lib/active_record/relation.rb index fa99e3f891..1a96cdad17 100644 --- a/activerecord/lib/active_record/relation.rb +++ b/activerecord/lib/active_record/relation.rb @@ -32,7 +32,7 @@ module ActiveRecord end def respond_to?(method, include_private = false) - return true if arel.respond_to?(method, include_private) || Array.method_defined?(method) + return true if arel.respond_to?(method, include_private) || Array.method_defined?(method) || @klass.respond_to?(method, include_private) if match = DynamicFinderMatch.match(method) return true if @klass.send(:all_attributes_exists?, match.attribute_names) diff --git a/activerecord/test/cases/relations_test.rb b/activerecord/test/cases/relations_test.rb index d34c9b4895..1e345399f5 100644 --- a/activerecord/test/cases/relations_test.rb +++ b/activerecord/test/cases/relations_test.rb @@ -164,6 +164,11 @@ class RelationTest < ActiveRecord::TestCase end end + def test_respond_to_class_methods_and_named_scopes + assert DeveloperOrderedBySalary.scoped.respond_to?(:all_ordered_by_name) + assert Topic.scoped.respond_to?(:by_lifo) + end + def test_find_with_readonly_option Developer.scoped.each { |d| assert !d.readonly? } Developer.scoped.readonly.each { |d| assert d.readonly? } -- cgit v1.2.3