1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

make sure string keys are always looked up from the class cache

This commit is contained in:
Aaron Patterson 2011-03-02 10:11:28 -08:00
parent 9198372421
commit 1f2e7214aa
2 changed files with 28 additions and 2 deletions

View file

@ -4,7 +4,7 @@ require "active_support/dependencies"
module ActionDispatch
class MiddlewareStack
class Middleware
attr_reader :args, :block
attr_reader :args, :block, :name, :classcache
def initialize(klass_or_name, *args, &block)
@klass = nil
@ -16,11 +16,12 @@ module ActionDispatch
@name = klass_or_name.to_s
end
@classcache = ActiveSupport::Dependencies::Reference
@args, @block = args, block
end
def klass
@klass ||= ActiveSupport::Inflector.constantize(@name)
@klass || classcache[@name]
end
def ==(middleware)

View file

@ -47,6 +47,31 @@ module ActionDispatch
mw = Middleware.new Omg
assert_operator mw, :==, "::#{Omg.name}"
end
def test_middleware_loads_classnames_from_cache
mw = Class.new(Middleware) {
attr_accessor :classcache
}.new(Omg.name)
fake_cache = { mw.name => Omg }
mw.classcache = fake_cache
assert_equal Omg, mw.klass
fake_cache[mw.name] = Middleware
assert_equal Middleware, mw.klass
end
def test_middleware_always_returns_class
mw = Class.new(Middleware) {
attr_accessor :classcache
}.new(Omg)
fake_cache = { mw.name => Middleware }
mw.classcache = fake_cache
assert_equal Omg, mw.klass
end
end
end
end