diff options
Diffstat (limited to 'actionview/test/template/form_helper')
-rw-r--r-- | actionview/test/template/form_helper/form_with_test.rb | 74 |
1 files changed, 29 insertions, 45 deletions
diff --git a/actionview/test/template/form_helper/form_with_test.rb b/actionview/test/template/form_helper/form_with_test.rb index bff0643fb0..c7d49070ce 100644 --- a/actionview/test/template/form_helper/form_with_test.rb +++ b/actionview/test/template/form_helper/form_with_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "abstract_unit" require "controller/fake_models" @@ -16,7 +18,7 @@ class FormWithActsLikeFormTagTest < FormWithTest method = options[:method] skip_enforcing_utf8 = options.fetch(:skip_enforcing_utf8, false) - "".tap do |txt| + "".dup.tap do |txt| unless skip_enforcing_utf8 txt << %{<input name="utf8" type="hidden" value="✓" />} end @@ -32,7 +34,7 @@ class FormWithActsLikeFormTagTest < FormWithTest method = method.to_s == "get" ? "get" : "post" - txt = %{<form accept-charset="UTF-8" action="#{action}"} + 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 @@ -403,9 +405,9 @@ class FormWithActsLikeFormForTest < FormWithTest expected = whole_form("/posts") do "<input type='hidden' name='post[active]' value='' />" \ - "<input name='post[active]' type='radio' value='true' />" \ + "<input name='post[active]' type='radio' value='true' id='post_active_true' />" \ "<label for='post_active_true'>true</label>" \ - "<input checked='checked' name='post[active]' type='radio' value='false' />" \ + "<input checked='checked' name='post[active]' type='radio' value='false' id='post_active_false' />" \ "<label for='post_active_false'>false</label>" end @@ -426,10 +428,10 @@ class FormWithActsLikeFormForTest < FormWithTest expected = whole_form("/posts") do "<input type='hidden' name='post[active]' value='' />" \ "<label for='post_active_true'>" \ - "<input name='post[active]' type='radio' value='true' />" \ + "<input name='post[active]' type='radio' value='true' id='post_active_true' />" \ "true</label>" \ "<label for='post_active_false'>" \ - "<input checked='checked' name='post[active]' type='radio' value='false' />" \ + "<input checked='checked' name='post[active]' type='radio' value='false' id='post_active_false' />" \ "false</label>" end @@ -452,10 +454,10 @@ class FormWithActsLikeFormForTest < FormWithTest expected = whole_form("/posts") do "<input type='hidden' name='post[active]' value='' />" \ "<label for='post_active_true'>" \ - "<input name='post[active]' type='radio' value='true' />" \ + "<input name='post[active]' type='radio' value='true' id='post_active_true' />" \ "true</label>" \ "<label for='post_active_false'>" \ - "<input checked='checked' name='post[active]' type='radio' value='false' />" \ + "<input checked='checked' name='post[active]' type='radio' value='false' id='post_active_false' />" \ "false</label>" \ "<input name='post[id]' type='hidden' value='1' />" end @@ -473,9 +475,9 @@ class FormWithActsLikeFormForTest < FormWithTest expected = whole_form("/posts") do "<input type='hidden' name='post[1][active]' value='' />" \ - "<input name='post[1][active]' type='radio' value='true' />" \ + "<input name='post[1][active]' type='radio' value='true' id='post_1_active_true' />" \ "<label for='post_1_active_true'>true</label>" \ - "<input checked='checked' name='post[1][active]' type='radio' value='false' />" \ + "<input checked='checked' name='post[1][active]' type='radio' value='false' id='post_1_active_false' />" \ "<label for='post_1_active_false'>false</label>" end @@ -492,11 +494,11 @@ class FormWithActsLikeFormForTest < FormWithTest expected = whole_form("/posts") do "<input name='post[tag_ids][]' type='hidden' value='' />" \ - "<input checked='checked' name='post[tag_ids][]' type='checkbox' value='1' />" \ + "<input checked='checked' name='post[tag_ids][]' type='checkbox' value='1' id='post_tag_ids_1' />" \ "<label for='post_tag_ids_1'>Tag 1</label>" \ - "<input name='post[tag_ids][]' type='checkbox' value='2' />" \ + "<input name='post[tag_ids][]' type='checkbox' value='2' id='post_tag_ids_2' />" \ "<label for='post_tag_ids_2'>Tag 2</label>" \ - "<input checked='checked' name='post[tag_ids][]' type='checkbox' value='3' />" \ + "<input checked='checked' name='post[tag_ids][]' type='checkbox' value='3' id='post_tag_ids_3' />" \ "<label for='post_tag_ids_3'>Tag 3</label>" end @@ -517,13 +519,13 @@ class FormWithActsLikeFormForTest < FormWithTest expected = whole_form("/posts") do "<input name='post[tag_ids][]' type='hidden' value='' />" \ "<label for='post_tag_ids_1'>" \ - "<input checked='checked' name='post[tag_ids][]' type='checkbox' value='1' />" \ + "<input checked='checked' name='post[tag_ids][]' type='checkbox' value='1' id='post_tag_ids_1' />" \ "Tag 1</label>" \ "<label for='post_tag_ids_2'>" \ - "<input name='post[tag_ids][]' type='checkbox' value='2' />" \ + "<input name='post[tag_ids][]' type='checkbox' value='2' id='post_tag_ids_2' />" \ "Tag 2</label>" \ "<label for='post_tag_ids_3'>" \ - "<input checked='checked' name='post[tag_ids][]' type='checkbox' value='3' />" \ + "<input checked='checked' name='post[tag_ids][]' type='checkbox' value='3' id='post_tag_ids_3' />" \ "Tag 3</label>" end @@ -547,13 +549,13 @@ class FormWithActsLikeFormForTest < FormWithTest expected = whole_form("/posts") do "<input name='post[tag_ids][]' type='hidden' value='' />" \ "<label for='post_tag_ids_1'>" \ - "<input checked='checked' name='post[tag_ids][]' type='checkbox' value='1' />" \ + "<input checked='checked' name='post[tag_ids][]' type='checkbox' value='1' id='post_tag_ids_1' />" \ "Tag 1</label>" \ "<label for='post_tag_ids_2'>" \ - "<input name='post[tag_ids][]' type='checkbox' value='2' />" \ + "<input name='post[tag_ids][]' type='checkbox' value='2' id='post_tag_ids_2' />" \ "Tag 2</label>" \ "<label for='post_tag_ids_3'>" \ - "<input checked='checked' name='post[tag_ids][]' type='checkbox' value='3' />" \ + "<input checked='checked' name='post[tag_ids][]' type='checkbox' value='3' id='post_tag_ids_3' />" \ "Tag 3</label>" \ "<input name='post[id]' type='hidden' value='1' />" end @@ -572,7 +574,7 @@ class FormWithActsLikeFormForTest < FormWithTest expected = whole_form("/posts") do "<input name='post[1][tag_ids][]' type='hidden' value='' />" \ - "<input checked='checked' name='post[1][tag_ids][]' type='checkbox' value='1' />" \ + "<input checked='checked' name='post[1][tag_ids][]' type='checkbox' value='1' id='post_1_tag_ids_1' />" \ "<label for='post_1_tag_ids_1'>Tag 1</label>" end @@ -878,24 +880,6 @@ class FormWithActsLikeFormForTest < FormWithTest assert_dom_equal expected, output_buffer end - def test_form_with_with_namespace - skip "Do namespaces still make sense?" - form_for(@post, namespace: "namespace") do |f| - concat f.text_field(:title) - concat f.text_area(:body) - concat f.check_box(:secret) - end - - expected = whole_form("/posts/123", "namespace_edit_post_123", "edit_post", method: "patch") do - "<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' value='1' />" - end - - assert_dom_equal expected, output_buffer - end - def test_submit_with_object_as_new_record_and_locale_strings with_locale :submit do @post.persisted = false @@ -1660,7 +1644,7 @@ class FormWithActsLikeFormForTest < FormWithTest expected = 0 @post.comments.each do |comment| f.fields(:comments, model: comment) { |cf| - assert_equal cf.index, expected + assert_equal expected, cf.index expected += 1 } end @@ -1674,7 +1658,7 @@ class FormWithActsLikeFormForTest < FormWithTest expected = 0 @post.comments.each do |comment| f.fields(:comments, model: comment) { |cf| - assert_equal cf.index, expected + assert_equal expected, cf.index expected += 1 } end @@ -1687,7 +1671,7 @@ class FormWithActsLikeFormForTest < FormWithTest form_with(model: @post) do |f| expected = 0 f.fields(:comments, model: @post.comments) { |cf| - assert_equal cf.index, expected + assert_equal expected, cf.index expected += 1 } end @@ -1698,7 +1682,7 @@ class FormWithActsLikeFormForTest < FormWithTest form_with(model: @post) do |f| f.fields(:comments, model: Comment.new(321), child_index: "abc") { |cf| - assert_equal cf.index, "abc" + assert_equal "abc", cf.index } end end @@ -2212,9 +2196,9 @@ class FormWithActsLikeFormForTest < FormWithTest method = options[:method] if options.fetch(:skip_enforcing_utf8, false) - txt = "" + txt = "".dup else - txt = %{<input name="utf8" type="hidden" value="✓" />} + txt = %{<input name="utf8" type="hidden" value="✓" />}.dup end if method && !%w(get post).include?(method.to_s) @@ -2225,7 +2209,7 @@ class FormWithActsLikeFormForTest < FormWithTest end def form_text(action = "/", id = nil, html_class = nil, local = nil, multipart = nil, method = nil) - txt = %{<form accept-charset="UTF-8" action="#{action}"} + txt = %{<form accept-charset="UTF-8" action="#{action}"}.dup txt << %{ enctype="multipart/form-data"} if multipart txt << %{ data-remote="true"} unless local txt << %{ class="#{html_class}"} if html_class |