From 7adf833311e6abd100e6688bfe5e04a18b79fb86 Mon Sep 17 00:00:00 2001 From: Andrew White Date: Sun, 16 Nov 2008 06:09:54 +0000 Subject: [PATCH] Fixed current_page? to work with multiple params in the url --- actionpack/lib/action_view/helpers/url_helper.rb | 2 +- actionpack/test/template/url_helper_test.rb | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletions(-) diff --git a/actionpack/lib/action_view/helpers/url_helper.rb b/actionpack/lib/action_view/helpers/url_helper.rb index 2e0eb87..605688d 100644 --- a/actionpack/lib/action_view/helpers/url_helper.rb +++ b/actionpack/lib/action_view/helpers/url_helper.rb @@ -516,7 +516,7 @@ module ActionView # current_page?(:controller => 'library', :action => 'checkout') # # => false def current_page?(options) - url_string = CGI.escapeHTML(url_for(options)) + url_string = CGI.unescapeHTML(url_for(options)) request = @controller.request # We ignore any extra parameters in the request_uri if the # submitted url doesn't have any either. This lets the function diff --git a/actionpack/test/template/url_helper_test.rb b/actionpack/test/template/url_helper_test.rb index 2f6fa13..f3a9f87 100644 --- a/actionpack/test/template/url_helper_test.rb +++ b/actionpack/test/template/url_helper_test.rb @@ -252,6 +252,27 @@ class UrlHelperTest < ActionView::TestCase assert_equal "Showing", link_to_if(false, "Showing", :action => "show", :controller => "weblog", :id => 1) end + def test_current_page_with_simple_url + @controller.request = RequestMock.new("http://www.example.com/weblog/show") + @controller.url = "http://www.example.com/weblog/show" + assert current_page?({ :action => "show", :controller => "weblog" }) + assert current_page?("http://www.example.com/weblog/show") + end + + def test_current_page_ignoring_params + @controller.request = RequestMock.new("http://www.example.com/weblog/show?order=desc&page=1") + @controller.url = "http://www.example.com/weblog/show?order=desc&page=1" + assert current_page?({ :action => "show", :controller => "weblog" }) + assert current_page?("http://www.example.com/weblog/show") + end + + def test_current_page_with_params_that_match + @controller.request = RequestMock.new("http://www.example.com/weblog/show?order=desc&page=1") + @controller.url = "http://www.example.com/weblog/show?order=desc&page=1" + assert current_page?({ :action => "show", :controller => "weblog", :order => "desc", :page => "1" }) + assert current_page?("http://www.example.com/weblog/show?order=desc&page=1") + end + def test_link_unless_current @controller.request = RequestMock.new("http://www.example.com/weblog/show") @controller.url = "http://www.example.com/weblog/show" -- 1.5.4.5