mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
As first step setup the load path and lazy compare middlewares.
This commit is contained in:
parent
1177a40e68
commit
02908e1142
6 changed files with 46 additions and 26 deletions
|
@ -55,7 +55,11 @@ module ActionDispatch
|
|||
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 @@ module ActionDispatch
|
|||
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 @@ class MiddlewareStackTest < ActiveSupport::TestCase
|
|||
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 @@ module ActiveRecord
|
|||
# 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 Rails
|
|||
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
|
|
@ -47,7 +47,7 @@ module Rails
|
|||
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 @@ module Rails
|
|||
|
||||
# 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 @@ module PluginsTest
|
|||
RUBY
|
||||
|
||||
boot_rails
|
||||
assert $foo
|
||||
end
|
||||
|
||||
test "plugin paths get added to the AS::Dependency list" do
|
||||
|
@ -252,26 +253,6 @@ YAML
|
|||
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 @@ YAML
|
|||
|
||||
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
|
||||
|
|
Loading…
Reference in a new issue