Permalink
Browse files

Define ActiveSupport#to_param as to_str - closes #1663

  • Loading branch information...
1 parent e51b8fb commit c1938d16fd09ff5addb0bd071fd483559e1cbbbc @pixeltrix pixeltrix committed Jun 12, 2011
@@ -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 @@ def test_link_tag_using_block_in_erb
assert_equal '<a href="/">Example site</a>', out
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
assert_equal "Showing", link_to_unless(true, "Showing", url_hash)
@@ -103,6 +103,10 @@ def to_s
self
end
+ def to_param
+ to_str
+ end
+
def encode_with(coder)
coder.represent_scalar nil, to_str
end
@@ -251,7 +251,7 @@ def test_string_squish
# 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 @@ def to_s
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

0 comments on commit c1938d1

Please sign in to comment.