form_with/fields: Don't output ids by default

Continuing 67f81cc where we decided not to output ids
by default in the new form helpers.

Went with @dhh's suggestion of just requiring ids on
fields being labelled:
https://github.com/rails/rails/issues/25197#issuecomment-231797117

Seems okay enough.
This commit is contained in:
Kasper Timm Hansen 2016-11-21 21:48:38 +01:00
parent 34a1c7e284
commit a6d065e39f
4 changed files with 243 additions and 206 deletions

@ -595,6 +595,16 @@ def apply_form_for_options!(record, object, options) #:nodoc:
#
# Where <tt>@document = Document.find(params[:id])</tt>.
#
# When using labels +form_with+ requires setting the id on the field being
# labelled:
#
# <%= form_with(model: @post) do |form| %>
# <%= form.label :title %>
# <%= form.text_field :title, id: :post_title %>
# <% end %>
#
# See +label+ for more on how the +for+ attribute is derived.
#
# === Mixing with other form helpers
#
# While +form_with+ uses a FormBuilder object it's possible to mix and
@ -690,6 +700,8 @@ def apply_form_for_options!(record, object, options) #:nodoc:
# form_with(**options.merge(builder: LabellingFormBuilder), &block)
# end
def form_with(model: nil, scope: nil, url: nil, format: nil, **options)
options[:skip_default_ids] = true
if model
url ||= polymorphic_path(model, format: format)
@ -986,6 +998,16 @@ def fields_for(record_name, record_object = nil, options = {}, &block)
# or model is yielded, so any generated field names are prefixed with
# either the passed scope or the scope inferred from the <tt>:model</tt>.
#
# When using labels +fields+ requires setting the id on the field being
# labelled:
#
# <%= fields :comment do |fields| %>
# <%= fields.label :body %>
# <%= fields.text_field :body, id: :comment_body %>
# <% end %>
#
# See +label+ for more on how the +for+ attribute is derived.
#
# === Mixing with other form helpers
#
# While +form_with+ uses a FormBuilder object it's possible to mix and
@ -1003,7 +1025,8 @@ def fields_for(record_name, record_object = nil, options = {}, &block)
# to work with an object as a base, like
# FormOptionHelper#collection_select and DateHelper#datetime_select.
def fields(scope = nil, model: nil, **options, &block)
# TODO: Remove when ids and classes are no longer output by default.
options[:skip_default_ids] = true
if model
scope ||= model_name_from_record_or_class(model).param_key
end
@ -1469,7 +1492,7 @@ def range_field(object_name, method, options = {})
private
def html_options_for_form_with(url_for_options = nil, model = nil, html: {}, local: false,
skip_enforcing_utf8: false, **options)
html_options = options.except(:index, :include_id, :builder).merge(html)
html_options = options.except(:index, :include_id, :skip_default_ids, :builder).merge(html)
html_options[:method] ||= :patch if model.respond_to?(:persisted?) && model.persisted?
html_options[:enforce_utf8] = !skip_enforcing_utf8
@ -1603,7 +1626,7 @@ def to_model
def initialize(object_name, object, template, options)
@nested_child_index = {}
@object_name, @object, @template, @options = object_name, object, template, options
@default_options = @options ? @options.slice(:index, :namespace) : {}
@default_options = @options ? @options.slice(:index, :namespace, :skip_default_ids) : {}
convert_to_legacy_options(@options)
@ -1910,6 +1933,8 @@ def fields_for(record_name, record_object = nil, fields_options = {}, &block)
# See the docs for the <tt>ActionView::FormHelper.fields</tt> helper method.
def fields(scope = nil, model: nil, **options, &block)
options[:skip_default_ids] = true
convert_to_legacy_options(options)
fields_for(scope || model, model, **options, &block)

@ -13,6 +13,7 @@ def initialize(object_name, method_name, template_object, options = {})
@object_name.sub!(/\[\]$/, "") || @object_name.sub!(/\[\]\]$/, "]")
@object = retrieve_object(options.delete(:object))
@skip_default_ids = options.delete(:skip_default_ids)
@options = options
@auto_index = Regexp.last_match ? retrieve_autoindex(Regexp.last_match.pre_match) : nil
end
@ -81,11 +82,14 @@ def add_default_name_and_id_for_value(tag_value, options)
def add_default_name_and_id(options)
index = name_and_id_index(options)
options["name"] = options.fetch("name") { tag_name(options["multiple"], index) }
unless skip_default_ids?
options["id"] = options.fetch("id") { tag_id(index) }
if namespace = options.delete("namespace")
options["id"] = options["id"] ? "#{namespace}_#{options['id']}" : namespace
end
end
end
def tag_name(multiple = false, index = nil)
# a little duplication to construct less strings
@ -154,6 +158,10 @@ def add_options(option_tags, options, value = nil)
def name_and_id_index(options)
options.key?("index") ? options.delete("index") || "" : @auto_index
end
def skip_default_ids?
@skip_default_ids
end
end
end
end

@ -73,6 +73,10 @@ def render(&block)
def render_component(builder)
builder.translation
end
def skip_default_ids?
false # The id is used as the `for` attribute.
end
end
end
end

