diff --git a/activerecord/lib/active_record/relation.rb b/activerecord/lib/active_record/relation.rb index d7cd78593fdc46f7d8881c01fa68ad73163af78d..b82a7d44f7ccd5c6da51ed16bb364fdf601eaa39 100644 --- a/activerecord/lib/active_record/relation.rb +++ b/activerecord/lib/active_record/relation.rb @@ -142,8 +142,8 @@ def where(*args) 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 1c344c0b4818987819905cac6891b7d309539c0c..8c1ce07e75781a00b18b1fa5ce03bc3efc4e6df7 100644 --- a/activerecord/test/cases/relations_test.rb +++ b/activerecord/test/cases/relations_test.rb @@ -146,6 +146,13 @@ def test_scoped_responds_to_delegated_methods 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