From c1938d16fd09ff5addb0bd071fd483559e1cbbbc Mon Sep 17 00:00:00 2001 From: Andrew White Date: Sun, 12 Jun 2011 15:03:24 +0100 Subject: [PATCH] Define ActiveSupport#to_param as to_str - closes #1663 --- actionpack/test/template/url_helper_test.rb | 8 ++++++++ .../lib/active_support/core_ext/string/output_safety.rb | 4 ++++ activesupport/test/core_ext/string_ext_test.rb | 8 +++++++- 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/actionpack/test/template/url_helper_test.rb b/actionpack/test/template/url_helper_test.rb index 8d0f0124c2..c5ba9b6ce5 100644 --- a/actionpack/test/template/url_helper_test.rb +++ b/actionpack/test/template/url_helper_test.rb @@ -15,6 +15,7 @@ class UrlHelperTest < ActiveSupport::TestCase routes.draw do match "/" => "foo#bar" match "/other" => "foo#other" + match "/article/:id" => "foo#article", :as => :article end include routes.url_helpers @@ -262,6 +263,13 @@ class UrlHelperTest < ActiveSupport::TestCase assert_equal 'Example site', out end + def test_link_tag_with_html_safe_string + assert_dom_equal( + "Gerd Müller", + link_to("Gerd Müller", article_path("Gerd_Müller".html_safe)) + ) + end + def test_link_to_unless assert_equal "Showing", link_to_unless(true, "Showing", url_hash) diff --git a/activesupport/lib/active_support/core_ext/string/output_safety.rb b/activesupport/lib/active_support/core_ext/string/output_safety.rb index 49694a5030..9b24fc42f1 100644 --- a/activesupport/lib/active_support/core_ext/string/output_safety.rb +++ b/activesupport/lib/active_support/core_ext/string/output_safety.rb @@ -103,6 +103,10 @@ module ActiveSupport #:nodoc: self end + def to_param + to_str + end + def encode_with(coder) coder.represent_scalar nil, to_str end diff --git a/activesupport/test/core_ext/string_ext_test.rb b/activesupport/test/core_ext/string_ext_test.rb index 32675c884a..7a8cda160d 100644 --- a/activesupport/test/core_ext/string_ext_test.rb +++ b/activesupport/test/core_ext/string_ext_test.rb @@ -251,7 +251,7 @@ class StringInflectionsTest < Test::Unit::TestCase # And changes the original string: assert_equal original, expected end - + def test_string_inquiry assert "production".inquiry.production? assert !"production".inquiry.development? @@ -451,6 +451,12 @@ class OutputSafetyTest < ActiveSupport::TestCase assert !'ruby'.encoding_aware? end end + + test "call to_param returns a normal string" do + string = @string.html_safe + assert string.html_safe? + assert !string.to_param.html_safe? + end end class StringExcludeTest < ActiveSupport::TestCase