1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Define ActiveSupport#to_param as to_str - closes #1663

This commit is contained in:
Andrew White 2011-06-12 15:03:24 +01:00
parent cd99784d99
commit 1fa059cd01
3 changed files with 19 additions and 1 deletions

View file

@ -15,6 +15,7 @@ class UrlHelperTest < ActiveSupport::TestCase
routes.draw do routes.draw do
match "/" => "foo#bar" match "/" => "foo#bar"
match "/other" => "foo#other" match "/other" => "foo#other"
match "/article/:id" => "foo#article", :as => :article
end end
include routes.url_helpers include routes.url_helpers
@ -264,6 +265,13 @@ class UrlHelperTest < ActiveSupport::TestCase
assert_equal '<a href="/">Example site</a>', out assert_equal '<a href="/">Example site</a>', out
end end
def test_link_tag_with_html_safe_string
assert_dom_equal(
"<a href=\"/article/Gerd_M%C3%BCller\">Gerd Müller</a>",
link_to("Gerd Müller", article_path("Gerd_Müller".html_safe))
)
end
def test_link_to_unless def test_link_to_unless
assert_equal "Showing", link_to_unless(true, "Showing", url_hash) assert_equal "Showing", link_to_unless(true, "Showing", url_hash)

View file

@ -103,6 +103,10 @@ module ActiveSupport #:nodoc:
self self
end end
def to_param
to_str
end
def encode_with(coder) def encode_with(coder)
coder.represent_scalar nil, to_str coder.represent_scalar nil, to_str
end end

View file

@ -451,6 +451,12 @@ class OutputSafetyTest < ActiveSupport::TestCase
assert !'ruby'.encoding_aware? assert !'ruby'.encoding_aware?
end end
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 end
class StringExcludeTest < ActiveSupport::TestCase class StringExcludeTest < ActiveSupport::TestCase