diff options
author | Godfrey Chan <godfreykfc@gmail.com> | 2014-01-24 18:05:33 -0800 |
---|---|---|
committer | Godfrey Chan <godfreykfc@gmail.com> | 2014-01-29 10:53:48 -0800 |
commit | 9ed66648b59b160b43c83c349263e8cb97eaa088 (patch) | |
tree | 4a0f50070e1e68fef5c437b422afddc7cc5383fe /activerecord | |
parent | 0f156100a2d25fba820016c684cbc3d3fadbc1bd (diff) | |
download | rails-9ed66648b59b160b43c83c349263e8cb97eaa088.tar.gz rails-9ed66648b59b160b43c83c349263e8cb97eaa088.tar.bz2 rails-9ed66648b59b160b43c83c349263e8cb97eaa088.zip |
Fixed a bug in AR::Base#respond_to?
Before:
>> ActiveRecord::Base.respond_to?(:find_by_something)
NoMethodError: undefined method `abstract_class?' for Object:Class
After:
>> ActiveRecord::Base.respond_to?(:find_by_something)
=> false
Diffstat (limited to 'activerecord')
-rw-r--r-- | activerecord/lib/active_record/dynamic_matchers.rb | 8 | ||||
-rw-r--r-- | activerecord/test/cases/finder_respond_to_test.rb | 5 |
2 files changed, 11 insertions, 2 deletions
diff --git a/activerecord/lib/active_record/dynamic_matchers.rb b/activerecord/lib/active_record/dynamic_matchers.rb index 5caab09038..e94b74063e 100644 --- a/activerecord/lib/active_record/dynamic_matchers.rb +++ b/activerecord/lib/active_record/dynamic_matchers.rb @@ -6,8 +6,12 @@ module ActiveRecord # then we can remove the indirection. def respond_to?(name, include_private = false) - match = Method.match(self, name) - match && match.valid? || super + if self == Base + super + else + match = Method.match(self, name) + match && match.valid? || super + end end private diff --git a/activerecord/test/cases/finder_respond_to_test.rb b/activerecord/test/cases/finder_respond_to_test.rb index 3ff22f222f..6ab2657c44 100644 --- a/activerecord/test/cases/finder_respond_to_test.rb +++ b/activerecord/test/cases/finder_respond_to_test.rb @@ -5,6 +5,11 @@ class FinderRespondToTest < ActiveRecord::TestCase fixtures :topics + def test_should_preserve_normal_respond_to_behaviour_on_base + assert_respond_to ActiveRecord::Base, :new + assert !ActiveRecord::Base.respond_to?(:find_by_something) + end + def test_should_preserve_normal_respond_to_behaviour_and_respond_to_newly_added_method class << Topic; self; end.send(:define_method, :method_added_for_finder_respond_to_test) { } assert_respond_to Topic, :method_added_for_finder_respond_to_test |