Permalink
Browse files

Memoize STI class lookups for the duration of a request

  • Loading branch information...
1 parent a16ec2f commit 64f4dc68f613321a5ab02c87a2071754d68de1c5 @jeremy jeremy committed Aug 19, 2010
Showing with 3 additions and 3 deletions.
  1. +2 −2 activerecord/lib/active_record/base.rb
  2. +1 −1 activerecord/test/cases/base_test.rb
@@ -1171,7 +1171,7 @@ def compute_type(type_name)
if type_name.match(/^::/)
# If the type is prefixed with a scope operator then we assume that
# the type_name is an absolute reference.
- type_name.constantize
+ ActiveSupport::Dependencies.constantize(type_name)
else
# Build a list of candidates to search for
candidates = []
@@ -1180,7 +1180,7 @@ def compute_type(type_name)
candidates.each do |candidate|
begin
- constant = candidate.constantize
+ constant = ActiveSupport::Dependencies.constantize(candidate)
return constant if candidate == constant.to_s
rescue NameError => e
# We don't want to swallow NoMethodError < NameError errors
@@ -1667,7 +1667,7 @@ def test_compute_type_nonexistent_constant
end
def test_compute_type_no_method_error
- String.any_instance.stubs(:constantize).raises(NoMethodError)
+ ActiveSupport::Dependencies.stubs(:constantize).raises(NoMethodError)
assert_raises NoMethodError do
ActiveRecord::Base.send :compute_type, 'InvalidModel'
end

0 comments on commit 64f4dc6

Please sign in to comment.