Skip to content

Commit

Permalink
Define ActiveSupport#to_param as to_str - closes rails#1663
Browse files Browse the repository at this point in the history
  • Loading branch information
pixeltrix committed Jun 12, 2011
1 parent cd99784 commit 1fa059c
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
8 changes: 8 additions & 0 deletions actionpack/test/template/url_helper_test.rb
Expand Up @@ -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
Expand Down Expand Up @@ -264,6 +265,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)

Expand Down
Expand Up @@ -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
Expand Down
8 changes: 7 additions & 1 deletion activesupport/test/core_ext/string_ext_test.rb
Expand Up @@ -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?
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 1fa059c

Please sign in to comment.