diff options
author | Pratik Naik <pratiknaik@gmail.com> | 2009-12-29 12:27:40 +0530 |
---|---|---|
committer | Pratik Naik <pratiknaik@gmail.com> | 2009-12-29 12:27:40 +0530 |
commit | bc933d0fa1b3a89deaf3e7c74d7717eb8fc7152a (patch) | |
tree | 34b05f17a1f79715c1b59f1fbda20f568745d303 | |
parent | f290e685f0497427b348a2fae760300429d5f0cd (diff) | |
download | rails-bc933d0fa1b3a89deaf3e7c74d7717eb8fc7152a.tar.gz rails-bc933d0fa1b3a89deaf3e7c74d7717eb8fc7152a.tar.bz2 rails-bc933d0fa1b3a89deaf3e7c74d7717eb8fc7152a.zip |
Make sure Relation responds to dynamic finder methods
-rw-r--r-- | activerecord/lib/active_record/relation.rb | 10 | ||||
-rw-r--r-- | activerecord/test/cases/relations_test.rb | 10 |
2 files changed, 18 insertions, 2 deletions
diff --git a/activerecord/lib/active_record/relation.rb b/activerecord/lib/active_record/relation.rb index 52a8bea567..d7cd78593f 100644 --- a/activerecord/lib/active_record/relation.rb +++ b/activerecord/lib/active_record/relation.rb @@ -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 diff --git a/activerecord/test/cases/relations_test.rb b/activerecord/test/cases/relations_test.rb index c3cce8c5f2..1c344c0b48 100644 --- a/activerecord/test/cases/relations_test.rb +++ b/activerecord/test/cases/relations_test.rb @@ -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 |