Fix current_page? with kwargs on ruby3
Prevent raising an error when `options` are given as kwargs, this is done by overriding `options` with kwargs if `options` are `nil`; this implies that if both `options` and kwargs are given, `options` takes precedence. Fixes #41198
This commit is contained in:
parent
1993496d7f
commit
3d76418b9d
@ -541,7 +541,7 @@ def mail_to(email_address, name = nil, html_options = {}, &block)
|
||||
#
|
||||
# We can also pass in the symbol arguments instead of strings.
|
||||
#
|
||||
def current_page?(options, check_parameters: false)
|
||||
def current_page?(options = nil, check_parameters: false, **options_as_kwargs)
|
||||
unless request
|
||||
raise "You cannot use helpers that need to determine the current " \
|
||||
"page unless your view context provides a Request object " \
|
||||
@ -550,6 +550,7 @@ def current_page?(options, check_parameters: false)
|
||||
|
||||
return false unless request.get? || request.head?
|
||||
|
||||
options ||= options_as_kwargs
|
||||
check_parameters ||= options.is_a?(Hash) && options.delete(:check_parameters)
|
||||
url_string = URI::DEFAULT_PARSER.unescape(url_for(options)).force_encoding(Encoding::BINARY)
|
||||
|
||||
|
@ -582,6 +582,12 @@ def test_current_page_considering_params_when_options_does_not_respond_to_to_has
|
||||
assert_not current_page?(:back, check_parameters: false)
|
||||
end
|
||||
|
||||
def test_current_page_when_options_given_as_keyword_arguments
|
||||
@request = request_for_url("/")
|
||||
|
||||
assert current_page?(**url_hash)
|
||||
end
|
||||
|
||||
def test_current_page_with_params_that_match
|
||||
@request = request_for_url("/?order=desc&page=1")
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user