class FormWithActsLikeFormTagTest

Public Instance Methods

form_text(action = "http://www.example.com", local: false, **options) click to toggle source
# File actionview/test/template/form_helper/form_with_test.rb, line 32
def form_text(action = "http://www.example.com", local: false, **options)
  enctype, html_class, id, method = options.values_at(:enctype, :html_class, :id, :method)

  method = method.to_s == "get" ? "get" : "post"

  txt =  %{<form accept-charset="UTF-8" action="#{action}"}.dup
  txt << %{ enctype="multipart/form-data"} if enctype
  txt << %{ data-remote="true"} unless local
  txt << %{ class="#{html_class}"} if html_class
  txt << %{ id="#{id}"} if id
  txt << %{ method="#{method}">}
end
hidden_fields(options = {}) click to toggle source
# File actionview/test/template/form_helper/form_with_test.rb, line 17
def hidden_fields(options = {})
  method = options[:method]
  skip_enforcing_utf8 = options.fetch(:skip_enforcing_utf8, false)

  "".dup.tap do |txt|
    unless skip_enforcing_utf8
      txt << %{<input name="utf8" type="hidden" value="&#x2713;" />}
    end

    if method && !%w(get post).include?(method.to_s)
      txt << %{<input name="_method" type="hidden" value="#{method}" />}
    end
  end
end
test_form_with_multipart() click to toggle source
# File actionview/test/template/form_helper/form_with_test.rb, line 63
def test_form_with_multipart
  actual = form_with(multipart: true)

  expected = whole_form("http://www.example.com", enctype: true)
  assert_dom_equal expected, actual
end
test_form_with_skip_enforcing_utf8_true() click to toggle source
# File actionview/test/template/form_helper/form_with_test.rb, line 98
def test_form_with_skip_enforcing_utf8_true
  actual = form_with(skip_enforcing_utf8: true)
  expected = whole_form("http://www.example.com", skip_enforcing_utf8: true)
  assert_dom_equal expected, actual
  assert actual.html_safe?
end
test_form_with_with_block_and_method_in_erb() click to toggle source
# File actionview/test/template/form_helper/form_with_test.rb, line 112
def test_form_with_with_block_and_method_in_erb
  output_buffer = render_erb("<%= form_with(url: 'http://www.example.com', method: :put) do %>Hello world!<% end %>")

  expected = whole_form("http://www.example.com", method: "put") do
    "Hello world!"
  end

  assert_dom_equal expected, output_buffer
end
test_form_with_with_block_in_erb() click to toggle source
# File actionview/test/template/form_helper/form_with_test.rb, line 105
def test_form_with_with_block_in_erb
  output_buffer = render_erb("<%= form_with(url: 'http://www.example.com') do %>Hello world!<% end %>")

  expected = whole_form { "Hello world!" }
  assert_dom_equal expected, output_buffer
end
test_form_with_with_block_in_erb_and_local_true() click to toggle source
# File actionview/test/template/form_helper/form_with_test.rb, line 122
def test_form_with_with_block_in_erb_and_local_true
  output_buffer = render_erb("<%= form_with(url: 'http://www.example.com', local: true) do %>Hello world!<% end %>")

  expected = whole_form("http://www.example.com", local: true) do
    "Hello world!"
  end

  assert_dom_equal expected, output_buffer
end
test_form_with_with_local_true() click to toggle source
# File actionview/test/template/form_helper/form_with_test.rb, line 91
def test_form_with_with_local_true
  actual = form_with(local: true)

  expected = whole_form("http://www.example.com", local: true)
  assert_dom_equal expected, actual
end
test_form_with_with_method_delete() click to toggle source
# File actionview/test/template/form_helper/form_with_test.rb, line 84
def test_form_with_with_method_delete
  actual = form_with(method: :delete)

  expected = whole_form("http://www.example.com", method: :delete)
  assert_dom_equal expected, actual
end
test_form_with_with_method_patch() click to toggle source
# File actionview/test/template/form_helper/form_with_test.rb, line 70
def test_form_with_with_method_patch
  actual = form_with(method: :patch)

  expected = whole_form("http://www.example.com", method: :patch)
  assert_dom_equal expected, actual
end
test_form_with_with_method_put() click to toggle source
# File actionview/test/template/form_helper/form_with_test.rb, line 77
def test_form_with_with_method_put
  actual = form_with(method: :put)

  expected = whole_form("http://www.example.com", method: :put)
  assert_dom_equal expected, actual
end
url_for(options) click to toggle source
Calls superclass method
# File actionview/test/template/form_helper/form_with_test.rb, line 55
def url_for(options)
  if options.is_a?(Hash)
    "http://www.example.com"
  else
    super
  end
end
whole_form(action = "http://www.example.com", options = {}) { |<< "</form>"| ... } click to toggle source
# File actionview/test/template/form_helper/form_with_test.rb, line 45
def whole_form(action = "http://www.example.com", options = {})
  out = form_text(action, options) + hidden_fields(options)

  if block_given?
    out << yield << "</form>"
  end

  out
end