Methods
H
P
R
T
U
Included Modules
Attributes
[RW] controller

In a few cases, the helper proxies to 'controller' or request.

In those cases, we'll set up a simple mock

[RW] request

In a few cases, the helper proxies to 'controller' or request.

In those cases, we'll set up a simple mock

Instance Public methods
hash_for(opts = [])
Also aliased as: url_hash
# File actionpack/test/template/url_helper_test.rb, line 30
def hash_for(opts = [])
  ActiveSupport::OrderedHash[*([:controller, "foo", :action, "bar"].concat(opts))]
end
protect_against_forgery?()

TODO: button_to looks at this … why?

# File actionpack/test/template/url_helper_test.rb, line 449
def protect_against_forgery?
  false
end
request_for_url(url, opts = {})
# File actionpack/test/template/url_helper_test.rb, line 321
def request_for_url(url, opts = {})
  env = Rack::MockRequest.env_for("http://www.example.com#{url}", opts)
  ActionDispatch::Request.new(env)
end
test_button_to_enabled_disabled()
# File actionpack/test/template/url_helper_test.rb, line 121
def test_button_to_enabled_disabled
  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", :disabled => false)
  )
  assert_dom_equal(
    "<form method=\"post\" action=\"http://www.example.com\" class=\"button_to\"><div><input disabled=\"disabled\" type=\"submit\" value=\"Hello\" /></div></form>",
    button_to("Hello", "http://www.example.com", :disabled => true)
  )
end
test_button_to_with_form_class()
# File actionpack/test/template/url_helper_test.rb, line 56
def test_button_to_with_form_class
  assert_dom_equal "<form method=\"post\" action=\"http://www.example.com\" class=\"custom-class\"><div><input type=\"submit\" value=\"Hello\" /></div></form>", button_to("Hello", "http://www.example.com", :form_class => 'custom-class')
end
test_button_to_with_form_class_escapes()
# File actionpack/test/template/url_helper_test.rb, line 60
def test_button_to_with_form_class_escapes
  assert_dom_equal "<form method=\"post\" action=\"http://www.example.com\" class=\"&lt;script&gt;evil_js&lt;/script&gt;\"><div><input type=\"submit\" value=\"Hello\" /></div></form>", button_to("Hello", "http://www.example.com", :form_class => '<script>evil_js</script>')
end
test_button_to_with_html_safe_URL()
# File actionpack/test/template/url_helper_test.rb, line 68
def test_button_to_with_html_safe_URL
  assert_dom_equal "<form method=\"post\" action=\"http://www.example.com/q1=v1&amp;q2=v2\" class=\"button_to\"><div><input type=\"submit\" value=\"Hello\" /></div></form>", button_to("Hello", "http://www.example.com/q1=v1&amp;q2=v2".html_safe)
end
test_button_to_with_javascript_confirm()
# File actionpack/test/template/url_helper_test.rb, line 76
def test_button_to_with_javascript_confirm
  assert_dom_equal(
    "<form method=\"post\" action=\"http://www.example.com\" class=\"button_to\"><div><input data-confirm=\"Are you sure?\" type=\"submit\" value=\"Hello\" /></div></form>",
    button_to("Hello", "http://www.example.com", :confirm => "Are you sure?")
  )
end
test_button_to_with_javascript_disable_with()
# File actionpack/test/template/url_helper_test.rb, line 83
def test_button_to_with_javascript_disable_with
  assert_dom_equal(
    "<form method=\"post\" action=\"http://www.example.com\" class=\"button_to\"><div><input data-disable-with=\"Greeting...\" type=\"submit\" value=\"Hello\" /></div></form>",
    button_to("Hello", "http://www.example.com", :disable_with => "Greeting...")
  )
end
test_button_to_with_method_delete()
# File actionpack/test/template/url_helper_test.rb, line 132
def test_button_to_with_method_delete
  assert_dom_equal(
    "<form method=\"post\" action=\"http://www.example.com\" class=\"button_to\"><div><input type=\"hidden\" name=\"_method\" value=\"delete\" /><input type=\"submit\" value=\"Hello\" /></div></form>",
    button_to("Hello", "http://www.example.com", :method => :delete)
  )
end
test_button_to_with_method_get()
# File actionpack/test/template/url_helper_test.rb, line 139
def test_button_to_with_method_get
  assert_dom_equal(
    "<form method=\"get\" action=\"http://www.example.com\" class=\"button_to\"><div><input type=\"submit\" value=\"Hello\" /></div></form>",
    button_to("Hello", "http://www.example.com", :method => :get)
  )
