Methods
F
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
form_authenticity_token(*args)
# File actionview/test/template/url_helper_test.rb, line 627
def form_authenticity_token(*args)
  "secret"
end
hash_for(options = {})
Also aliased as: url_hash
# File actionview/test/template/url_helper_test.rb, line 32
def hash_for(options = {})
  { controller: "foo", action: "bar" }.merge!(options)
end
protect_against_forgery?()
# File actionview/test/template/url_helper_test.rb, line 623
def protect_against_forgery?
  self.request_forgery
end
request_for_url(url, opts = {})
# File actionview/test/template/url_helper_test.rb, line 449
def request_for_url(url, opts = {})
  env = Rack::MockRequest.env_for("http://www.example.com#{url}", opts)
  ActionDispatch::Request.new(env)
end
request_forgery_protection_token()
# File actionview/test/template/url_helper_test.rb, line 631
def request_forgery_protection_token
  "form_token"
end
test_button_to_enabled_disabled()
# File actionview/test/template/url_helper_test.rb, line 186
def test_button_to_enabled_disabled
  assert_dom_equal(
    %Q{<form method="post" action="http://www.example.com" class="button_to"><input type="submit" value="Hello" /></form>},
    button_to("Hello", "http://www.example.com", disabled: false)
  )
  assert_dom_equal(
    %Q{<form method="post" action="http://www.example.com" class="button_to"><input disabled="disabled" type="submit" value="Hello" /></form>},
    button_to("Hello", "http://www.example.com", disabled: true)
  )
end
test_button_to_with_block()
# File actionview/test/template/url_helper_test.rb, line 211
def test_button_to_with_block
  assert_dom_equal(
    %Q{<form method="post" action="http://www.example.com" class="button_to"><button type="submit"><span>Hello</span></button></form>},
    button_to("http://www.example.com") { content_tag(:span, 'Hello') }
  )
end
test_button_to_with_form_class()
# File actionview/test/template/url_helper_test.rb, line 124
def test_button_to_with_form_class
  assert_dom_equal %Q{<form method="post" action="http://www.example.com" class="custom-class"><input type="submit" value="Hello" /></form>}, button_to("Hello", "http://www.example.com", form_class: 'custom-class')
end
test_button_to_with_form_class_escapes()
# File actionview/test/template/url_helper_test.rb, line 128
def test_button_to_with_form_class_escapes
  assert_dom_equal %Q{<form method="post" action="http://www.example.com" class="&lt;script&gt;evil_js&lt;/script&gt;"><input type="submit" value="Hello" /></form>}, button_to("Hello", "http://www.example.com", form_class: '<script>evil_js</script>')
end
test_button_to_with_html_safe_URL()
# File actionview/test/template/url_helper_test.rb, line 136
def test_button_to_with_html_safe_URL
  assert_dom_equal %Q{<form method="post" action="http://www.example.com/q1=v1&amp;q2=v2" class="button_to"><input type="submit" value="Hello" /></form>}, button_to("Hello", raw("http://www.example.com/q1=v1&amp;q2=v2"))
end
test_button_to_with_javascript_confirm()
# File actionview/test/template/url_helper_test.rb, line 144
def test_button_to_with_javascript_confirm
  assert_dom_equal(
    %Q{<form method="post" action="http://www.example.com" class="button_to"><input data-confirm="Are you sure?" type="submit" value="Hello" /></form>},
    button_to("Hello", "http://www.example.com", data: { confirm: "Are you sure?" })
  )
end
test_button_to_with_javascript_disable_with()
# File actionview/test/template/url_helper_test.rb, line 151
def test_button_to_with_javascript_disable_with
  assert_dom_equal(
    %Q{<form method="post" action="http://www.example.com" class="button_to"><input data-disable-with="Greeting..." type="submit" value="Hello" /></form>},
    button_to("Hello", "http://www.example.com", data: { disable_with: "Greeting..." })
  )
end
test_button_to_with_method_delete()
# File actionview/test/template/url_helper_test.rb, line 197
def test_button_to_with_method_delete
  assert_dom_equal(
    %Q{<form method="post" action="http://www.example.com" class="button_to"><input type="hidden" name="_method" value="delete" /><input type="submit" value="Hello" /></form>},
    button_to("Hello", "http://www.example.com", method: :delete)
  )
end
test_button_to_with_method_get()
# File actionview/test/template/url_helper_test.rb, line 204
def test_button_to_with_method_get
  assert_dom_equal(
    %Q{<form method="get" action="http://www.example.com" class="button_to"><input type="submit" value="Hello" /></form>},
    button_to("Hello", "http://www.example.com", method: :get)
  )
