diff options
author | Edouard CHIN <edouard.chin@shopify.com> | 2017-04-23 22:20:55 -0400 |
---|---|---|
committer | Edouard CHIN <edouard.chin@shopify.com> | 2017-04-26 15:36:30 -0400 |
commit | 615fd399cd3c0e2f10874f21af89ac584dd0a0ba (patch) | |
tree | 6215b1e730d68b29a6e11474919fccb17833758d /actionview | |
parent | 0dd40fe72cfcf53b475a4084d61e9e931417c29e (diff) | |
download | rails-615fd399cd3c0e2f10874f21af89ac584dd0a0ba.tar.gz rails-615fd399cd3c0e2f10874f21af89ac584dd0a0ba.tar.bz2 rails-615fd399cd3c0e2f10874f21af89ac584dd0a0ba.zip |
Fix `current_page?` regression:
- `check_parameters` kwargs was added to the `current_page?` method, the implementation was assuming only hashes responds to `delete`. This was causing issues when `current_page?` was called with a Active Model object
- ref https://github.com/rails/rails/pull/27549
- Fixes #28846
Diffstat (limited to 'actionview')
-rw-r--r-- | actionview/lib/action_view/helpers/url_helper.rb | 2 | ||||
-rw-r--r-- | actionview/test/template/url_helper_test.rb | 18 |
2 files changed, 19 insertions, 1 deletions
diff --git a/actionview/lib/action_view/helpers/url_helper.rb b/actionview/lib/action_view/helpers/url_helper.rb index 70fc57c35f..a6857101b9 100644 --- a/actionview/lib/action_view/helpers/url_helper.rb +++ b/actionview/lib/action_view/helpers/url_helper.rb @@ -542,7 +542,7 @@ module ActionView return false unless request.get? || request.head? - check_parameters ||= !options.is_a?(String) && options.try(:delete, :check_parameters) + check_parameters ||= options.is_a?(Hash) && options.delete(:check_parameters) url_string = URI.parser.unescape(url_for(options)).force_encoding(Encoding::BINARY) # We ignore any extra parameters in the request_uri if the diff --git a/actionview/test/template/url_helper_test.rb b/actionview/test/template/url_helper_test.rb index a6444a1686..fc02ffb7c3 100644 --- a/actionview/test/template/url_helper_test.rb +++ b/actionview/test/template/url_helper_test.rb @@ -509,6 +509,12 @@ class UrlHelperTest < ActiveSupport::TestCase assert !current_page?("http://www.example.com/", check_parameters: true) end + def test_current_page_considering_params_when_options_does_not_respond_to_to_hash + @request = request_for_url("/?order=desc&page=1") + + assert !current_page?(:back, check_parameters: false) + end + def test_current_page_with_params_that_match @request = request_for_url("/?order=desc&page=1") @@ -880,6 +886,11 @@ class WorkshopsController < ActionController::Base @workshop = Workshop.new(params[:id]) render inline: "<%= url_for(@workshop) %>\n<%= link_to('Workshop', @workshop) %>" end + + def edit + @workshop = Workshop.new(params[:id]) + render inline: "<%= current_page?(@workshop) %>" + end end class SessionsController < ActionController::Base @@ -944,4 +955,11 @@ class PolymorphicControllerTest < ActionController::TestCase get :edit, params: { workshop_id: 1, id: 1, format: "json" } assert_equal %{/workshops/1/sessions/1.json\n<a href="/workshops/1/sessions/1.json">Session</a>}, @response.body end + + def test_current_page_when_options_does_not_respond_to_to_hash + @controller = WorkshopsController.new + + get :edit, params: { id: 1 } + assert_equal "false", @response.body + end end |