mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Merge pull request #31261 from rails/fix-relative-url-root-with-optimized-url-helpers
Fix optimized url helpers when using relative url root
This commit is contained in:
commit
076d1621bb
3 changed files with 54 additions and 0 deletions
|
@ -1,3 +1,10 @@
|
||||||
|
* Fix optimized url helpers when using relative url root
|
||||||
|
|
||||||
|
Fixes #31220.
|
||||||
|
|
||||||
|
*Andrew White*
|
||||||
|
|
||||||
|
|
||||||
## Rails 5.2.0.beta1 (November 27, 2017) ##
|
## Rails 5.2.0.beta1 (November 27, 2017) ##
|
||||||
|
|
||||||
* Add DSL for configuring Content-Security-Policy header
|
* Add DSL for configuring Content-Security-Policy header
|
||||||
|
|
|
@ -199,6 +199,16 @@ module ActionDispatch
|
||||||
if args.size == arg_size && !inner_options && optimize_routes_generation?(t)
|
if args.size == arg_size && !inner_options && optimize_routes_generation?(t)
|
||||||
options = t.url_options.merge @options
|
options = t.url_options.merge @options
|
||||||
options[:path] = optimized_helper(args)
|
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
|
url_strategy.call options
|
||||||
else
|
else
|
||||||
super
|
super
|
||||||
|
|
|
@ -5057,3 +5057,40 @@ class TestRecognizePath < ActionDispatch::IntegrationTest
|
||||||
Routes.recognize_path(*args)
|
Routes.recognize_path(*args)
|
||||||
end
|
end
|
||||||
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
|
||||||
|
|
Loading…
Reference in a new issue