diff options
author | Emilio Tagua <miloops@gmail.com> | 2009-08-18 16:35:33 -0300 |
---|---|---|
committer | Emilio Tagua <miloops@gmail.com> | 2009-08-18 16:35:33 -0300 |
commit | 74ed123e082a9b2b160ddecc2eb141f1678c600a (patch) | |
tree | f22be82f6173693baed83a264cb52df99239076a /activerecord | |
parent | fefb4c78ac8f37ea0b14cbb0c008f305a1bbd36f (diff) | |
download | rails-74ed123e082a9b2b160ddecc2eb141f1678c600a.tar.gz rails-74ed123e082a9b2b160ddecc2eb141f1678c600a.tar.bz2 rails-74ed123e082a9b2b160ddecc2eb141f1678c600a.zip |
Override respond_to? in ActiveRecord::Relation to go with
method_missing.
Diffstat (limited to 'activerecord')
-rw-r--r-- | activerecord/lib/active_record/relation.rb | 8 | ||||
-rw-r--r-- | activerecord/test/cases/relations_test.rb | 8 |
2 files changed, 16 insertions, 0 deletions
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 |