end
test_button_to_with_nested_array_params()
# File actionview/test/template/url_helper_test.rb, line 232
def test_button_to_with_nested_array_params
  assert_dom_equal(
    %Q{<form action="http://www.example.com" class="button_to" method="post"><input type="submit" value="Hello" /><input type="hidden" name="foo[]" value="bar" /></form>},
    button_to("Hello", "http://www.example.com", params: { foo: ['bar'] })
  )
end
test_button_to_with_nested_hash_params()
# File actionview/test/template/url_helper_test.rb, line 225
def test_button_to_with_nested_hash_params
  assert_dom_equal(
    %Q{<form action="http://www.example.com" class="button_to" method="post"><input type="submit" value="Hello" /><input type="hidden" name="foo[bar]" value="baz" /></form>},
    button_to("Hello", "http://www.example.com", params: { foo: { bar: 'baz' } })
  )
end
test_button_to_with_params()
# File actionview/test/template/url_helper_test.rb, line 218
def test_button_to_with_params
  assert_dom_equal(
    %Q{<form action="http://www.example.com" class="button_to" method="post"><input type="submit" value="Hello" /><input type="hidden" name="baz" value="quux" /><input type="hidden" name="foo" value="bar" /></form>},
    button_to("Hello", "http://www.example.com", params: { foo: :bar, baz: "quux" })
  )
end
test_button_to_with_path()
# File actionview/test/template/url_helper_test.rb, line 106
def test_button_to_with_path
  assert_dom_equal(
    %Q{<form method="post" action="/article/Hello" class="button_to"><input type="submit" value="Hello" /></form>},
    button_to("Hello", article_path("Hello"))
  )
end
test_button_to_with_query()
# File actionview/test/template/url_helper_test.rb, line 132
def test_button_to_with_query
  assert_dom_equal %Q{<form method="post" action="http://www.example.com/q1=v1&amp;q2=v2" class="button_to"><input type="submit" value="Hello" /></form>}, button_to("Hello", "http://www.example.com/q1=v1&q2=v2")
end
test_button_to_with_query_and_no_name()
# File actionview/test/template/url_helper_test.rb, line 140
def test_button_to_with_query_and_no_name
  assert_dom_equal %Q{<form method="post" action="http://www.example.com?q1=v1&amp;q2=v2" class="button_to"><input type="submit" value="http://www.example.com?q1=v1&amp;q2=v2" /></form>}, button_to(nil, "http://www.example.com?q1=v1&q2=v2")
