From 74ed123e082a9b2b160ddecc2eb141f1678c600a Mon Sep 17 00:00:00 2001 From: Emilio Tagua Date: Tue, 18 Aug 2009 16:35:33 -0300 Subject: [PATCH] Override respond_to? in ActiveRecord::Relation to go with method_missing. --- activerecord/lib/active_record/relation.rb | 8 ++++++++ activerecord/test/cases/relations_test.rb | 8 ++++++++ 2 files changed, 16 insertions(+) diff --git a/activerecord/lib/active_record/relation.rb b/activerecord/lib/active_record/relation.rb index 84cd739781..b69a12bc7b 100644 --- a/activerecord/lib/active_record/relation.rb +++ b/activerecord/lib/active_record/relation.rb @@ -73,6 +73,14 @@ module ActiveRecord end end + def respond_to?(method) + if @relation.respond_to?(method) || Array.instance_methods.include?(method.to_s) + true + else + super + end + end + private def method_missing(method, *args, &block) if @relation.respond_to?(method) diff --git a/activerecord/test/cases/relations_test.rb b/activerecord/test/cases/relations_test.rb index b017570b45..6a39aa6e40 100644 --- a/activerecord/test/cases/relations_test.rb +++ b/activerecord/test/cases/relations_test.rb @@ -71,5 +71,13 @@ class RelationTest < ActiveRecord::TestCase ).to_a assert_equal 1, person_with_reader_and_post.size end + + def test_relation_responds_to_delegated_methods + relation = Topic.all + + ["map", "uniq", "sort", "insert", "delete", "update"].each do |method| + assert relation.respond_to?(method) + end + end end