Override respond_to? in ActiveRecord::Relation to go with

method_missing.
This commit is contained in:
Emilio Tagua
2009-08-18 16:35:33 -03:00
parent fefb4c78ac
commit 74ed123e08
2 changed files with 16 additions and 0 deletions

View File

@@ -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)

View File

@@ -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