Skip to content

Commit

Permalink
Avoid compiling regexs in AR::Base.respond_to?
Browse files Browse the repository at this point in the history
Caches the patterns of ActiveRecord::DynamicMatchers in a class instance
variable.
  • Loading branch information
jhawthorn committed Aug 22, 2013
1 parent 9208338 commit 646bfe1
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion activerecord/lib/active_record/dynamic_matchers.rb
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions activerecord/test/cases/finder_respond_to_test.rb
Expand Up @@ -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
Expand Down

0 comments on commit 646bfe1

Please sign in to comment.