提交 e9b77953 编写于 作者: A Andrew White

Fix optimized url helpers when using relative url root

Fixes #31220.

(cherry picked from commit 00c0e400)
上级 350f7890
* Fix optimized url helpers when using relative url root
Fixes #31220.
*Andrew White*
* Ensure dev and prod puma configs do not clobber `ActionDispatch::SystemTesting` defaults. Adds workers: 0 and daemon: false
*Max Schwenk*
......
......@@ -203,6 +203,16 @@ def call(t, args, inner_options)
if args.size == arg_size && !inner_options && optimize_routes_generation?(t)
options = t.url_options.merge @options
options[:path] = optimized_helper(args)
original_script_name = options.delete(:original_script_name)
script_name = t._routes.find_script_name(options)
if original_script_name
script_name = original_script_name + script_name
end
options[:script_name] = script_name
url_strategy.call options
else
super
......
......@@ -5051,3 +5051,40 @@ def recognize_path(*args)
Routes.recognize_path(*args)
end
end
class TestRelativeUrlRootGeneration < ActionDispatch::IntegrationTest
config = ActionDispatch::Routing::RouteSet::Config.new("/blog", false)
stub_controllers(config) do |routes|
Routes = routes
routes.draw do
get "/", to: "posts#index", as: :posts
get "/:id", to: "posts#show", as: :post
end
end
include Routes.url_helpers
APP = build_app Routes
def app
APP
end
def test_url_helpers
assert_equal "/blog/", posts_path({})
assert_equal "/blog/", Routes.url_helpers.posts_path({})
assert_equal "/blog/1", post_path(id: "1")
assert_equal "/blog/1", Routes.url_helpers.post_path(id: "1")
end
def test_optimized_url_helpers
assert_equal "/blog/", posts_path
assert_equal "/blog/", Routes.url_helpers.posts_path
assert_equal "/blog/1", post_path("1")
assert_equal "/blog/1", Routes.url_helpers.post_path("1")
end
end
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册