end
test_button_to_with_query()
# File actionpack/test/template/url_helper_test.rb, line 64
def test_button_to_with_query
  assert_dom_equal "<form method=\"post\" action=\"http://www.example.com/q1=v1&amp;q2=v2\" class=\"button_to\"><div><input type=\"submit\" value=\"Hello\" /></div></form>", button_to("Hello", "http://www.example.com/q1=v1&q2=v2")
end
test_button_to_with_query_and_no_name()
# File actionpack/test/template/url_helper_test.rb, line 72
def test_button_to_with_query_and_no_name
  assert_dom_equal "<form method=\"post\" action=\"http://www.example.com?q1=v1&amp;q2=v2\" class=\"button_to\"><div><input type=\"submit\" value=\"http://www.example.com?q1=v1&amp;q2=v2\" /></div></form>", button_to(nil, "http://www.example.com?q1=v1&q2=v2")
end
test_button_to_with_remote_and_form_options()
# File actionpack/test/template/url_helper_test.rb, line 90
def test_button_to_with_remote_and_form_options
  assert_dom_equal "<form method=\"post\" action=\"http://www.example.com\" class=\"custom-class\" data-remote=\"true\" data-type=\"json\"><div><input type=\"submit\" value=\"Hello\" /></div></form>", button_to("Hello", "http://www.example.com", :remote => true, :form => { :class => "custom-class", "data-type" => "json" } )
end
test_button_to_with_remote_and_javascript_confirm()
# File actionpack/test/template/url_helper_test.rb, line 94
def test_button_to_with_remote_and_javascript_confirm
  assert_dom_equal(
    "<form method=\"post\" action=\"http://www.example.com\" class=\"button_to\" data-remote=\"true\"><div><input data-confirm=\"Are you sure?\" type=\"submit\" value=\"Hello\" /></div></form>",
    button_to("Hello", "http://www.example.com", :remote => true, :confirm => "Are you sure?")
  )
end
test_button_to_with_remote_and_javascript_confirm_and_javascript_disable_with()
# File actionpack/test/template/url_helper_test.rb, line 107
def test_button_to_with_remote_and_javascript_confirm_and_javascript_disable_with
  assert_dom_equal(
    "<form method=\"post\" action=\"http://www.example.com\" class=\"button_to\" data-remote=\"true\"><div><input data-disable-with=\"Greeting...\" data-confirm=\"Are you sure?\" type=\"submit\" value=\"Hello\" /></div></form>",
    button_to("Hello", "http://www.example.com", :remote => true, :confirm => "Are you sure?", :disable_with => "Greeting...")
  )
end
test_button_to_with_remote_and_javascript_disable_with()
# File actionpack/test/template/url_helper_test.rb, line 100
def test_button_to_with_remote_and_javascript_disable_with
  assert_dom_equal(
    "<form method=\"post\" action=\"http://www.example.com\" class=\"button_to\" data-remote=\"true\"><div><input data-disable-with=\"Greeting...\" type=\"submit\" value=\"Hello\" /></div></form>",
    button_to("Hello", "http://www.example.com", :remote => true, :disable_with => "Greeting...")
  )
end
test_button_to_with_remote_false()
# File actionpack/test/template/url_helper_test.rb, line 114
def test_button_to_with_remote_false
  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", :remote => false)
  )
end
test_button_to_with_straight_url()

todo: missing test cases

# File actionpack/test/template/url_helper_test.rb, line 52
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")
end
test_current_page_ignoring_params()
# File actionpack/test/template/url_helper_test.rb, line 332
def test_current_page_ignoring_params
  @request = request_for_url("/?order=desc&page=1")

  assert current_page?(url_hash)
  assert current_page?("http://www.example.com/")
end
test_current_page_with_not_get_verb()
# File actionpack/test/template/url_helper_test.rb, line 346
def test_current_page_with_not_get_verb
  @request = request_for_url("/events", :method => :post)

  assert !current_page?('/events')
end
test_current_page_with_params_that_match()
# File actionpack/test/template/url_helper_test.rb, line 339
def test_current_page_with_params_that_match
  @request = request_for_url("/?order=desc&page=1")

  assert current_page?(hash_for([:order, "desc", :page, "1"]))
  assert current_page?("http://www.example.com/?order=desc&page=1")
end
test_current_page_with_simple_url()
# File actionpack/test/template/url_helper_test.rb, line 326
def test_current_page_with_simple_url
  @request = request_for_url("/")
  assert current_page?(url_hash)
  assert current_page?("http://www.example.com/")