end
test_button_to_with_remote_and_form_options()
# File actionview/test/template/url_helper_test.rb, line 158
def test_button_to_with_remote_and_form_options
  assert_dom_equal(
    %Q{<form method="post" action="http://www.example.com" class="custom-class" data-remote="true" data-type="json"><input type="submit" value="Hello" /></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 actionview/test/template/url_helper_test.rb, line 165
def test_button_to_with_remote_and_javascript_confirm
  assert_dom_equal(
    %Q{<form method="post" action="http://www.example.com" class="button_to" data-remote="true"><input data-confirm="Are you sure?" type="submit" value="Hello" /></form>},
    button_to("Hello", "http://www.example.com", remote: true, data: { confirm: "Are you sure?" })
  )
end
test_button_to_with_remote_and_javascript_disable_with()
# File actionview/test/template/url_helper_test.rb, line 172
def test_button_to_with_remote_and_javascript_disable_with
  assert_dom_equal(
    %Q{<form method="post" action="http://www.example.com" class="button_to" data-remote="true"><input data-disable-with="Greeting..." type="submit" value="Hello" /></form>},
    button_to("Hello", "http://www.example.com", remote: true, data: { disable_with: "Greeting..." })
  )
end
test_button_to_with_remote_false()
# File actionview/test/template/url_helper_test.rb, line 179
def test_button_to_with_remote_false
  assert_dom_equal(
    %Q{<form method="post" action="http://www.example.com" class="button_to"><input type="submit" value="Hello" /></form>},
    button_to("Hello", "http://www.example.com", remote: false)
  )
end
test_button_to_with_straight_url()
# File actionview/test/template/url_helper_test.rb, line 102
def test_button_to_with_straight_url
  assert_dom_equal %Q{<form method="post" action="http://www.example.com" class="button_to"><input type="submit" value="Hello" /></form>}, button_to("Hello", "http://www.example.com")
end
test_button_to_with_straight_url_and_request_forgery()
# File actionview/test/template/url_helper_test.rb, line 113
def test_button_to_with_straight_url_and_request_forgery
  self.request_forgery = true

  assert_dom_equal(
    %Q{<form method="post" action="http://www.example.com" class="button_to"><input type="submit" value="Hello" /><input name="form_token" type="hidden" value="secret" /></form>},
    button_to("Hello", "http://www.example.com")
  )
ensure
  self.request_forgery = false
end
test_current_page_ignoring_params()
# File actionview/test/template/url_helper_test.rb, line 466
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_double_escaped_params()
# File actionview/test/template/url_helper_test.rb, line 500
def test_current_page_with_double_escaped_params
  @request = request_for_url("/category/administra%c3%a7%c3%a3o?callback_url=http%3a%2f%2fexample.com%2ffoo")

  assert current_page?(controller: 'foo', action: 'category', category: 'administração', callback_url: 'http://example.com/foo')
end
test_current_page_with_escaped_params()
# File actionview/test/template/url_helper_test.rb, line 486
def test_current_page_with_escaped_params
  @request = request_for_url("/category/administra%c3%a7%c3%a3o")

  assert current_page?(controller: 'foo', action: 'category', category: 'administração')
end
test_current_page_with_escaped_params_with_different_encoding()
# File actionview/test/template/url_helper_test.rb, line 492
def test_current_page_with_escaped_params_with_different_encoding
  @request = request_for_url("/")
  @request.stub(:path, "/category/administra%c3%a7%c3%a3o".force_encoding(Encoding::ASCII_8BIT)) do
    assert current_page?(:controller => 'foo', :action => 'category', category: 'administração')
    assert current_page?("http://www.example.com/category/administra%c3%a7%c3%a3o")
  end
end
test_current_page_with_http_head_method()
# File actionview/test/template/url_helper_test.rb, line 454
def test_current_page_with_http_head_method
  @request = request_for_url("/", :method => :head)
  assert current_page?(url_hash)
  assert current_page?("http://www.example.com/")
end
test_current_page_with_not_get_verb()
# File actionview/test/template/url_helper_test.rb, line 480
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 actionview/test/template/url_helper_test.rb, line 473
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 actionview/test/template/url_helper_test.rb, line 460
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 actionview/test/template/url_helper_test.rb, line 336
def test_link_tag_using_post_javascript
  assert_dom_equal(
    %Q{<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 actionview/test/template/url_helper_test.rb, line 364
def test_link_tag_using_post_javascript_and_confirm
  assert_dom_equal(
    %Q{<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, data: { confirm: "Are you serious?" })
  )
end
test_link_tag_using_post_javascript_and_rel()
# File actionview/test/template/url_helper_test.rb, line 357
def test_link_tag_using_post_javascript_and_rel
  assert_dom_equal(
    %Q{<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 actionview/test/template/url_helper_test.rb, line 554
def test_mail_to
  assert_dom_equal %Q{<a href="mailto:david@loudthinking.com">david@loudthinking.com</a>}, mail_to("david@loudthinking.com")
  assert_dom_equal %Q{<a href="mailto:david@loudthinking.com">David Heinemeier Hansson</a>}, mail_to("david@loudthinking.com", "David Heinemeier Hansson")
  assert_dom_equal(
    %Q{<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_does_not_modify_html_options_hash()
# File actionview/test/template/url_helper_test.rb, line 617
def test_mail_to_does_not_modify_html_options_hash
  options = { class: 'special' }
  mail_to 'me@example.com', 'ME!', options
  assert_equal({ class: 'special' }, options)
end
test_mail_to_returns_html_safe_string()
# File actionview/test/template/url_helper_test.rb, line 603
def test_mail_to_returns_html_safe_string
  assert mail_to("david@loudthinking.com").html_safe?
end
test_mail_to_with_block()
# File actionview/test/template/url_helper_test.rb, line 607
def test_mail_to_with_block
  assert_dom_equal %Q{<a href="mailto:me@example.com"><span>Email me</span></a>},
    mail_to('me@example.com') { content_tag(:span, 'Email me') }
end
test_mail_to_with_block_and_options()
# File actionview/test/template/url_helper_test.rb, line 612
def test_mail_to_with_block_and_options
  assert_dom_equal %Q{<a class="special" href="mailto:me@example.com?cc=ccaddress%40example.com"><span>Email me</span></a>},
    mail_to('me@example.com', cc: "ccaddress@example.com", class: "special") { content_tag(:span, 'Email me') }
end
test_mail_to_with_html_safe_string()
# File actionview/test/template/url_helper_test.rb, line 589
def test_mail_to_with_html_safe_string
  assert_dom_equal(
    %Q{<a href="mailto:david@loudthinking.com">david@loudthinking.com</a>},
    mail_to(raw("david@loudthinking.com"))
  )
end
test_mail_to_with_img()
# File actionview/test/template/url_helper_test.rb, line 584
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', raw('<img src="/feedback.png" />'))
end
test_mail_to_with_nil()
# File actionview/test/template/url_helper_test.rb, line 596
def test_mail_to_with_nil
  assert_dom_equal(
    %Q{<a href="mailto:"></a>},
    mail_to(nil)
  )
end
test_mail_to_with_special_characters()
# File actionview/test/template/url_helper_test.rb, line 565
def test_mail_to_with_special_characters
  assert_dom_equal(
    %Q{<a href="mailto:%23%21%24%25%26%27%2A%2B-%2F%3D%3F%5E_%60%7B%7D%7C%7E@example.org">#!$%&amp;&#39;*+-/=?^_`{}|~@example.org</a>},
    mail_to("#!$%&'*+-/=?^_`{}|~@example.org")
  )
end
test_mail_with_options()
# File actionview/test/template/url_helper_test.rb, line 572
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&amp;reply-to=foo%40bar.com">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.", reply_to: "foo@bar.com")
  )

  assert_dom_equal(
    %Q{<a href="mailto:me@example.com?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: '', bcc: '', subject: "This is an example email", body: "This is the body of the message.")
  )
end
test_to_form_params_with_array_nested_in_hash()
# File actionview/test/template/url_helper_test.rb, line 88
def test_to_form_params_with_array_nested_in_hash
  assert_equal(
    [{ name: 'countries[]', value: 'Denmark' }, { name: 'countries[]', value: 'Sweden' }],
    to_form_params(countries: ['Denmark', 'Sweden'])
  )
end
test_to_form_params_with_hash()
# File actionview/test/template/url_helper_test.rb, line 74
def test_to_form_params_with_hash
  assert_equal(
    [{ name: :name, value: 'David' }, { name: :nationality, value: 'Danish' }],
    to_form_params(name: 'David', nationality: 'Danish')
  )
end
test_to_form_params_with_namespace()
# File actionview/test/template/url_helper_test.rb, line 95
def test_to_form_params_with_namespace
  assert_equal(
    [{ name: 'country[name]', value: 'Denmark' }],
    to_form_params({name: 'Denmark'}, 'country')
  )
end
test_to_form_params_with_nested_hash()
# File actionview/test/template/url_helper_test.rb, line 81
def test_to_form_params_with_nested_hash
  assert_equal(
    [{ name: 'country[name]', value: 'Denmark' }],
    to_form_params(country: { name: 'Denmark' })
  )
end
test_url_for_does_not_escape_urls()
# File actionview/test/template/url_helper_test.rb, line 37
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_does_not_include_empty_hashes()
# File actionview/test/template/url_helper_test.rb, line 41
def test_url_for_does_not_include_empty_hashes
  assert_equal "/", url_for(hash_for(a: {}))
end
test_url_for_with_back()
# File actionview/test/template/url_helper_test.rb, line 45
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_javascript_referer()
# File actionview/test/template/url_helper_test.rb, line 62
def test_url_for_with_back_and_javascript_referer
  referer = 'javascript:alert(document.cookie)'
  @controller = Struct.new(:request).new(Struct.new(:env).new("HTTP_REFERER" => referer))
  assert_equal 'javascript:history.back()', url_for(:back)
end
test_url_for_with_back_and_no_controller()
# File actionview/test/template/url_helper_test.rb, line 57
def test_url_for_with_back_and_no_controller
  @controller = nil
  assert_equal 'javascript:history.back()', url_for(:back)
end
test_url_for_with_back_and_no_referer()
# File actionview/test/template/url_helper_test.rb, line 52
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
test_url_for_with_invalid_referer()
# File actionview/test/template/url_helper_test.rb, line 68
def test_url_for_with_invalid_referer
  referer = 'THIS IS NOT A URL'
  @controller = Struct.new(:request).new(Struct.new(:env).new("HTTP_REFERER" => referer))
  assert_equal 'javascript:history.back()', url_for(:back)
end
url_hash(options = {})
Alias for: hash_for