From 981f69639841759a558a0083cd507fa610d564ad Mon Sep 17 00:00:00 2001 From: Pratik Naik Date: Tue, 29 Dec 2009 12:31:08 +0530 Subject: Relation#respond_to? should take second argument for responding to private methods --- activerecord/lib/active_record/relation.rb | 4 ++-- activerecord/test/cases/relations_test.rb | 7 +++++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/activerecord/lib/active_record/relation.rb b/activerecord/lib/active_record/relation.rb index d7cd78593f..b82a7d44f7 100644 --- a/activerecord/lib/active_record/relation.rb +++ b/activerecord/lib/active_record/relation.rb @@ -142,8 +142,8 @@ module ActiveRecord create_new_relation(@relation.where(conditions)) end - def respond_to?(method) - return true if @relation.respond_to?(method) || Array.method_defined?(method) + def respond_to?(method, include_private = false) + return true if @relation.respond_to?(method, include_private) || Array.method_defined?(method) 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 1c344c0b48..8c1ce07e75 100644 --- a/activerecord/test/cases/relations_test.rb +++ b/activerecord/test/cases/relations_test.rb @@ -146,6 +146,13 @@ class RelationTest < ActiveRecord::TestCase end end + def test_respond_to_private_arel_methods + relation = Topic.scoped + + assert ! relation.respond_to?(:matching_attributes) + assert relation.respond_to?(:matching_attributes, true) + end + def test_respond_to_dynamic_finders relation = Topic.scoped -- cgit v1.2.3