提交 02908e11 编写于 作者: J José Valim

As first step setup the load path and lazy compare middlewares.

上级 1177a40e
......@@ -55,7 +55,11 @@ def ==(middleware)
when Class
klass == middleware
else
klass == ActiveSupport::Inflector.constantize(middleware.to_s)
if lazy_compare?(@klass) && lazy_compare?(middleware)
normalize(@klass) == normalize(middleware)
else
klass == ActiveSupport::Inflector.constantize(middleware.to_s)
end
end
end
......@@ -72,6 +76,14 @@ def build(app)
end
private
def lazy_compare?(object)
object.is_a?(String) || object.is_a?(Symbol)
end
def normalize(object)
object.to_s.strip.sub(/^::/, '')
end
def build_args
Array(args).map { |arg| arg.respond_to?(:call) ? arg.call : arg }
end
......
......@@ -87,4 +87,10 @@ def setup
end
assert_equal [:foo], @stack.last.send(:build_args)
end
test "lazy compares so unloaded constants can be loaded" do
@stack.use "UnknownMiddleware"
@stack.use :"MiddlewareStackTest::BazMiddleware"
assert @stack.include?("::MiddlewareStackTest::BazMiddleware")
end
end
......@@ -49,9 +49,9 @@ class Railtie < Rails::Railtie
# Setup database middleware after initializers have run
initializer "active_record.initialize_database_middleware" do |app|
middleware = app.config.middleware
if middleware.include?(ActiveRecord::SessionStore)
middleware.insert_before ActiveRecord::SessionStore, ActiveRecord::ConnectionAdapters::ConnectionManagement
middleware.insert_before ActiveRecord::SessionStore, ActiveRecord::QueryCache
if middleware.include?("ActiveRecord::SessionStore")
middleware.insert_before "ActiveRecord::SessionStore", ActiveRecord::ConnectionAdapters::ConnectionManagement
middleware.insert_before "ActiveRecord::SessionStore", ActiveRecord::QueryCache
else
middleware.use ActiveRecord::ConnectionAdapters::ConnectionManagement
middleware.use ActiveRecord::QueryCache
......
......@@ -76,6 +76,10 @@ module Bootstrap
initializer :initialize_dependency_mechanism do |app|
ActiveSupport::Dependencies.mechanism = app.config.cache_classes ? :require : :load
end
initializer :bootstrap_load_path do
# This is just an initializer used as hook so all load paths are loaded together
end
end
end
end
\ No newline at end of file
......@@ -47,7 +47,7 @@ def load_tasks
end
# Add configured load paths to ruby load paths and remove duplicates.
initializer :set_load_path do
initializer :set_load_path, :before => :bootstrap_load_path do
config.load_paths.reverse_each do |path|
$LOAD_PATH.unshift(path) if File.directory?(path)
end
......@@ -56,7 +56,7 @@ def load_tasks
# Set the paths from which Rails will automatically load source files,
# and the load_once paths.
initializer :set_autoload_paths do |app|
initializer :set_autoload_paths, :before => :bootstrap_load_path do |app|
ActiveSupport::Dependencies.load_paths.unshift(*config.load_paths)
if reloadable?(app)
......
......@@ -48,6 +48,7 @@ def app
RUBY
boot_rails
assert $foo
end
test "plugin paths get added to the AS::Dependency list" do
......@@ -252,26 +253,6 @@ def self.call(env)
assert_equal "FooMetal", last_response.body
end
test "use plugin middleware in application config" do
plugin "foo" do |plugin|
plugin.write "lib/foo.rb", <<-RUBY
class Foo
def initialize(app)
@app = app
end
def call(env)
@app.call(env)
end
end
RUBY
end
add_to_config "config.middleware.use :Foo"
boot_rails
end
test "namespaced controllers with namespaced routes" do
@plugin.write "config/routes.rb", <<-RUBY
ActionController::Routing::Routes.draw do
......@@ -332,6 +313,23 @@ class Engine < Rails::Engine
assert rescued, "Expected boot rails to fail"
end
test "use plugin middleware in application config" do
@plugin.write "lib/bukkits.rb", <<-RUBY
class Bukkits
def initialize(app)
@app = app
end
def call(env)
@app.call(env)
end
end
RUBY
add_to_config "config.middleware.use \"Bukkits\""
boot_rails
end
end
class VendoredOrderingTest < Test::Unit::TestCase
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册