Skip to content

Commit

Permalink
Merge pull request #41206 from intrip/41198-fix-current-page-kwargs
Browse files Browse the repository at this point in the history
Fix current_page? with kwargs on ruby3
  • Loading branch information
kamipo committed Jan 24, 2021
1 parent 1514745 commit ab23ee6
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
3 changes: 2 additions & 1 deletion actionview/lib/action_view/helpers/url_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,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 " \
Expand All @@ -548,6 +548,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)

Expand Down
6 changes: 6 additions & 0 deletions actionview/test/template/url_helper_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -564,6 +564,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")

Expand Down

0 comments on commit ab23ee6

Please sign in to comment.