end
test_link_tag_using_post_javascript()
# File actionpack/test/template/url_helper_test.rb, line 236
def test_link_tag_using_post_javascript
  assert_dom_equal(
    "<a href='http://www.example.com' data-method=\"post\" rel=\"nofollow\">Hello</a>",
    link_to("Hello", "http://www.example.com", :method => :post)
  )
end
test_link_tag_using_post_javascript_and_confirm()
# File actionpack/test/template/url_helper_test.rb, line 264
def test_link_tag_using_post_javascript_and_confirm
  assert_dom_equal(
    "<a href=\"http://www.example.com\" data-method=\"post\" rel=\"nofollow\" data-confirm=\"Are you serious?\">Hello</a>",
    link_to("Hello", "http://www.example.com", :method => :post, :confirm => "Are you serious?")
  )
end
test_link_tag_using_post_javascript_and_rel()
# File actionpack/test/template/url_helper_test.rb, line 257
def test_link_tag_using_post_javascript_and_rel
  assert_dom_equal(
    "<a href='http://www.example.com' data-method=\"post\" rel=\"example nofollow\">Hello</a>",
    link_to("Hello", "http://www.example.com", :method => :post, :rel => 'example')
  )
end
test_mail_to()
# File actionpack/test/template/url_helper_test.rb, line 395
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")
  assert_dom_equal(
    "<a class=\"admin\" href=\"mailto:david@loudthinking.com\">David Heinemeier Hansson</a>",
    mail_to("david@loudthinking.com", "David Heinemeier Hansson", "class" => "admin")
  )
  assert_equal mail_to("david@loudthinking.com", "David Heinemeier Hansson", "class" => "admin"),
               mail_to("david@loudthinking.com", "David Heinemeier Hansson", :class => "admin")
end
test_mail_to_returns_html_safe_string()
# File actionpack/test/template/url_helper_test.rb, line 442
def test_mail_to_returns_html_safe_string
  assert mail_to("david@loudthinking.com").html_safe?
  assert mail_to("me@domain.com", "My email", :encode => "javascript").html_safe?
  assert mail_to("me@domain.com", "My email", :encode => "hex").html_safe?
end
test_mail_to_with_hex()
# File actionpack/test/template/url_helper_test.rb, line 428
def test_mail_to_with_hex
  assert_dom_equal "<a href=\"&#109;&#97;&#105;&#108;&#116;&#111;&#58;%6d%65@%64%6f%6d%61%69%6e.%63%6f%6d\">My email</a>", mail_to("me@domain.com", "My email", :encode => "hex")
  assert_dom_equal "<a href=\"&#109;&#97;&#105;&#108;&#116;&#111;&#58;%6d%65@%64%6f%6d%61%69%6e.%63%6f%6d\">&#109;&#101;&#64;&#100;&#111;&#109;&#97;&#105;&#110;&#46;&#99;&#111;&#109;</a>", mail_to("me@domain.com", nil, :encode => "hex")
end
test_mail_to_with_img()
# File actionpack/test/template/url_helper_test.rb, line 423
def test_mail_to_with_img
  assert_dom_equal %Q(<a href="mailto:feedback@example.com"><img src="/feedback.png" /></a>),
    mail_to('feedback@example.com', '<img src="/feedback.png" />'.html_safe)
end
test_mail_to_with_javascript()
# File actionpack/test/template/url_helper_test.rb, line 406
def test_mail_to_with_javascript
  snippet = mail_to("me@domain.com", "My email", :encode => "javascript")
  assert_dom_equal "<script type=\"text/javascript\">eval(decodeURIComponent('%64%6f%63%75%6d%65%6e%74%2e%77%72%69%74%65%28%27%3c%61%20%68%72%65%66%3d%5c%22%6d%61%69%6c%74%6f%3a%6d%65%40%64%6f%6d%61%69%6e%2e%63%6f%6d%5c%22%3e%4d%79%20%65%6d%61%69%6c%3c%5c%2f%61%3e%27%29%3b'))</script>", snippet
end
test_mail_to_with_javascript_unicode()
# File actionpack/test/template/url_helper_test.rb, line 411
def test_mail_to_with_javascript_unicode
  snippet = mail_to("unicode@example.com", "únicode", :encode => "javascript")
  assert_dom_equal "<script type=\"text/javascript\">eval(decodeURIComponent('%64%6f%63%75%6d%65%6e%74%2e%77%72%69%74%65%28%27%3c%61%20%68%72%65%66%3d%5c%22%6d%61%69%6c%74%6f%3a%75%6e%69%63%6f%64%65%40%65%78%61%6d%70%6c%65%2e%63%6f%6d%5c%22%3e%c3%ba%6e%69%63%6f%64%65%3c%5c%2f%61%3e%27%29%3b'))</script>", snippet
