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()
# File actionview/test/template/url_helper_test.rb, line 567
def form_authenticity_token
  "secret"
end
hash_for(options = {})
Also aliased as: url_hash
# File actionview/test/template/url_helper_test.rb, line 33
def hash_for(options = {})
  { controller: "foo", action: "bar" }.merge!(options)
end
protect_against_forgery?()
# File actionview/test/template/url_helper_test.rb, line 563
def protect_against_forgery?
  self.request_forgery
end
request_for_url(url, opts = {})
# File actionview/test/template/url_helper_test.rb, line 387
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 571
def request_forgery_protection_token
  "form_token"
end
test_button_to_enabled_disabled()
# File actionview/test/template/url_helper_test.rb, line 138
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 163
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 76
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 80
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 88
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", "http://www.example.com/q1=v1&amp;q2=v2".html_safe)
end
test_button_to_with_javascript_confirm()
# File actionview/test/template/url_helper_test.rb, line 96
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 103
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 149
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 156
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_params()
# File actionview/test/template/url_helper_test.rb, line 170
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="foo" value="bar" /><input type="hidden" name="baz" value="quux" /></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 58
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".html_safe))
  )
end
test_button_to_with_query()
# File actionview/test/template/url_helper_test.rb, line 84
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 92
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 110
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 117
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 124
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 131
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 54
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 65
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 404
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 438
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 424
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 430
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 392
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 418
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 411
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 398
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 274
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 302
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 295
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 492
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 557
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 543
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 547
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 552
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 517
def test_mail_to_with_html_safe_string
  assert_dom_equal(
    %Q{<a href="mailto:david@loudthinking.com">david@loudthinking.com</a>},
    mail_to("david@loudthinking.com".html_safe)
  )
end
test_mail_to_with_img()
# File actionview/test/template/url_helper_test.rb, line 524
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_nil()
# File actionview/test/template/url_helper_test.rb, line 536
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 503
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 510
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 actionview/test/template/url_helper_test.rb, line 38
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 actionview/test/template/url_helper_test.rb, line 42
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 actionview/test/template/url_helper_test.rb, line 49
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(options = {})
Alias for: hash_for