aboutsummaryrefslogtreecommitdiffstats
path: root/actionview/test/activerecord/form_helper_activerecord_test.rb
diff options
context:
space:
mode:
Diffstat (limited to 'actionview/test/activerecord/form_helper_activerecord_test.rb')
-rw-r--r--actionview/test/activerecord/form_helper_activerecord_test.rb60
1 files changed, 30 insertions, 30 deletions
diff --git a/actionview/test/activerecord/form_helper_activerecord_test.rb b/actionview/test/activerecord/form_helper_activerecord_test.rb
index 2769b97445..0f7960b408 100644
--- a/actionview/test/activerecord/form_helper_activerecord_test.rb
+++ b/actionview/test/activerecord/form_helper_activerecord_test.rb
@@ -1,6 +1,6 @@
-require 'active_record_unit'
-require 'fixtures/project'
-require 'fixtures/developer'
+require "active_record_unit"
+require "fixtures/project"
+require "fixtures/developer"
class FormHelperActiveRecordTest < ActionView::TestCase
tests ActionView::Helpers::FormHelper
@@ -39,12 +39,12 @@ class FormHelperActiveRecordTest < ActionView::TestCase
def test_nested_fields_for_with_child_index_option_override_on_a_nested_attributes_collection_association
form_for(@developer) do |f|
- concat f.fields_for(:projects, @developer.projects.first, :child_index => 'abc') { |cf|
+ concat f.fields_for(:projects, @developer.projects.first, child_index: "abc") { |cf|
concat cf.text_field(:name)
}
end
- expected = whole_form('/developers/123', 'edit_developer_123', 'edit_developer', :method => 'patch') do
+ expected = whole_form("/developers/123", "edit_developer_123", "edit_developer", method: "patch") do
'<input id="developer_projects_attributes_abc_name" name="developer[projects_attributes][abc][name]" type="text" value="project #321" />' +
'<input id="developer_projects_attributes_abc_id" name="developer[projects_attributes][abc][id]" type="hidden" value="321" />'
end
@@ -52,37 +52,37 @@ class FormHelperActiveRecordTest < ActionView::TestCase
assert_dom_equal expected, output_buffer
end
- protected
+ private
- def hidden_fields(method = nil)
- txt = %{<input name="utf8" type="hidden" value="&#x2713;" />}
+ def hidden_fields(method = nil)
+ txt = %{<input name="utf8" type="hidden" value="&#x2713;" />}
- if method && !%w(get post).include?(method.to_s)
- txt << %{<input name="_method" type="hidden" value="#{method}" />}
+ if method && !%w(get post).include?(method.to_s)
+ txt << %{<input name="_method" type="hidden" value="#{method}" />}
+ end
+
+ txt
end
- txt
- end
+ def form_text(action = "/", id = nil, html_class = nil, remote = nil, multipart = nil, method = nil)
+ txt = %{<form accept-charset="UTF-8" action="#{action}"}
+ txt << %{ enctype="multipart/form-data"} if multipart
+ txt << %{ data-remote="true"} if remote
+ txt << %{ class="#{html_class}"} if html_class
+ txt << %{ id="#{id}"} if id
+ method = method.to_s == "get" ? "get" : "post"
+ txt << %{ method="#{method}">}
+ end
- def form_text(action = "/", id = nil, html_class = nil, remote = nil, multipart = nil, method = nil)
- txt = %{<form accept-charset="UTF-8" action="#{action}"}
- txt << %{ enctype="multipart/form-data"} if multipart
- txt << %{ data-remote="true"} if remote
- txt << %{ class="#{html_class}"} if html_class
- txt << %{ id="#{id}"} if id
- method = method.to_s == "get" ? "get" : "post"
- txt << %{ method="#{method}">}
- end
+ def whole_form(action = "/", id = nil, html_class = nil, options = nil)
+ contents = block_given? ? yield : ""
- def whole_form(action = "/", id = nil, html_class = nil, options = nil)
- contents = block_given? ? yield : ""
+ if options.is_a?(Hash)
+ method, remote, multipart = options.values_at(:method, :remote, :multipart)
+ else
+ method = options
+ end
- if options.is_a?(Hash)
- method, remote, multipart = options.values_at(:method, :remote, :multipart)
- else
- method = options
+ form_text(action, id, html_class, remote, multipart, method) + hidden_fields(method) + contents + "</form>"
end
-
- form_text(action, id, html_class, remote, multipart, method) + hidden_fields(method) + contents + "</form>"
- end
end