mirror of
https://github.com/github/rails.git
synced 2026-04-26 03:00:59 -04:00
Override respond_to? in ActiveRecord::Relation to go with
method_missing.
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user