diff options
Diffstat (limited to 'actionpack/test/template')
-rw-r--r-- | actionpack/test/template/url_helper_test.rb | 32 |
1 files changed, 21 insertions, 11 deletions
diff --git a/actionpack/test/template/url_helper_test.rb b/actionpack/test/template/url_helper_test.rb index 85ce24b1c2..95b9373c7f 100644 --- a/actionpack/test/template/url_helper_test.rb +++ b/actionpack/test/template/url_helper_test.rb @@ -13,13 +13,20 @@ class UrlHelperTest < Test::Unit::TestCase def setup @controller = Class.new do + attr_accessor :url def url_for(options, *parameters_for_method_reference) - "http://www.example.com" + url end end @controller = @controller.new + @controller.url = "http://www.example.com" end - + + def test_url_for_escapes_urls + @controller.url = "http://www.example.com?a=b&c=d" + assert_equal "http://www.example.com?a=b&c=d", url_for(:a => 'b', :c => 'd') + end + # todo: missing test cases def test_button_to_with_straight_url assert_dom_equal "<form method=\"post\" action=\"http://www.example.com\" class=\"button-to\"><div><input type=\"submit\" value=\"Hello\" /></div></form>", button_to("Hello", "http://www.example.com") @@ -56,17 +63,25 @@ class UrlHelperTest < Test::Unit::TestCase end def test_link_tag_with_query - assert_dom_equal "<a href=\"http://www.example.com?q1=v1&q2=v2\">Hello</a>", link_to("Hello", "http://www.example.com?q1=v1&q2=v2") + assert_dom_equal "<a href=\"http://www.example.com?q1=v1&q2=v2\">Hello</a>", link_to("Hello", "http://www.example.com?q1=v1&q2=v2") end def test_link_tag_with_query_and_no_name - assert_dom_equal "<a href=\"http://www.example.com?q1=v1&q2=v2\">http://www.example.com?q1=v1&q2=v2</a>", link_to(nil, "http://www.example.com?q1=v1&q2=v2") + assert_dom_equal "<a href=\"http://www.example.com?q1=v1&q2=v2\">http://www.example.com?q1=v1&q2=v2</a>", link_to(nil, "http://www.example.com?q1=v1&q2=v2") + end + + def test_link_tag_with_img + assert_dom_equal "<a href=\"http://www.example.com\"><img src='/favicon.jpg' /></a>", link_to("<img src='/favicon.jpg' />", "http://www.example.com") + end + + def test_link_with_nil_html_options + assert_dom_equal "<a href=\"http://www.example.com\">Hello</a>", link_to("Hello", {:action => 'myaction'}, nil) end def test_link_tag_with_custom_onclick assert_dom_equal "<a href=\"http://www.example.com\" onclick=\"alert('yay!')\">Hello</a>", link_to("Hello", "http://www.example.com", :onclick => "alert('yay!')") end - + def test_link_tag_with_javascript_confirm assert_dom_equal( "<a href=\"http://www.example.com\" onclick=\"return confirm('Are you sure?');\">Hello</a>", @@ -147,7 +162,6 @@ class UrlHelperTest < Test::Unit::TestCase assert_equal "Showing", link_to_if(false, "Showing", :action => "show", :controller => "weblog", :id => 1) end - def xtest_link_unless_current @request = RequestMock.new("http://www.example.com") assert_equal "Showing", link_to_unless_current("Showing", :action => "show", :controller => "weblog") @@ -157,7 +171,7 @@ class UrlHelperTest < Test::Unit::TestCase @request = RequestMock.new("http://www.example.com") assert_equal "Showing", link_to_unless_current("Showing", :action => "show", :controller => "weblog", :id => 1) end - + def test_mail_to assert_dom_equal "<a href=\"mailto:david@loudthinking.com\">david@loudthinking.com</a>", mail_to("david@loudthinking.com") assert_dom_equal "<a href=\"mailto:david@loudthinking.com\">David Heinemeier Hansson</a>", mail_to("david@loudthinking.com", "David Heinemeier Hansson") @@ -191,8 +205,4 @@ class UrlHelperTest < Test::Unit::TestCase assert_dom_equal "<a href=\"mailto:%6d%65@%64%6f%6d%61%69%6e.%63%6f%6d\">me(at)domain(dot)com</a>", mail_to("me@domain.com", nil, :encode => "hex", :replace_at => "(at)", :replace_dot => "(dot)") assert_dom_equal "<script type=\"text/javascript\">eval(unescape('%64%6f%63%75%6d%65%6e%74%2e%77%72%69%74%65%28%27%3c%61%20%68%72%65%66%3d%22%6d%61%69%6c%74%6f%3a%6d%65%40%64%6f%6d%61%69%6e%2e%63%6f%6d%22%3e%4d%79%20%65%6d%61%69%6c%3c%2f%61%3e%27%29%3b'))</script>", mail_to("me@domain.com", "My email", :encode => "javascript", :replace_at => "(at)", :replace_dot => "(dot)") end - - def test_link_with_nil_html_options - assert_dom_equal "<a href=\"http://www.example.com\">Hello</a>", link_to("Hello", {:action => 'myaction'}, nil) - end end |