@ -301,10 +301,10 @@ def test_form_with
expected = whole_form("/posts/123", "create-post", method: "patch") do
"<label for='post_title'>The Title</label>" +
"<input name='post[title]' type='text' id='post_title' value='Hello World' />" +
"<textarea name='post[body]' id='post_body'>\nBack to the hill and over it again!</textarea>" +
"<input name='post[title]' type='text' value='Hello World' />" +
"<textarea name='post[body]'>\nBack to the hill and over it again!</textarea>" +
"<input name='post[secret]' type='hidden' value='0' />" +
"<input name='post[secret]' checked='checked' type='checkbox' id='post_secret' value='1' />" +
"<input name='post[secret]' checked='checked' type='checkbox' value='1' />" +
"<input name='commit' data-disable-with='Create post' type='submit' value='Create post' />" +
"<button name='button' type='submit'>Create post</button>" +
"<button name='button' type='submit'><span>Create post</span></button>"
@ -322,9 +322,9 @@ def post.active; false; end
expected = whole_form("/posts") do
"<input type='hidden' name='post[active]' value='' />" +
"<input id='post_active_true' name='post[active]' type='radio' value='true' />" +
"<input name='post[active]' type='radio' value='true' />" +
"<label for='post_active_true'>true</label>" +
"<input checked='checked' id='post_active_false' name='post[active]' type='radio' value='false' />" +
"<input checked='checked' name='post[active]' type='radio' value='false' />" +
"<label for='post_active_false'>false</label>"
end
@ -345,10 +345,10 @@ def post.active; false; end
expected = whole_form("/posts") do
"<input type='hidden' name='post[active]' value='' />" +
"<label for='post_active_true'>" +
"<input id='post_active_true' name='post[active]' type='radio' value='true' />" +
"<input name='post[active]' type='radio' value='true' />" +
"true</label>" +
"<label for='post_active_false'>" +
"<input checked='checked' id='post_active_false' name='post[active]' type='radio' value='false' />" +
"<input checked='checked' name='post[active]' type='radio' value='false' />" +
"false</label>"
end
@ -371,12 +371,12 @@ def post.id; 1; end
expected = whole_form("/posts") do
"<input type='hidden' name='post[active]' value='' />" +
"<label for='post_active_true'>" +
"<input id='post_active_true' name='post[active]' type='radio' value='true' />" +
"<input name='post[active]' type='radio' value='true' />" +
"true</label>" +
"<label for='post_active_false'>" +
"<input checked='checked' id='post_active_false' name='post[active]' type='radio' value='false' />" +
"<input checked='checked' name='post[active]' type='radio' value='false' />" +
"false</label>" +
"<input id='post_id' name='post[id]' type='hidden' value='1' />"
"<input name='post[id]' type='hidden' value='1' />"
end
assert_dom_equal expected, output_buffer
@ -392,9 +392,9 @@ def post.active; false; end
expected = whole_form("/posts") do
"<input type='hidden' name='post[1][active]' value='' />" +
"<input id='post_1_active_true' name='post[1][active]' type='radio' value='true' />" +
"<input name='post[1][active]' type='radio' value='true' />" +
"<label for='post_1_active_true'>true</label>" +
"<input checked='checked' id='post_1_active_false' name='post[1][active]' type='radio' value='false' />" +
"<input checked='checked' name='post[1][active]' type='radio' value='false' />" +
"<label for='post_1_active_false'>false</label>"
end
@ -411,11 +411,11 @@ def post.tag_ids; [1, 3]; end
expected = whole_form("/posts") do
"<input name='post[tag_ids][]' type='hidden' value='' />" +
"<input checked='checked' id='post_tag_ids_1' name='post[tag_ids][]' type='checkbox' value='1' />" +
"<input checked='checked' name='post[tag_ids][]' type='checkbox' value='1' />" +
"<label for='post_tag_ids_1'>Tag 1</label>" +
"<input id='post_tag_ids_2' name='post[tag_ids][]' type='checkbox' value='2' />" +
"<input name='post[tag_ids][]' type='checkbox' value='2' />" +
"<label for='post_tag_ids_2'>Tag 2</label>" +
"<input checked='checked' id='post_tag_ids_3' name='post[tag_ids][]' type='checkbox' value='3' />" +
"<input checked='checked' name='post[tag_ids][]' type='checkbox' value='3' />" +
"<label for='post_tag_ids_3'>Tag 3</label>"
end
@ -436,13 +436,13 @@ def post.tag_ids; [1, 3]; end
expected = whole_form("/posts") do
"<input name='post[tag_ids][]' type='hidden' value='' />" +
"<label for='post_tag_ids_1'>" +
"<input checked='checked' id='post_tag_ids_1' name='post[tag_ids][]' type='checkbox' value='1' />" +
"<input checked='checked' name='post[tag_ids][]' type='checkbox' value='1' />" +
"Tag 1</label>" +
"<label for='post_tag_ids_2'>" +
"<input id='post_tag_ids_2' name='post[tag_ids][]' type='checkbox' value='2' />" +
"<input name='post[tag_ids][]' type='checkbox' value='2' />" +
"Tag 2</label>" +
"<label for='post_tag_ids_3'>" +
"<input checked='checked' id='post_tag_ids_3' name='post[tag_ids][]' type='checkbox' value='3' />" +
"<input checked='checked' name='post[tag_ids][]' type='checkbox' value='3' />" +
"Tag 3</label>"
end
@ -466,15 +466,15 @@ def post.id; 1; end
expected = whole_form("/posts") do
"<input name='post[tag_ids][]' type='hidden' value='' />" +
"<label for='post_tag_ids_1'>" +
"<input checked='checked' id='post_tag_ids_1' name='post[tag_ids][]' type='checkbox' value='1' />" +
"<input checked='checked' name='post[tag_ids][]' type='checkbox' value='1' />" +
"Tag 1</label>" +
"<label for='post_tag_ids_2'>" +
"<input id='post_tag_ids_2' name='post[tag_ids][]' type='checkbox' value='2' />" +
"<input name='post[tag_ids][]' type='checkbox' value='2' />" +
"Tag 2</label>" +
"<label for='post_tag_ids_3'>" +
"<input checked='checked' id='post_tag_ids_3' name='post[tag_ids][]' type='checkbox' value='3' />" +
"<input checked='checked' name='post[tag_ids][]' type='checkbox' value='3' />" +
"Tag 3</label>" +
"<input id='post_id' name='post[id]' type='hidden' value='1' />"
"<input name='post[id]' type='hidden' value='1' />"
end
assert_dom_equal expected, output_buffer
@ -491,7 +491,7 @@ def post.tag_ids; [1]; end
expected = whole_form("/posts") do
"<input name='post[1][tag_ids][]' type='hidden' value='' />" +
"<input checked='checked' id='post_1_tag_ids_1' name='post[1][tag_ids][]' type='checkbox' value='1' />" +
"<input checked='checked' name='post[1][tag_ids][]' type='checkbox' value='1' />" +
"<label for='post_1_tag_ids_1'>Tag 1</label>"
end
@ -506,7 +506,7 @@ def test_form_with_with_file_field_generate_multipart
end
expected = whole_form("/posts/123", "create-post", method: "patch", multipart: true) do
"<input name='post[file]' type='file' id='post_file' />"
"<input name='post[file]' type='file' />"
end
assert_dom_equal expected, output_buffer
@ -522,7 +522,7 @@ def test_fields_with_file_field_generate_multipart
end
expected = whole_form("/posts/123", method: "patch", multipart: true) do
"<input name='post[comment][file]' type='file' id='post_comment_file' />"
"<input name='post[comment][file]' type='file' />"
end
assert_dom_equal expected, output_buffer
@ -561,7 +561,7 @@ def test_form_with_with_model_using_relative_model_naming
end
expected = whole_form("/posts/44", method: "patch") do
"<input name='post[title]' type='text' id='post_title' value='And his name will be forty and four.' />" +
"<input name='post[title]' type='text' value='And his name will be forty and four.' />" +
"<input name='commit' data-disable-with='Edit post' type='submit' value='Edit post' />"
end
@ -579,10 +579,10 @@ def test_form_with_with_symbol_scope
expected = whole_form("/posts/123", "create-post", method: "patch") do
"<label for='other_name_title' class='post_title'>Title</label>" +
"<input name='other_name[title]' id='other_name_title' value='Hello World' type='text' />" +
"<textarea name='other_name[body]' id='other_name_body'>\nBack to the hill and over it again!</textarea>" +
"<input name='other_name[title]' value='Hello World' type='text' />" +
"<textarea name='other_name[body]'>\nBack to the hill and over it again!</textarea>" +
"<input name='other_name[secret]' value='0' type='hidden' />" +
"<input name='other_name[secret]' checked='checked' id='other_name_secret' value='1' type='checkbox' />" +
"<input name='other_name[secret]' checked='checked' value='1' type='checkbox' />" +
"<input name='commit' value='Create post' data-disable-with='Create post' type='submit' />"
end
@ -609,10 +609,10 @@ def test_form_with_with_method_as_part_of_html_options
end
expected = whole_form("/", "create-post", method: "delete") do
"<input name='post[title]' type='text' id='post_title' value='Hello World' />" +
"<textarea name='post[body]' id='post_body'>\nBack to the hill and over it again!</textarea>" +
"<input name='post[title]' type='text' value='Hello World' />" +
"<textarea name='post[body]'>\nBack to the hill and over it again!</textarea>" +
"<input name='post[secret]' type='hidden' value='0' />" +
"<input name='post[secret]' checked='checked' type='checkbox' id='post_secret' value='1' />"
"<input name='post[secret]' checked='checked' type='checkbox' value='1' />"
end
assert_dom_equal expected, output_buffer
@ -626,10 +626,10 @@ def test_form_with_with_method
end
expected = whole_form("/", "create-post", method: "delete") do
"<input name='post[title]' type='text' id='post_title' value='Hello World' />" +
"<textarea name='post[body]' id='post_body'>\nBack to the hill and over it again!</textarea>" +
"<input name='post[title]' type='text' value='Hello World' />" +
"<textarea name='post[body]'>\nBack to the hill and over it again!</textarea>" +
"<input name='post[secret]' type='hidden' value='0' />" +
"<input name='post[secret]' checked='checked' type='checkbox' id='post_secret' value='1' />"
"<input name='post[secret]' checked='checked' type='checkbox' value='1' />"
end
assert_dom_equal expected, output_buffer
@ -643,7 +643,7 @@ def test_form_with_with_search_field
end
expected = whole_form("/search", "search-post", method: "get") do
"<input name='post[title]' type='search' id='post_title' />"
"<input name='post[title]' type='search' />"
end
assert_dom_equal expected, output_buffer
@ -657,10 +657,10 @@ def test_form_with_enables_remote_by_default
end
expected = whole_form("/", "create-post", method: "patch") do
"<input name='post[title]' type='text' id='post_title' value='Hello World' />" +
"<textarea name='post[body]' id='post_body'>\nBack to the hill and over it again!</textarea>" +
"<input name='post[title]' type='text' value='Hello World' />" +
"<textarea name='post[body]'>\nBack to the hill and over it again!</textarea>" +
"<input name='post[secret]' type='hidden' value='0' />" +
"<input name='post[secret]' checked='checked' type='checkbox' id='post_secret' value='1' />"
"<input name='post[secret]' checked='checked' type='checkbox' value='1' />"
end
assert_dom_equal expected, output_buffer
@ -672,7 +672,7 @@ def test_form_with_skip_enforcing_utf8_true
end
expected = whole_form("/", skip_enforcing_utf8: true) do
"<input name='post[title]' type='text' id='post_title' value='Hello World' />"
"<input name='post[title]' type='text' value='Hello World' />"
end
assert_dom_equal expected, output_buffer
@ -684,7 +684,7 @@ def test_form_with_skip_enforcing_utf8_false
end
expected = whole_form("/", skip_enforcing_utf8: false) do
"<input name='post[title]' type='text' id='post_title' value='Hello World' />"
"<input name='post[title]' type='text' value='Hello World' />"
end
assert_dom_equal expected, output_buffer
@ -698,10 +698,10 @@ def test_form_with_without_object
end
expected = whole_form("/", "create-post") do
"<input name='post[title]' type='text' id='post_title' value='Hello World' />" +
"<textarea name='post[body]' id='post_body'>\nBack to the hill and over it again!</textarea>" +
"<input name='post[title]' type='text' value='Hello World' />" +
"<textarea name='post[body]'>\nBack to the hill and over it again!</textarea>" +
"<input name='post[secret]' type='hidden' value='0' />" +
"<input name='post[secret]' checked='checked' type='checkbox' id='post_secret' value='1' />"
"<input name='post[secret]' checked='checked' type='checkbox' value='1' />"
end
assert_dom_equal expected, output_buffer
@ -717,10 +717,10 @@ def test_form_with_with_index
expected = whole_form("/posts/123", method: "patch") do
"<label for='post_123_title'>Title</label>" +
"<input name='post[123][title]' type='text' id='post_123_title' value='Hello World' />" +
"<textarea name='post[123][body]' id='post_123_body'>\nBack to the hill and over it again!</textarea>" +
"<input name='post[123][title]' type='text' value='Hello World' />" +
"<textarea name='post[123][body]'>\nBack to the hill and over it again!</textarea>" +
"<input name='post[123][secret]' type='hidden' value='0' />" +
"<input name='post[123][secret]' checked='checked' type='checkbox' id='post_123_secret' value='1' />"
"<input name='post[123][secret]' checked='checked' type='checkbox' value='1' />"
end
assert_dom_equal expected, output_buffer
@ -734,10 +734,10 @@ def test_form_with_with_nil_index_option_override
end
expected = whole_form("/posts/123", method: "patch") do
"<input name='post[][title]' type='text' id='post__title' value='Hello World' />" +
"<textarea name='post[][body]' id='post__body'>\nBack to the hill and over it again!</textarea>" +
"<input name='post[][title]' type='text' value='Hello World' />" +
"<textarea name='post[][body]'>\nBack to the hill and over it again!</textarea>" +
"<input name='post[][secret]' type='hidden' value='0' />" +
"<input name='post[][secret]' checked='checked' type='checkbox' id='post__secret' value='1' />"
"<input name='post[][secret]' checked='checked' type='checkbox' value='1' />"
end
assert_dom_equal expected, output_buffer
@ -752,7 +752,7 @@ def test_form_with_label_error_wrapping
expected = whole_form("/posts/123", method: "patch") do
"<div class='field_with_errors'><label for='post_author_name' class='label'>Author name</label></div>" +
"<div class='field_with_errors'><input name='post[author_name]' type='text' id='post_author_name' value='' /></div>" +
"<div class='field_with_errors'><input name='post[author_name]' type='text' value='' /></div>" +
"<input name='commit' data-disable-with='Create post' type='submit' value='Create post' />"
end
@ -770,7 +770,7 @@ def test_form_with_label_error_wrapping_without_conventional_instance_variable
expected = whole_form("/posts/123", method: "patch") do
"<div class='field_with_errors'><label for='post_author_name' class='label'>Author name</label></div>" +
"<div class='field_with_errors'><input name='post[author_name]' type='text' id='post_author_name' value='' /></div>" +
"<div class='field_with_errors'><input name='post[author_name]' type='text' value='' /></div>" +
"<input name='commit' data-disable-with='Create post' type='submit' value='Create post' />"
end
@ -800,10 +800,10 @@ def test_form_with_with_namespace
end
expected = whole_form("/posts/123", "namespace_edit_post_123", "edit_post", method: "patch") do
"<input name='post[title]' type='text' id='namespace_post_title' value='Hello World' />" +
"<textarea name='post[body]' id='namespace_post_body'>\nBack to the hill and over it again!</textarea>" +
"<input name='post[title]' type='text' value='Hello World' />" +
"<textarea name='post[body]'>\nBack to the hill and over it again!</textarea>" +
"<input name='post[secret]' type='hidden' value='0' />" +
"<input name='post[secret]' checked='checked' type='checkbox' id='namespace_post_secret' value='1' />"
"<input name='post[secret]' checked='checked' type='checkbox' value='1' />"
end
assert_dom_equal expected, output_buffer
@ -877,7 +877,7 @@ def test_nested_fields
end
expected = whole_form("/posts/123", method: "patch") do
"<input name='post[comment][body]' type='text' id='post_comment_body' value='Hello World' />"
"<input name='post[comment][body]' type='text' value='Hello World' />"
end
assert_dom_equal expected, output_buffer
@ -897,7 +897,7 @@ def test_deep_nested_fields
end
expected = whole_form do
"<input name='posts[post][0][comment][1][name]' type='text' id='posts_post_0_comment_1_name' value='comment #1' />"
"<input name='posts[post][0][comment][1][name]' type='text' value='comment #1' />"
end
assert_dom_equal expected, output_buffer
@ -912,8 +912,8 @@ def test_nested_fields_with_nested_collections
end
expected = whole_form("/posts/123", method: "patch") do
"<input name='post[123][title]' type='text' id='post_123_title' value='Hello World' />" +
"<input name='post[123][comment][][name]' type='text' id='post_123_comment__name' value='new comment' />"
"<input name='post[123][title]' type='text' value='Hello World' />" +
"<input name='post[123][comment][][name]' type='text' value='new comment' />"
end
assert_dom_equal expected, output_buffer
@ -928,8 +928,8 @@ def test_nested_fields_with_index_and_parent_fields
end
expected = whole_form("/posts/123", method: "patch") do
"<input name='post[1][title]' type='text' id='post_1_title' value='Hello World' />" +
"<input name='post[1][comment][1][name]' type='text' id='post_1_comment_1_name' value='new comment' />"
"<input name='post[1][title]' type='text' value='Hello World' />" +
"<input name='post[1][comment][1][name]' type='text' value='new comment' />"
end
assert_dom_equal expected, output_buffer
@ -943,7 +943,7 @@ def test_form_with_with_index_and_nested_fields
end
expected = whole_form("/posts/123", method: "patch") do
"<input name='post[1][comment][title]' type='text' id='post_1_comment_title' value='Hello World' />"
"<input name='post[1][comment][title]' type='text' value='Hello World' />"
end
assert_dom_equal expected, output_buffer
@ -957,7 +957,7 @@ def test_nested_fields_with_index_on_both
end
expected = whole_form("/posts/123", method: "patch") do
"<input name='post[1][comment][5][title]' type='text' id='post_1_comment_5_title' value='Hello World' />"
"<input name='post[1][comment][5][title]' type='text' value='Hello World' />"
end
assert_dom_equal expected, output_buffer
@ -971,7 +971,7 @@ def test_nested_fields_with_auto_index
end
expected = whole_form("/posts/123", method: "patch") do
"<input name='post[123][comment][title]' type='text' id='post_123_comment_title' value='Hello World' />"
"<input name='post[123][comment][title]' type='text' value='Hello World' />"
end
assert_dom_equal expected, output_buffer
@ -985,7 +985,7 @@ def test_nested_fields_with_index_radio_button
end
expected = whole_form("/posts/123", method: "patch") do
"<input name='post[comment][5][title]' type='radio' id='post_comment_5_title_hello' value='hello' />"
"<input name='post[comment][5][title]' type='radio' value='hello' />"
end
assert_dom_equal expected, output_buffer
@ -999,7 +999,7 @@ def test_nested_fields_with_auto_index_on_both
end
expected = whole_form("/posts/123", method: "patch") do
"<input name='post[123][comment][123][title]' type='text' id='post_123_comment_123_title' value='Hello World' />"
"<input name='post[123][comment][123][title]' type='text' value='Hello World' />"
end
assert_dom_equal expected, output_buffer
@ -1019,9 +1019,9 @@ def test_nested_fields_with_index_and_auto_index
end
expected = whole_form("/posts/123", method: "patch") do
"<input name='post[123][comment][5][title]' type='text' id='post_123_comment_5_title' value='Hello World' />"
"<input name='post[123][comment][5][title]' type='text' value='Hello World' />"
end + whole_form("/posts/123", method: "patch") do
"<input name='post[1][comment][123][title]' type='text' id='post_1_comment_123_title' value='Hello World' />"
"<input name='post[1][comment][123][title]' type='text' value='Hello World' />"
end
assert_dom_equal expected, output_buffer
@ -1038,8 +1038,8 @@ def test_nested_fields_with_a_new_record_on_a_nested_attributes_one_to_one_assoc
end
expected = whole_form("/posts/123", method: "patch") do
'<input name="post[title]" type="text" id="post_title" value="Hello World" />' +
'<input id="post_author_attributes_name" name="post[author_attributes][name]" type="text" value="new author" />'
'<input name="post[title]" type="text" value="Hello World" />' +
'<input name="post[author_attributes][name]" type="text" value="new author" />'
end
assert_dom_equal expected, output_buffer
@ -1065,9 +1065,9 @@ def test_nested_fields_with_an_existing_record_on_a_nested_attributes_one_to_one
end
expected = whole_form("/posts/123", method: "patch") do
'<input name="post[title]" type="text" id="post_title" value="Hello World" />' +
'<input id="post_author_attributes_name" name="post[author_attributes][name]" type="text" value="author #321" />' +
'<input id="post_author_attributes_id" name="post[author_attributes][id]" type="hidden" value="321" />'
'<input name="post[title]" type="text" value="Hello World" />' +
'<input name="post[author_attributes][name]" type="text" value="author #321" />' +
'<input name="post[author_attributes][id]" type="hidden" value="321" />'
end
assert_dom_equal expected, output_buffer
@ -1084,9 +1084,9 @@ def test_nested_fields_with_an_existing_record_on_a_nested_attributes_one_to_one
end
expected = whole_form("/posts/123", method: "patch") do
'<input name="post[title]" type="text" id="post_title" value="Hello World" />' +
'<input id="post_author_attributes_name" name="post[author_attributes][name]" type="text" value="author #321" />' +
'<input id="post_author_attributes_id" name="post[author_attributes][id]" type="hidden" value="321" />'
'<input name="post[title]" type="text" value="Hello World" />' +
'<input name="post[author_attributes][name]" type="text" value="author #321" />' +
'<input name="post[author_attributes][id]" type="hidden" value="321" />'
end
assert_dom_equal expected, output_buffer
@ -1103,8 +1103,8 @@ def test_nested_fields_with_an_existing_record_on_a_nested_attributes_one_to_one
end
expected = whole_form("/posts/123", method: "patch") do
'<input name="post[title]" type="text" id="post_title" value="Hello World" />' +
'<input id="post_author_attributes_name" name="post[author_attributes][name]" type="text" value="author #321" />'
'<input name="post[title]" type="text" value="Hello World" />' +
'<input name="post[author_attributes][name]" type="text" value="author #321" />'
end
assert_dom_equal expected, output_buffer
@ -1121,8 +1121,8 @@ def test_nested_fields_with_an_existing_record_on_a_nested_attributes_one_to_one
end
expected = whole_form("/posts/123", method: "patch") do
'<input name="post[title]" type="text" id="post_title" value="Hello World" />' +
'<input id="post_author_attributes_name" name="post[author_attributes][name]" type="text" value="author #321" />'
'<input name="post[title]" type="text" value="Hello World" />' +
'<input name="post[author_attributes][name]" type="text" value="author #321" />'
end
assert_dom_equal expected, output_buffer
@ -1139,9 +1139,9 @@ def test_nested_fields_with_an_existing_record_on_a_nested_attributes_one_to_one
end
expected = whole_form("/posts/123", method: "patch") do
'<input name="post[title]" type="text" id="post_title" value="Hello World" />' +
'<input id="post_author_attributes_name" name="post[author_attributes][name]" type="text" value="author #321" />' +
'<input id="post_author_attributes_id" name="post[author_attributes][id]" type="hidden" value="321" />'
'<input name="post[title]" type="text" value="Hello World" />' +
'<input name="post[author_attributes][name]" type="text" value="author #321" />' +
'<input name="post[author_attributes][id]" type="hidden" value="321" />'
end
assert_dom_equal expected, output_buffer
@ -1159,9 +1159,9 @@ def test_nested_fields_with_existing_records_on_a_nested_attributes_one_to_one_a
end
expected = whole_form("/posts/123", method: "patch") do
'<input name="post[title]" type="text" id="post_title" value="Hello World" />' +
'<input id="post_author_attributes_id" name="post[author_attributes][id]" type="hidden" value="321" />' +
'<input id="post_author_attributes_name" name="post[author_attributes][name]" type="text" value="author #321" />'
'<input name="post[title]" type="text" value="Hello World" />' +
'<input name="post[author_attributes][id]" type="hidden" value="321" />' +
'<input name="post[author_attributes][name]" type="text" value="author #321" />'
end
assert_dom_equal expected, output_buffer
@ -1180,11 +1180,11 @@ def test_nested_fields_with_existing_records_on_a_nested_attributes_collection_a
end
expected = whole_form("/posts/123", method: "patch") do
'<input name="post[title]" type="text" id="post_title" value="Hello World" />' +
'<input id="post_comments_attributes_0_name" name="post[comments_attributes][0][name]" type="text" value="comment #1" />' +
'<input id="post_comments_attributes_0_id" name="post[comments_attributes][0][id]" type="hidden" value="1" />' +
'<input id="post_comments_attributes_1_name" name="post[comments_attributes][1][name]" type="text" value="comment #2" />' +
'<input id="post_comments_attributes_1_id" name="post[comments_attributes][1][id]" type="hidden" value="2" />'
'<input name="post[title]" type="text" value="Hello World" />' +
'<input name="post[comments_attributes][0][name]" type="text" value="comment #1" />' +
'<input name="post[comments_attributes][0][id]" type="hidden" value="1" />' +
'<input name="post[comments_attributes][1][name]" type="text" value="comment #2" />' +
'<input name="post[comments_attributes][1][id]" type="hidden" value="2" />'
end
assert_dom_equal expected, output_buffer
@ -1207,11 +1207,11 @@ def test_nested_fields_with_existing_records_on_a_nested_attributes_collection_a
end
expected = whole_form("/posts/123", method: "patch") do
'<input name="post[title]" type="text" id="post_title" value="Hello World" />' +
'<input id="post_author_attributes_name" name="post[author_attributes][name]" type="text" value="author #321" />' +
'<input id="post_author_attributes_id" name="post[author_attributes][id]" type="hidden" value="321" />' +
'<input id="post_comments_attributes_0_name" name="post[comments_attributes][0][name]" type="text" value="comment #1" />' +
'<input id="post_comments_attributes_1_name" name="post[comments_attributes][1][name]" type="text" value="comment #2" />'
'<input name="post[title]" type="text" value="Hello World" />' +
'<input name="post[author_attributes][name]" type="text" value="author #321" />' +
'<input name="post[author_attributes][id]" type="hidden" value="321" />' +
'<input name="post[comments_attributes][0][name]" type="text" value="comment #1" />' +
'<input name="post[comments_attributes][1][name]" type="text" value="comment #2" />'
end
assert_dom_equal expected, output_buffer
@ -1234,10 +1234,10 @@ def test_nested_fields_with_existing_records_on_a_nested_attributes_collection_a
end
expected = whole_form("/posts/123", method: "patch") do
'<input name="post[title]" type="text" id="post_title" value="Hello World" />' +
'<input id="post_author_attributes_name" name="post[author_attributes][name]" type="text" value="author #321" />' +
'<input id="post_comments_attributes_0_name" name="post[comments_attributes][0][name]" type="text" value="comment #1" />' +
'<input id="post_comments_attributes_1_name" name="post[comments_attributes][1][name]" type="text" value="comment #2" />'
'<input name="post[title]" type="text" value="Hello World" />' +
'<input name="post[author_attributes][name]" type="text" value="author #321" />' +
'<input name="post[comments_attributes][0][name]" type="text" value="comment #1" />' +
'<input name="post[comments_attributes][1][name]" type="text" value="comment #2" />'
end
assert_dom_equal expected, output_buffer
@ -1260,11 +1260,11 @@ def test_nested_fields_with_existing_records_on_a_nested_attributes_collection_a
end
expected = whole_form("/posts/123", method: "patch") do
'<input name="post[title]" type="text" id="post_title" value="Hello World" />' +
'<input id="post_author_attributes_name" name="post[author_attributes][name]" type="text" value="author #321" />' +
'<input id="post_author_attributes_id" name="post[author_attributes][id]" type="hidden" value="321" />' +
'<input id="post_comments_attributes_0_name" name="post[comments_attributes][0][name]" type="text" value="comment #1" />' +
'<input id="post_comments_attributes_1_name" name="post[comments_attributes][1][name]" type="text" value="comment #2" />'
'<input name="post[title]" type="text" value="Hello World" />' +
'<input name="post[author_attributes][name]" type="text" value="author #321" />' +
'<input name="post[author_attributes][id]" type="hidden" value="321" />' +
'<input name="post[comments_attributes][0][name]" type="text" value="comment #1" />' +
'<input name="post[comments_attributes][1][name]" type="text" value="comment #2" />'
end
assert_dom_equal expected, output_buffer
@ -1283,11 +1283,11 @@ def test_nested_fields_with_existing_records_on_a_nested_attributes_collection_a
end
expected = whole_form("/posts/123", method: "patch") do
'<input name="post[title]" type="text" id="post_title" value="Hello World" />' +
'<input id="post_comments_attributes_0_name" name="post[comments_attributes][0][name]" type="text" value="comment #1" />' +
'<input id="post_comments_attributes_0_id" name="post[comments_attributes][0][id]" type="hidden" value="1" />' +
'<input id="post_comments_attributes_1_name" name="post[comments_attributes][1][name]" type="text" value="comment #2" />' +
'<input id="post_comments_attributes_1_id" name="post[comments_attributes][1][id]" type="hidden" value="2" />'
'<input name="post[title]" type="text" value="Hello World" />' +
'<input name="post[comments_attributes][0][name]" type="text" value="comment #1" />' +
'<input name="post[comments_attributes][0][id]" type="hidden" value="1" />' +
'<input name="post[comments_attributes][1][name]" type="text" value="comment #2" />' +
'<input name="post[comments_attributes][1][id]" type="hidden" value="2" />'
end
assert_dom_equal expected, output_buffer
@ -1307,11 +1307,11 @@ def test_nested_fields_with_existing_records_on_a_nested_attributes_collection_a
end
expected = whole_form("/posts/123", method: "patch") do
'<input name="post[title]" type="text" id="post_title" value="Hello World" />' +
'<input id="post_comments_attributes_0_id" name="post[comments_attributes][0][id]" type="hidden" value="1" />' +
'<input id="post_comments_attributes_0_name" name="post[comments_attributes][0][name]" type="text" value="comment #1" />' +
'<input id="post_comments_attributes_1_id" name="post[comments_attributes][1][id]" type="hidden" value="2" />' +
'<input id="post_comments_attributes_1_name" name="post[comments_attributes][1][name]" type="text" value="comment #2" />'
'<input name="post[title]" type="text" value="Hello World" />' +
'<input name="post[comments_attributes][0][id]" type="hidden" value="1" />' +
'<input name="post[comments_attributes][0][name]" type="text" value="comment #1" />' +
'<input name="post[comments_attributes][1][id]" type="hidden" value="2" />' +
'<input name="post[comments_attributes][1][name]" type="text" value="comment #2" />'
end
assert_dom_equal expected, output_buffer
@ -1330,9 +1330,9 @@ def test_nested_fields_with_new_records_on_a_nested_attributes_collection_associ
end
expected = whole_form("/posts/123", method: "patch") do
'<input name="post[title]" type="text" id="post_title" value="Hello World" />' +
'<input id="post_comments_attributes_0_name" name="post[comments_attributes][0][name]" type="text" value="new comment" />' +
'<input id="post_comments_attributes_1_name" name="post[comments_attributes][1][name]" type="text" value="new comment" />'
'<input name="post[title]" type="text" value="Hello World" />' +
'<input name="post[comments_attributes][0][name]" type="text" value="new comment" />' +
'<input name="post[comments_attributes][1][name]" type="text" value="new comment" />'
end
assert_dom_equal expected, output_buffer
@ -1351,10 +1351,10 @@ def test_nested_fields_with_existing_and_new_records_on_a_nested_attributes_coll
end
expected = whole_form("/posts/123", method: "patch") do
'<input name="post[title]" type="text" id="post_title" value="Hello World" />' +
'<input id="post_comments_attributes_0_name" name="post[comments_attributes][0][name]" type="text" value="comment #321" />' +
'<input id="post_comments_attributes_0_id" name="post[comments_attributes][0][id]" type="hidden" value="321" />' +
'<input id="post_comments_attributes_1_name" name="post[comments_attributes][1][name]" type="text" value="new comment" />'
'<input name="post[title]" type="text" value="Hello World" />' +
'<input name="post[comments_attributes][0][name]" type="text" value="comment #321" />' +
'<input name="post[comments_attributes][0][id]" type="hidden" value="321" />' +
'<input name="post[comments_attributes][1][name]" type="text" value="new comment" />'
end
assert_dom_equal expected, output_buffer
@ -1369,7 +1369,7 @@ def test_nested_fields_with_an_empty_supplied_attributes_collection
end
expected = whole_form("/posts/123", method: "patch") do
'<input name="post[title]" type="text" id="post_title" value="Hello World" />'
'<input name="post[title]" type="text" value="Hello World" />'
end
assert_dom_equal expected, output_buffer
@ -1386,11 +1386,11 @@ def test_nested_fields_with_existing_records_on_a_supplied_nested_attributes_col
end
expected = whole_form("/posts/123", method: "patch") do
'<input name="post[title]" type="text" id="post_title" value="Hello World" />' +
'<input id="post_comments_attributes_0_name" name="post[comments_attributes][0][name]" type="text" value="comment #1" />' +
'<input id="post_comments_attributes_0_id" name="post[comments_attributes][0][id]" type="hidden" value="1" />' +
'<input id="post_comments_attributes_1_name" name="post[comments_attributes][1][name]" type="text" value="comment #2" />' +
'<input id="post_comments_attributes_1_id" name="post[comments_attributes][1][id]" type="hidden" value="2" />'
'<input name="post[title]" type="text" value="Hello World" />' +
'<input name="post[comments_attributes][0][name]" type="text" value="comment #1" />' +
'<input name="post[comments_attributes][0][id]" type="hidden" value="1" />' +
'<input name="post[comments_attributes][1][name]" type="text" value="comment #2" />' +
'<input name="post[comments_attributes][1][id]" type="hidden" value="2" />'
end
assert_dom_equal expected, output_buffer
@ -1407,11 +1407,11 @@ def test_nested_fields_arel_like
end
expected = whole_form("/posts/123", method: "patch") do
'<input name="post[title]" type="text" id="post_title" value="Hello World" />' +
'<input id="post_comments_attributes_0_name" name="post[comments_attributes][0][name]" type="text" value="comment #1" />' +
'<input id="post_comments_attributes_0_id" name="post[comments_attributes][0][id]" type="hidden" value="1" />' +
'<input id="post_comments_attributes_1_name" name="post[comments_attributes][1][name]" type="text" value="comment #2" />' +
'<input id="post_comments_attributes_1_id" name="post[comments_attributes][1][id]" type="hidden" value="2" />'
'<input name="post[title]" type="text" value="Hello World" />' +
'<input name="post[comments_attributes][0][name]" type="text" value="comment #1" />' +
'<input name="post[comments_attributes][0][id]" type="hidden" value="1" />' +
'<input name="post[comments_attributes][1][name]" type="text" value="comment #2" />' +
'<input name="post[comments_attributes][1][id]" type="hidden" value="2" />'
end
assert_dom_equal expected, output_buffer
@ -1442,11 +1442,11 @@ def test_nested_fields_with_existing_records_on_a_supplied_nested_attributes_col
end
expected = whole_form("/posts/123", method: "patch") do
'<input name="post[title]" type="text" id="post_title" value="Hello World" />' +
'<input id="post_comments_attributes_0_name" name="post[comments_attributes][0][name]" type="text" value="comment #1" />' +
'<input id="post_comments_attributes_0_id" name="post[comments_attributes][0][id]" type="hidden" value="1" />' +
'<input id="post_comments_attributes_1_name" name="post[comments_attributes][1][name]" type="text" value="comment #2" />' +
'<input id="post_comments_attributes_1_id" name="post[comments_attributes][1][id]" type="hidden" value="2" />'
'<input name="post[title]" type="text" value="Hello World" />' +
'<input name="post[comments_attributes][0][name]" type="text" value="comment #1" />' +
'<input name="post[comments_attributes][0][id]" type="hidden" value="1" />' +
'<input name="post[comments_attributes][1][name]" type="text" value="comment #2" />' +
'<input name="post[comments_attributes][1][id]" type="hidden" value="2" />'
end
assert_dom_equal expected, output_buffer
@ -1465,10 +1465,10 @@ def test_nested_fields_on_a_nested_attributes_collection_association_yields_only
end
expected = whole_form("/posts/123", method: "patch") do
'<input name="post[title]" type="text" id="post_title" value="Hello World" />' +
'<input id="post_comments_attributes_0_name" name="post[comments_attributes][0][name]" type="text" value="comment #321" />' +
'<input id="post_comments_attributes_0_id" name="post[comments_attributes][0][id]" type="hidden" value="321" />' +
'<input id="post_comments_attributes_1_name" name="post[comments_attributes][1][name]" type="text" value="new comment" />'
'<input name="post[title]" type="text" value="Hello World" />' +
'<input name="post[comments_attributes][0][name]" type="text" value="comment #321" />' +
'<input name="post[comments_attributes][0][id]" type="hidden" value="321" />' +
'<input name="post[comments_attributes][1][name]" type="text" value="new comment" />'
end
assert_dom_equal expected, output_buffer
@ -1485,8 +1485,8 @@ def test_nested_fields_with_child_index_option_override_on_a_nested_attributes_c
end
expected = whole_form("/posts/123", method: "patch") do
'<input id="post_comments_attributes_abc_name" name="post[comments_attributes][abc][name]" type="text" value="comment #321" />' +
'<input id="post_comments_attributes_abc_id" name="post[comments_attributes][abc][id]" type="hidden" value="321" />'
'<input name="post[comments_attributes][abc][name]" type="text" value="comment #321" />' +
'<input name="post[comments_attributes][abc][id]" type="hidden" value="321" />'
end
assert_dom_equal expected, output_buffer
@ -1502,8 +1502,8 @@ def test_nested_fields_with_child_index_as_lambda_option_override_on_a_nested_at
end
expected = whole_form("/posts/123", method: "patch") do
'<input id="post_comments_attributes_abc_name" name="post[comments_attributes][abc][name]" type="text" value="comment #321" />' +
'<input id="post_comments_attributes_abc_id" name="post[comments_attributes][abc][id]" type="hidden" value="321" />'
'<input name="post[comments_attributes][abc][name]" type="text" value="comment #321" />' +
'<input name="post[comments_attributes][abc][id]" type="hidden" value="321" />'
end
assert_dom_equal expected, output_buffer
@ -1525,8 +1525,8 @@ def test_nested_fields_with_child_index_option_override_on_a_nested_attributes_c
end
expected = whole_form("/posts/123", method: "patch") do
'<input id="post_comments_attributes_abc_name" name="post[comments_attributes][abc][name]" type="text" value="comment #321" />' +
'<input id="post_comments_attributes_abc_id" name="post[comments_attributes][abc][id]" type="hidden" value="321" />'
'<input name="post[comments_attributes][abc][name]" type="text" value="comment #321" />' +
'<input name="post[comments_attributes][abc][id]" type="hidden" value="321" />'
end
assert_dom_equal expected, output_buffer
@ -1611,18 +1611,18 @@ def test_nested_fields_uses_unique_indices_for_different_collection_associations
end
expected = whole_form("/posts/123", method: "patch") do
'<input id="post_comments_attributes_0_name" name="post[comments_attributes][0][name]" type="text" value="comment #321" />' +
'<input id="post_comments_attributes_0_relevances_attributes_0_value" name="post[comments_attributes][0][relevances_attributes][0][value]" type="text" value="commentrelevance #314" />' +
'<input id="post_comments_attributes_0_relevances_attributes_0_id" name="post[comments_attributes][0][relevances_attributes][0][id]" type="hidden" value="314" />' +
'<input id="post_comments_attributes_0_id" name="post[comments_attributes][0][id]" type="hidden" value="321" />' +
'<input id="post_tags_attributes_0_value" name="post[tags_attributes][0][value]" type="text" value="tag #123" />' +
'<input id="post_tags_attributes_0_relevances_attributes_0_value" name="post[tags_attributes][0][relevances_attributes][0][value]" type="text" value="tagrelevance #3141" />' +
'<input id="post_tags_attributes_0_relevances_attributes_0_id" name="post[tags_attributes][0][relevances_attributes][0][id]" type="hidden" value="3141" />' +
'<input id="post_tags_attributes_0_id" name="post[tags_attributes][0][id]" type="hidden" value="123" />' +
'<input id="post_tags_attributes_1_value" name="post[tags_attributes][1][value]" type="text" value="tag #456" />' +
'<input id="post_tags_attributes_1_relevances_attributes_0_value" name="post[tags_attributes][1][relevances_attributes][0][value]" type="text" value="tagrelevance #31415" />' +
'<input id="post_tags_attributes_1_relevances_attributes_0_id" name="post[tags_attributes][1][relevances_attributes][0][id]" type="hidden" value="31415" />' +
'<input id="post_tags_attributes_1_id" name="post[tags_attributes][1][id]" type="hidden" value="456" />'
'<input name="post[comments_attributes][0][name]" type="text" value="comment #321" />' +
'<input name="post[comments_attributes][0][relevances_attributes][0][value]" type="text" value="commentrelevance #314" />' +
'<input name="post[comments_attributes][0][relevances_attributes][0][id]" type="hidden" value="314" />' +
'<input name="post[comments_attributes][0][id]" type="hidden" value="321" />' +
'<input name="post[tags_attributes][0][value]" type="text" value="tag #123" />' +
'<input name="post[tags_attributes][0][relevances_attributes][0][value]" type="text" value="tagrelevance #3141" />' +
'<input name="post[tags_attributes][0][relevances_attributes][0][id]" type="hidden" value="3141" />' +
'<input name="post[tags_attributes][0][id]" type="hidden" value="123" />' +
'<input name="post[tags_attributes][1][value]" type="text" value="tag #456" />' +
'<input name="post[tags_attributes][1][relevances_attributes][0][value]" type="text" value="tagrelevance #31415" />' +
'<input name="post[tags_attributes][1][relevances_attributes][0][id]" type="hidden" value="31415" />' +
'<input name="post[tags_attributes][1][id]" type="hidden" value="456" />'
end
assert_dom_equal expected, output_buffer
@ -1638,7 +1638,7 @@ def test_nested_fields_with_hash_like_model
end
expected = whole_form("/posts/123", method: "patch") do
'<input id="post_author_attributes_name" name="post[author_attributes][name]" type="text" value="hash backed author" />'
'<input name="post[author_attributes][name]" type="text" value="hash backed author" />'
end
assert_dom_equal expected, output_buffer
@ -1652,10 +1652,10 @@ def test_fields
end
expected =
"<input name='post[title]' type='text' id='post_title' value='Hello World' />" +
"<textarea name='post[body]' id='post_body'>\nBack to the hill and over it again!</textarea>" +
"<input name='post[title]' type='text' value='Hello World' />" +
"<textarea name='post[body]'>\nBack to the hill and over it again!</textarea>" +
"<input name='post[secret]' type='hidden' value='0' />" +
"<input name='post[secret]' checked='checked' type='checkbox' id='post_secret' value='1' />"
"<input name='post[secret]' checked='checked' type='checkbox' value='1' />"
assert_dom_equal expected, output_buffer
end
@ -1668,10 +1668,10 @@ def test_fields_with_index
end
expected =
"<input name='post[123][title]' type='text' id='post_123_title' value='Hello World' />" +
"<textarea name='post[123][body]' id='post_123_body'>\nBack to the hill and over it again!</textarea>" +
"<input name='post[123][title]' type='text' value='Hello World' />" +
"<textarea name='post[123][body]'>\nBack to the hill and over it again!</textarea>" +
"<input name='post[123][secret]' type='hidden' value='0' />" +
"<input name='post[123][secret]' checked='checked' type='checkbox' id='post_123_secret' value='1' />"
"<input name='post[123][secret]' checked='checked' type='checkbox' value='1' />"
assert_dom_equal expected, output_buffer
end
@ -1684,10 +1684,10 @@ def test_fields_with_nil_index_option_override
end
expected =
"<input name='post[][title]' type='text' id='post__title' value='Hello World' />" +
"<textarea name='post[][body]' id='post__body'>\nBack to the hill and over it again!</textarea>" +
"<input name='post[][title]' type='text' value='Hello World' />" +
"<textarea name='post[][body]'>\nBack to the hill and over it again!</textarea>" +
"<input name='post[][secret]' type='hidden' value='0' />" +
"<input name='post[][secret]' checked='checked' type='checkbox' id='post__secret' value='1' />"
"<input name='post[][secret]' checked='checked' type='checkbox' value='1' />"
assert_dom_equal expected, output_buffer
end
@ -1700,10 +1700,10 @@ def test_fields_with_index_option_override
end
expected =
"<input name='post[abc][title]' type='text' id='post_abc_title' value='Hello World' />" +
"<textarea name='post[abc][body]' id='post_abc_body'>\nBack to the hill and over it again!</textarea>" +
"<input name='post[abc][title]' type='text' value='Hello World' />" +
"<textarea name='post[abc][body]'>\nBack to the hill and over it again!</textarea>" +
"<input name='post[abc][secret]' type='hidden' value='0' />" +
"<input name='post[abc][secret]' checked='checked' type='checkbox' id='post_abc_secret' value='1' />"
"<input name='post[abc][secret]' checked='checked' type='checkbox' value='1' />"
assert_dom_equal expected, output_buffer
end
@ -1716,10 +1716,10 @@ def test_fields_without_object
end
expected =
"<input name='post[title]' type='text' id='post_title' value='Hello World' />" +
"<textarea name='post[body]' id='post_body'>\nBack to the hill and over it again!</textarea>" +
"<input name='post[title]' type='text' value='Hello World' />" +
"<textarea name='post[body]'>\nBack to the hill and over it again!</textarea>" +
"<input name='post[secret]' type='hidden' value='0' />" +
"<input name='post[secret]' checked='checked' type='checkbox' id='post_secret' value='1' />"
"<input name='post[secret]' checked='checked' type='checkbox' value='1' />"
assert_dom_equal expected, output_buffer
end
@ -1732,10 +1732,10 @@ def test_fields_with_only_object
end
expected =
"<input name='post[title]' type='text' id='post_title' value='Hello World' />" +
"<textarea name='post[body]' id='post_body'>\nBack to the hill and over it again!</textarea>" +
"<input name='post[title]' type='text' value='Hello World' />" +
"<textarea name='post[body]'>\nBack to the hill and over it again!</textarea>" +
"<input name='post[secret]' type='hidden' value='0' />" +
"<input name='post[secret]' checked='checked' type='checkbox' id='post_secret' value='1' />"
"<input name='post[secret]' checked='checked' type='checkbox' value='1' />"
assert_dom_equal expected, output_buffer
end
@ -1747,7 +1747,7 @@ def test_fields_object_with_bracketed_name
end
assert_dom_equal "<label for=\"author_post_title\">Title</label>" +
"<input name='author[post][title]' type='text' id='author_post_title' value='Hello World' />",
"<input name='author[post][title]' type='text' value='Hello World' />",
output_buffer
end
@ -1758,7 +1758,7 @@ def test_fields_object_with_bracketed_name_and_index
end
assert_dom_equal "<label for=\"author_post_1_title\">Title</label>" +
"<input name='author[post][1][title]' type='text' id='author_post_1_title' value='Hello World' />",
"<input name='author[post][1][title]' type='text' value='Hello World' />",
output_buffer
end
@ -1777,10 +1777,10 @@ def test_form_with_and_fields
end
expected = whole_form("/posts/123", "create-post", method: "patch") do
"<input name='post[title]' type='text' id='post_title' value='Hello World' />" +
"<textarea name='post[body]' id='post_body'>\nBack to the hill and over it again!</textarea>" +
"<input name='post[title]' type='text' value='Hello World' />" +
"<textarea name='post[body]'>\nBack to the hill and over it again!</textarea>" +
"<input name='parent_post[secret]' type='hidden' value='0' />" +
"<input name='parent_post[secret]' checked='checked' type='checkbox' id='parent_post_secret' value='1' />"
"<input name='parent_post[secret]' checked='checked' type='checkbox' value='1' />"
end
assert_dom_equal expected, output_buffer
@ -1797,9 +1797,9 @@ def test_form_with_and_fields_with_object
end
expected = whole_form("/posts/123", "create-post", method: "patch") do
"<input name='post[title]' type='text' id='post_title' value='Hello World' />" +
"<textarea name='post[body]' id='post_body'>\nBack to the hill and over it again!</textarea>" +
"<input name='post[comment][name]' type='text' id='post_comment_name' value='new comment' />"
"<input name='post[title]' type='text' value='Hello World' />" +
"<textarea name='post[body]'>\nBack to the hill and over it again!</textarea>" +
"<input name='post[comment][name]' type='text' value='new comment' />"
end
assert_dom_equal expected, output_buffer
@ -1813,7 +1813,7 @@ def test_form_with_and_fields_with_non_nested_association_and_without_object
end
expected = whole_form("/posts/123", method: "patch") do
"<input name='post[category][name]' type='text' id='post_category_name' />"
"<input name='post[category][name]' type='text' />"
end
assert_dom_equal expected, output_buffer
@ -1837,9 +1837,9 @@ def test_form_with_with_labelled_builder
end
expected = whole_form("/posts/123", method: "patch") do
"<label for='title'>Title:</label> <input name='post[title]' type='text' id='post_title' value='Hello World' /><br/>" +
"<label for='body'>Body:</label> <textarea name='post[body]' id='post_body'>\nBack to the hill and over it again!</textarea><br/>" +
"<label for='secret'>Secret:</label> <input name='post[secret]' type='hidden' value='0' /><input name='post[secret]' checked='checked' type='checkbox' id='post_secret' value='1' /><br/>"
"<label for='title'>Title:</label> <input name='post[title]' type='text' value='Hello World' /><br/>" +
"<label for='body'>Body:</label> <textarea name='post[body]'>\nBack to the hill and over it again!</textarea><br/>" +
"<label for='secret'>Secret:</label> <input name='post[secret]' type='hidden' value='0' /><input name='post[secret]' checked='checked' type='checkbox' value='1' /><br/>"
end
assert_dom_equal expected, output_buffer
@ -1856,9 +1856,9 @@ def test_default_form_builder
end
expected = whole_form("/posts/123", method: "patch") do
"<label for='title'>Title:</label> <input name='post[title]' type='text' id='post_title' value='Hello World' /><br/>" +
"<label for='body'>Body:</label> <textarea name='post[body]' id='post_body'>\nBack to the hill and over it again!</textarea><br/>" +
"<label for='secret'>Secret:</label> <input name='post[secret]' type='hidden' value='0' /><input name='post[secret]' checked='checked' type='checkbox' id='post_secret' value='1' /><br/>"
"<label for='title'>Title:</label> <input name='post[title]' type='text' value='Hello World' /><br/>" +
"<label for='body'>Body:</label> <textarea name='post[body]'>\nBack to the hill and over it again!</textarea><br/>" +
"<label for='secret'>Secret:</label> <input name='post[secret]' type='hidden' value='0' /><input name='post[secret]' checked='checked' type='checkbox' value='1' /><br/>"
end
assert_dom_equal expected, output_buffer
@ -1875,7 +1875,7 @@ def test_lazy_loading_default_form_builder
end
expected = whole_form("/posts/123", method: "patch") do
"<label for='title'>Title:</label> <input name='post[title]' type='text' id='post_title' value='Hello World' /><br/>"
"<label for='title'>Title:</label> <input name='post[title]' type='text' value='Hello World' /><br/>"
end
assert_dom_equal expected, output_buffer
@ -1890,7 +1890,7 @@ def test_form_builder_override
concat f.text_field(:title)
end
expected = "<label for='title'>Title:</label> <input name='post[title]' type='text' id='post_title' value='Hello World' /><br/>"
expected = "<label for='title'>Title:</label> <input name='post[title]' type='text' value='Hello World' /><br/>"
assert_dom_equal expected, output_buffer
end
@ -1902,7 +1902,7 @@ def test_lazy_loading_form_builder_override
concat f.text_field(:title)
end
expected = "<label for='title'>Title:</label> <input name='post[title]' type='text' id='post_title' value='Hello World' /><br/>"
expected = "<label for='title'>Title:</label> <input name='post[title]' type='text' value='Hello World' /><br/>"
assert_dom_equal expected, output_buffer
end
@ -1915,9 +1915,9 @@ def test_fields_with_labelled_builder
end
expected =
"<label for='title'>Title:</label> <input name='post[title]' type='text' id='post_title' value='Hello World' /><br/>" +
"<label for='body'>Body:</label> <textarea name='post[body]' id='post_body'>\nBack to the hill and over it again!</textarea><br/>" +
"<label for='secret'>Secret:</label> <input name='post[secret]' type='hidden' value='0' /><input name='post[secret]' checked='checked' type='checkbox' id='post_secret' value='1' /><br/>"
"<label for='title'>Title:</label> <input name='post[title]' type='text' value='Hello World' /><br/>" +
"<label for='body'>Body:</label> <textarea name='post[body]'>\nBack to the hill and over it again!</textarea><br/>" +
"<label for='secret'>Secret:</label> <input name='post[secret]' type='hidden' value='0' /><input name='post[secret]' checked='checked' type='checkbox' value='1' /><br/>"
assert_dom_equal expected, output_buffer
end