Skip to content
Browse files

Avoid compiling regexs in AR::Base.respond_to?

Caches the patterns of ActiveRecord::DynamicMatchers in a class instance
variable.
  • Loading branch information...
1 parent 9208338 commit 646bfe1a5e7b30863e5ab8a5927246be3a69ed3b @jhawthorn jhawthorn committed Aug 20, 2013
View
2 activerecord/lib/active_record/dynamic_matchers.rb
@@ -35,7 +35,7 @@ def match(model, name)
end
def pattern
- /^#{prefix}_([_a-zA-Z]\w*)#{suffix}$/
+ @pattern ||= /\A#{prefix}_([_a-zA-Z]\w*)#{suffix}\Z/
end
def prefix
View
5 activerecord/test/cases/finder_respond_to_test.rb
@@ -21,6 +21,11 @@ def test_should_respond_to_find_by_one_attribute_before_caching
assert_respond_to Topic, :find_by_title
end
+ def test_should_respond_to_find_by_with_bang
+ ensure_topic_method_is_not_cached(:find_by_title!)
+ assert_respond_to Topic, :find_by_title!
+ end
+
def test_should_respond_to_find_by_two_attributes
ensure_topic_method_is_not_cached(:find_by_title_and_author_name)
assert_respond_to Topic, :find_by_title_and_author_name

0 comments on commit 646bfe1

Please sign in to comment.
Something went wrong with that request. Please try again.