mirror of
https://github.com/github/rails.git
synced 2026-04-26 03:00:59 -04:00
Make sure Relation responds to dynamic finder methods
This commit is contained in:
@@ -143,7 +143,15 @@ module ActiveRecord
|
||||
end
|
||||
|
||||
def respond_to?(method)
|
||||
@relation.respond_to?(method) || Array.method_defined?(method) || super
|
||||
return true if @relation.respond_to?(method) || Array.method_defined?(method)
|
||||
|
||||
if match = DynamicFinderMatch.match(method)
|
||||
return true if @klass.send(:all_attributes_exists?, match.attribute_names)
|
||||
elsif match = DynamicScopeMatch.match(method)
|
||||
return true if @klass.send(:all_attributes_exists?, match.attribute_names)
|
||||
else
|
||||
super
|
||||
end
|
||||
end
|
||||
|
||||
def to_a
|
||||
|
||||
@@ -142,7 +142,15 @@ class RelationTest < ActiveRecord::TestCase
|
||||
relation = Topic.scoped
|
||||
|
||||
["map", "uniq", "sort", "insert", "delete", "update"].each do |method|
|
||||
assert relation.respond_to?(method), "Topic.all should respond to #{method.inspect}"
|
||||
assert relation.respond_to?(method), "Topic.scoped should respond to #{method.inspect}"
|
||||
end
|
||||
end
|
||||
|
||||
def test_respond_to_dynamic_finders
|
||||
relation = Topic.scoped
|
||||
|
||||
["find_by_title", "find_by_title_and_author_name", "find_or_create_by_title", "find_or_initialize_by_title_and_author_name"].each do |method|
|
||||
assert relation.respond_to?(method), "Topic.scoped should respond to #{method.inspect}"
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user