提交 235e734e 编写于 作者: S schneems

Revert "Merge pull request #33970 from rails/eager-url-helpers"

Until #34050 can be resolved

This reverts commit 7f870a5b, reversing
changes made to 65568988.
上级 ebf98df9
......@@ -7,8 +7,11 @@ def self.with(routes, include_path_helpers = true)
Module.new do
define_method(:inherited) do |klass|
super(klass)
routes.include_helpers klass, include_path_helpers
if namespace = klass.parents.detect { |m| m.respond_to?(:railtie_routes_url_helpers) }
klass.include(namespace.railtie_routes_url_helpers(include_path_helpers))
else
klass.include(routes.url_helpers(include_path_helpers))
end
end
end
end
......
......@@ -676,6 +676,7 @@ def app_name(app, rails_app)
def define_generate_prefix(app, name)
_route = @set.named_routes.get name
_routes = @set
_url_helpers = @set.url_helpers
script_namer = ->(options) do
prefix_options = options.slice(*_route.segment_keys)
......@@ -687,7 +688,7 @@ def define_generate_prefix(app, name)
# We must actually delete prefix segment keys to avoid passing them to next url_for.
_route.segment_keys.each { |k| options.delete(k) }
@set.url_helpers.send("#{name}_path", prefix_options)
_url_helpers.send("#{name}_path", prefix_options)
end
app.routes.define_mounted_helper(name, script_namer)
......
......@@ -458,11 +458,6 @@ def finalize!
return if @finalized
@append.each { |blk| eval_block(blk) }
@finalized = true
@url_helpers = build_url_helper_module true
@deferred_classes.each { |klass, include_path_helpers|
include_helpers klass, include_path_helpers
}
@deferred_classes.clear
end
def clear!
......@@ -491,10 +486,11 @@ def define_mounted_helper(name, script_namer = nil)
return if MountedHelpers.method_defined?(name)
routes = self
helpers = routes.url_helpers
MountedHelpers.class_eval do
define_method "_#{name}" do
RoutesProxy.new(routes, _routes_context, routes.url_helpers, script_namer)
RoutesProxy.new(routes, _routes_context, helpers, script_namer)
end
end
......@@ -505,20 +501,7 @@ def #{name}
RUBY
end
class UnfinalizedRouteSet < StandardError
end
def url_helpers(supports_path = true)
raise UnfinalizedRouteSet, "routes have not been finalized. Please call `finalize!` or use `draw(&block)`" unless @finalized
if supports_path
@url_helpers
else
build_url_helper_module false
end
end
def build_url_helper_module(supports_path)
routes = self
Module.new do
......
......@@ -138,20 +138,6 @@ def assert_routing(path, options, defaults = {}, extras = {}, message = nil)
assert_generates(path.is_a?(Hash) ? path[:path] : path, generate_options, defaults, extras, message)
end
# Provides a hook on `finalize!` so we can mutate a controller after the
# route set has been drawn.
class WithRouting < ActionDispatch::Routing::RouteSet # :nodoc:
def initialize(&block)
super()
@block = block
end
def finalize!
super
@block.call self
end
end
# A helper to make it easier to test different route configurations.
# This method temporarily replaces @routes with a new RouteSet instance.
#
......@@ -166,19 +152,16 @@ def finalize!
# end
#
def with_routing
old_routes = @routes
old_controller = nil
@routes = WithRouting.new do |_routes|
if defined?(@controller) && @controller
old_controller, @controller = @controller, @controller.clone
_routes = @routes
@controller.singleton_class.include(_routes.url_helpers)
if @controller.respond_to? :view_context_class
@controller.view_context_class = Class.new(@controller.view_context_class) do
include _routes.url_helpers
end
old_routes, @routes = @routes, ActionDispatch::Routing::RouteSet.new
if defined?(@controller) && @controller
old_controller, @controller = @controller, @controller.clone
_routes = @routes
@controller.singleton_class.include(_routes.url_helpers)
if @controller.respond_to? :view_context_class
@controller.view_context_class = Class.new(@controller.view_context_class) do
include _routes.url_helpers
end
end
end
......
......@@ -100,10 +100,7 @@ def call(env)
class ActionDispatch::IntegrationTest < ActiveSupport::TestCase
def self.build_app(routes = nil)
routes ||= ActionDispatch::Routing::RouteSet.new.tap { |rs|
rs.draw { }
}
RoutedRackApp.new(routes) do |middleware|
RoutedRackApp.new(routes || ActionDispatch::Routing::RouteSet.new) do |middleware|
middleware.use ActionDispatch::ShowExceptions, ActionDispatch::PublicExceptions.new("#{FIXTURE_LOAD_PATH}/public")
middleware.use ActionDispatch::DebugExceptions
middleware.use ActionDispatch::Callbacks
......
......@@ -542,6 +542,9 @@ def with_default_headers(headers)
def with_test_route_set
with_routing do |set|
controller = ::IntegrationProcessTest::IntegrationController.clone
controller.class_eval do
include set.url_helpers
end
set.draw do
get "moved" => redirect("/method")
......@@ -552,10 +555,6 @@ def with_test_route_set
end
end
controller.class_eval do
include set.url_helpers
end
singleton_class.include(set.url_helpers)
yield
......
......@@ -4,11 +4,6 @@
class IPv6IntegrationTest < ActionDispatch::IntegrationTest
Routes = ActionDispatch::Routing::RouteSet.new
Routes.draw do
get "/", to: "bad_route_request#index", as: :index
get "/foo", to: "bad_route_request#foo", as: :foo
end
include Routes.url_helpers
class ::BadRouteRequestController < ActionController::Base
......@@ -22,6 +17,11 @@ def foo
end
end
Routes.draw do
get "/", to: "bad_route_request#index", as: :index
get "/foo", to: "bad_route_request#foo", as: :foo
end
def _routes
Routes
end
......
......@@ -4,13 +4,16 @@
module TestUrlGeneration
class WithMountPoint < ActionDispatch::IntegrationTest
Routes = ActionDispatch::Routing::RouteSet.new
include Routes.url_helpers
class ::MyRouteGeneratingController < ActionController::Base
include Routes.url_helpers
def index
render plain: foo_path
end
end
Routes = ActionDispatch::Routing::RouteSet.new
Routes.draw do
get "/foo", to: "my_route_generating#index", as: :foo
......@@ -19,10 +22,6 @@ def index
mount MyRouteGeneratingController.action(:index), at: "/bar"
end
class ::MyRouteGeneratingController
include Routes.url_helpers
end
APP = build_app Routes
def _routes
......
......@@ -403,12 +403,6 @@ def isolate_namespace(mod)
define_method(:railtie_helpers_paths) { railtie.helpers_paths }
end
unless mod.respond_to?(:railtie_include_helpers)
define_method(:railtie_include_helpers) { |klass, include_path_helpers|
railtie.routes.include_helpers(klass, include_path_helpers)
}
end
unless mod.respond_to?(:railtie_routes_url_helpers)
define_method(:railtie_routes_url_helpers) { |include_path_helpers = true| railtie.routes.url_helpers(include_path_helpers) }
end
......@@ -479,13 +473,9 @@ def load_generators(app = self)
# files inside eager_load paths.
def eager_load!
config.eager_load_paths.each do |load_path|
if File.file?(load_path)
require_dependency load_path
else
matcher = /\A#{Regexp.escape(load_path.to_s)}\/(.*)\.rb\Z/
Dir.glob("#{load_path}/**/*.rb").sort.each do |file|
require_dependency file.sub(matcher, '\1')
end
matcher = /\A#{Regexp.escape(load_path.to_s)}\/(.*)\.rb\Z/
Dir.glob("#{load_path}/**/*.rb").sort.each do |file|
require_dependency file.sub(matcher, '\1')
end
end
end
......
......@@ -38,7 +38,6 @@ def paths
@paths ||= begin
paths = Rails::Paths::Root.new(@root)
paths.add "config/routes.rb", eager_load: true
paths.add "app", eager_load: true, glob: "{*,*/concerns}"
paths.add "app/assets", glob: "*"
paths.add "app/controllers", eager_load: true
......@@ -56,6 +55,7 @@ def paths
paths.add "config/environments", glob: "#{Rails.env}.rb"
paths.add "config/initializers", glob: "**/*.rb"
paths.add "config/locales", glob: "*.{rb,yml}"
paths.add "config/routes.rb"
paths.add "db"
paths.add "db/migrate"
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册