end
test_mail_to_with_replace_options()
# File actionpack/test/template/url_helper_test.rb, line 433
def test_mail_to_with_replace_options
  assert_dom_equal "<a href=\"mailto:wolfgang@stufenlos.net\">wolfgang(at)stufenlos(dot)net</a>", mail_to("wolfgang@stufenlos.net", nil, :replace_at => "(at)", :replace_dot => "(dot)")
  assert_dom_equal "<a href=\"&#109;&#97;&#105;&#108;&#116;&#111;&#58;%6d%65@%64%6f%6d%61%69%6e.%63%6f%6d\">&#109;&#101;&#40;&#97;&#116;&#41;&#100;&#111;&#109;&#97;&#105;&#110;&#46;&#99;&#111;&#109;</a>", mail_to("me@domain.com", nil, :encode => "hex", :replace_at => "(at)")
  assert_dom_equal "<a href=\"&#109;&#97;&#105;&#108;&#116;&#111;&#58;%6d%65@%64%6f%6d%61%69%6e.%63%6f%6d\">My email</a>", mail_to("me@domain.com", "My email", :encode => "hex", :replace_at => "(at)")
  assert_dom_equal "<a href=\"&#109;&#97;&#105;&#108;&#116;&#111;&#58;%6d%65@%64%6f%6d%61%69%6e.%63%6f%6d\">&#109;&#101;&#40;&#97;&#116;&#41;&#100;&#111;&#109;&#97;&#105;&#110;&#40;&#100;&#111;&#116;&#41;&#99;&#111;&#109;</a>", mail_to("me@domain.com", nil, :encode => "hex", :replace_at => "(at)", :replace_dot => "(dot)")
  assert_dom_equal "<script type=\"text/javascript\">eval(decodeURIComponent('%64%6f%63%75%6d%65%6e%74%2e%77%72%69%74%65%28%27%3c%61%20%68%72%65%66%3d%5c%22%6d%61%69%6c%74%6f%3a%6d%65%40%64%6f%6d%61%69%6e%2e%63%6f%6d%5c%22%3e%4d%79%20%65%6d%61%69%6c%3c%5c%2f%61%3e%27%29%3b'))</script>", mail_to("me@domain.com", "My email", :encode => "javascript", :replace_at => "(at)", :replace_dot => "(dot)")
  assert_dom_equal "<script type=\"text/javascript\">eval(decodeURIComponent('%64%6f%63%75%6d%65%6e%74%2e%77%72%69%74%65%28%27%3c%61%20%68%72%65%66%3d%5c%22%6d%61%69%6c%74%6f%3a%6d%65%40%64%6f%6d%61%69%6e%2e%63%6f%6d%5c%22%3e%6d%65%28%61%74%29%64%6f%6d%61%69%6e%28%64%6f%74%29%63%6f%6d%3c%5c%2f%61%3e%27%29%3b'))</script>", mail_to("me@domain.com", nil, :encode => "javascript", :replace_at => "(at)", :replace_dot => "(dot)")
end
test_mail_with_options()
# File actionpack/test/template/url_helper_test.rb, line 416
def test_mail_with_options
  assert_dom_equal(
    %Q(<a href="mailto:me@example.com?cc=ccaddress%40example.com&amp;bcc=bccaddress%40example.com&amp;body=This%20is%20the%20body%20of%20the%20message.&amp;subject=This%20is%20an%20example%20email">My email</a>),
    mail_to("me@example.com", "My email", :cc => "ccaddress@example.com", :bcc => "bccaddress@example.com", :subject => "This is an example email", :body => "This is the body of the message.")
  )
end
test_url_for_does_not_escape_urls()
# File actionpack/test/template/url_helper_test.rb, line 35
def test_url_for_does_not_escape_urls
  assert_equal "/?a=b&c=d", url_for(hash_for([:a, :b, :c, :d]))
end
test_url_for_with_back()
# File actionpack/test/template/url_helper_test.rb, line 39
def test_url_for_with_back
  referer = 'http://www.example.com/referer'
  @controller = Struct.new(:request).new(Struct.new(:env).new({"HTTP_REFERER" => referer}))

  assert_equal 'http://www.example.com/referer', url_for(:back)
end
test_url_for_with_back_and_no_referer()
# File actionpack/test/template/url_helper_test.rb, line 46
def test_url_for_with_back_and_no_referer
  @controller = Struct.new(:request).new(Struct.new(:env).new({}))
  assert_equal 'javascript:history.back()', url_for(:back)
end
url_hash(opts = [])
Alias for: hash_for