提交 2135daf0 编写于 作者: R Rafael França 提交者: Rafael Mendonça França

Merge pull request #29503 from savroff/fix_current_page_engine_issue

Fix current_page? helper issue with engine root path
上级 1c7ad55c
* Fix issues with scopes and engine on `current_page?` method.
Fixes #29401.
*Nikita Savrov*
* Generate field ids in `collection_check_boxes` and `collection_radio_buttons`.
This makes sure that the labels are linked up with the fields.
......
......@@ -552,7 +552,10 @@ def current_page?(options, check_parameters: false)
request_uri = url_string.index("?") || check_parameters ? request.fullpath : request.path
request_uri = URI.parser.unescape(request_uri).force_encoding(Encoding::BINARY)
url_string.chomp!("/") if url_string.start_with?("/") && url_string != "/"
if url_string.start_with?("/") && url_string != "/"
url_string.chomp!("/")
request_uri.chomp!("/")
end
if %r{^\w+://}.match?(url_string)
url_string == "#{request.protocol}#{request.host_with_port}#{request_uri}"
......
......@@ -16,6 +16,10 @@ class UrlHelperTest < ActiveSupport::TestCase
get "/other" => "foo#other"
get "/article/:id" => "foo#article", :as => :article
get "/category/:category" => "foo#category"
scope :engine do
get "/" => "foo#bar"
end
end
include ActionView::Helpers::UrlHelper
......@@ -522,10 +526,10 @@ def test_current_page_with_params_that_match
assert current_page?("http://www.example.com/?order=desc&page=1")
end
def test_current_page_with_not_get_verb
@request = request_for_url("/events", method: :post)
def test_current_page_with_scope_that_match
@request = request_for_url("/engine/")
assert !current_page?("/events")
assert current_page?("/engine")
end
def test_current_page_with_escaped_params
......@@ -554,6 +558,12 @@ def test_current_page_with_trailing_slash
assert current_page?("/posts/")
end
def test_current_page_with_not_get_verb
@request = request_for_url("/events", method: :post)
assert !current_page?("/events")
end
def test_link_unless_current
@request = request_for_url("/")
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册