Browse files

Override respond_to? in ActiveRecord::Relation to go with

method_missing.
  • Loading branch information...
1 parent fefb4c7 commit 74ed123e082a9b2b160ddecc2eb141f1678c600a @miloops miloops committed Aug 18, 2009
Showing with 16 additions and 0 deletions.
  1. +8 −0 activerecord/lib/active_record/relation.rb
  2. +8 −0 activerecord/test/cases/relations_test.rb
View
8 activerecord/lib/active_record/relation.rb
@@ -73,6 +73,14 @@ def conditions(conditions)
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)
View
8 activerecord/test/cases/relations_test.rb
@@ -71,5 +71,13 @@ def test_joins_with_string_array
).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

0 comments on commit 74ed123

Please sign in to comment.