1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Make form helpers work with <%=

This commit is contained in:
wycats 2010-03-09 23:41:39 -08:00
parent 4464b8e87b
commit 7b622786fc
10 changed files with 188 additions and 126 deletions

View file

@ -6,6 +6,7 @@ module ActionView
include ActionView::Helpers::TagHelper
include ActionView::Helpers::TextHelper
include ActionView::Helpers::JavaScriptHelper
include ActionView::Helpers::FormHelper
def content_tag(*, &block)
block_called_from_erb?(block) ? safe_concat(super) : super
@ -15,6 +16,22 @@ module ActionView
block_called_from_erb?(block) ? safe_concat(super) : super
end
def form_for(*, &block)
block_called_from_erb?(block) ? safe_concat(super) : super
end
def form_tag(*, &block)
block_called_from_erb?(block) ? safe_concat(super) : super
end
def fields_for(*, &block)
block_called_from_erb?(block) ? safe_concat(super) : super
end
def field_set_tag(*, &block)
block_called_from_erb?(block) ? safe_concat(super) : super
end
BLOCK_CALLED_FROM_ERB = 'defined? __in_erb_template'
if RUBY_VERSION < '1.9.0'

View file

@ -92,6 +92,10 @@ module ActionView
# link:classes/ActionView/Helpers/DateHelper.html, and
# link:classes/ActionView/Helpers/ActiveRecordHelper.html
module FormHelper
extend ActiveSupport::Concern
include FormTagHelper
# Creates a form and a scope around a specific model object that is used
# as a base for questioning about values for the fields.
#
@ -309,9 +313,9 @@ module ActionView
options[:html][:remote] = true if options.delete(:remote)
safe_concat(form_tag(options.delete(:url) || {}, options.delete(:html) || {}))
fields_for(object_name, *(args << options), &proc)
safe_concat('</form>')
output = form_tag(options.delete(:url) || {}, options.delete(:html) || {})
output << fields_for(object_name, *(args << options), &proc)
output.safe_concat('</form>')
end
def apply_form_for_options!(object_or_array, options) #:nodoc:
@ -528,7 +532,10 @@ module ActionView
end
builder = options[:builder] || ActionView::Base.default_form_builder
yield builder.new(object_name, object, self, options, block)
with_output_buffer do
yield builder.new(object_name, object, self, options, block)
end
end
# Returns a label tag tailored for labelling an input field for a specified attribute (identified by +method+) on an object
@ -1183,9 +1190,11 @@ module ActionView
if association.is_a?(Array)
explicit_child_index = options[:child_index]
association.map do |child|
fields_for_nested_model("#{name}[#{explicit_child_index || nested_child_index(name)}]", child, options, block)
end.join
output = ActiveSupport::SafeBuffer.new
association.each do |child|
output << fields_for_nested_model("#{name}[#{explicit_child_index || nested_child_index(name)}]", child, options, block)
end
output
elsif association
fields_for_nested_model(name, association, options, block)
end

View file

@ -97,7 +97,9 @@ module ActionView
# </select>
#
module FormOptionsHelper
# ERB::Util can mask some helpers like textilize. Make sure to include them.
include ERB::Util
include TextHelper
# Create a select tag and a series of contained option tags for the provided object and method.
# The option currently held by the object will be selected, provided that the object is available.

View file

@ -10,6 +10,11 @@ module ActionView
# NOTE: The HTML options <tt>disabled</tt>, <tt>readonly</tt>, and <tt>multiple</tt> can all be treated as booleans. So specifying
# <tt>:disabled => true</tt> will give <tt>disabled="disabled"</tt>.
module FormTagHelper
extend ActiveSupport::Concern
include UrlHelper
include TextHelper
# Starts a form tag that points the action to an url configured with <tt>url_for_options</tt> just like
# ActionController::Base#url_for. The method for the form defaults to POST.
#
@ -441,10 +446,10 @@ module ActionView
# # => <fieldset class="format"><p><input id="name" name="name" type="text" /></p></fieldset>
def field_set_tag(legend = nil, options = nil, &block)
content = capture(&block)
safe_concat(tag(:fieldset, options, true))
safe_concat(content_tag(:legend, legend)) unless legend.blank?
concat(content)
safe_concat("</fieldset>")
output = tag(:fieldset, options, true)
output.safe_concat(content_tag(:legend, legend)) unless legend.blank?
output.concat(content)
output.safe_concat("</fieldset>")
end
private
@ -477,9 +482,10 @@ module ActionView
def form_tag_in_block(html_options, &block)
content = capture(&block)
safe_concat(form_tag_html(html_options))
concat(content)
safe_concat("</form>")
output = ActiveSupport::SafeBuffer.new
output.safe_concat(form_tag_html(html_options))
output << content
output.safe_concat("</form>")
end
def token_tag

View file

@ -28,10 +28,18 @@ module ActionView
@buffer.to_s
end
def to_str
@buffer.to_str
end
def empty?
@buffer.empty?
end
def html_safe?
@buffer.html_safe?
end
if "".respond_to?(:force_encoding)
def force_encoding(encoding)
@buffer.force_encoding(encoding)

View file

@ -1250,7 +1250,7 @@ class DateHelperTest < ActionView::TestCase
@post = Post.new
@post.written_on = Date.new(2004, 6, 15)
fields_for :post, @post do |f|
output_buffer = fields_for :post, @post do |f|
concat f.date_select(:written_on)
end
@ -1266,7 +1266,7 @@ class DateHelperTest < ActionView::TestCase
@post.written_on = Date.new(2004, 6, 15)
id = 27
fields_for :post, @post, :index => id do |f|
output_buffer = fields_for :post, @post, :index => id do |f|
concat f.date_select(:written_on)
end
@ -1282,7 +1282,7 @@ class DateHelperTest < ActionView::TestCase
@post.written_on = Date.new(2004, 6, 15)
id = nil
fields_for :post, @post, :index => id do |f|
output_buffer = fields_for :post, @post, :index => id do |f|
concat f.date_select(:written_on)
end
@ -1478,7 +1478,7 @@ class DateHelperTest < ActionView::TestCase
@post = Post.new
@post.written_on = Date.new(2004, 6, 15)
fields_for :post, @post do |f|
output_buffer = fields_for :post, @post do |f|
concat f.date_select(:written_on, {}, :class => 'selector')
end
@ -1642,7 +1642,7 @@ class DateHelperTest < ActionView::TestCase
@post = Post.new
@post.written_on = Time.local(2004, 6, 15, 15, 16, 35)
fields_for :post, @post do |f|
output_buffer = fields_for :post, @post do |f|
concat f.time_select(:written_on, {}, :class => 'selector')
end
@ -1816,7 +1816,7 @@ class DateHelperTest < ActionView::TestCase
@post = Post.new
@post.updated_at = Time.local(2004, 6, 15, 16, 35)
fields_for :post, @post do |f|
output_buffer = fields_for :post, @post do |f|
concat f.datetime_select(:updated_at, {}, :class => 'selector')
end
@ -2052,7 +2052,7 @@ class DateHelperTest < ActionView::TestCase
@post.updated_at = Time.local(2004, 6, 15, 16, 35)
id = 456
fields_for :post, @post, :index => id do |f|
output_buffer = fields_for :post, @post, :index => id do |f|
concat f.datetime_select(:updated_at)
end

View file

@ -1,6 +1,28 @@
require "abstract_unit"
module ERBTest
class ViewContext
mock_controller = Class.new do
include SharedTestRoutes.url_helpers
end
include ActionView::Helpers::TagHelper
include ActionView::Helpers::JavaScriptHelper
include ActionView::Helpers::FormHelper
attr_accessor :output_buffer
def protect_against_forgery?() false end
define_method(:controller) do
mock_controller.new
end
end
class DeprecatedViewContext < ViewContext
include ActionView::Helpers::DeprecatedBlockHelpers
end
module SharedTagHelpers
extend ActiveSupport::Testing::Declarative
@ -22,16 +44,21 @@ module ERBTest
expected_output = "<script id=\"the_js_tag\" type=\"text/javascript\">\n//<![CDATA[\nalert('Hello')\n//]]>\n</script>"
assert_equal expected_output, render_content("javascript_tag(:id => 'the_js_tag')", "alert('Hello')")
end
test "percent equals works with form tags" do
expected_output = "<form action=\"foo\" method=\"post\">hello</form>"
assert_equal expected_output, render_content("form_tag('foo')", "<%= 'hello' %>")
end
test "percent equals works with fieldset tags" do
expected_output = "<fieldset><legend>foo</legend>hello</fieldset>"
assert_equal expected_output, render_content("field_set_tag('foo')", "<%= 'hello' %>")
end
end
class TagHelperTest < ActiveSupport::TestCase
def context
Class.new do
include ActionView::Helpers::TagHelper
include ActionView::Helpers::JavaScriptHelper
attr_accessor :output_buffer
end
ViewContext
end
def block_helper(str, rest)
@ -43,12 +70,7 @@ module ERBTest
class DeprecatedTagHelperTest < ActiveSupport::TestCase
def context
Class.new do
include ActionView::Helpers::TagHelper
include ActionView::Helpers::JavaScriptHelper
include ActionView::Helpers::DeprecatedBlockHelpers
attr_accessor :output_buffer
end
DeprecatedViewContext
end
def block_helper(str, rest)

View file

@ -4,6 +4,10 @@ require 'controller/fake_models'
class FormHelperTest < ActionView::TestCase
tests ActionView::Helpers::FormHelper
def form_for(*)
@output_buffer = super
end
def setup
super
@ -590,9 +594,9 @@ class FormHelperTest < ActionView::TestCase
def test_nested_fields_for
form_for(:post, @post) do |f|
f.fields_for(:comment, @post) do |c|
concat f.fields_for(:comment, @post) { |c|
concat c.text_field(:title)
end
}
end
expected = "<form action='http://www.example.com' method='post'>" +
@ -605,9 +609,9 @@ class FormHelperTest < ActionView::TestCase
def test_nested_fields_for_with_nested_collections
form_for('post[]', @post) do |f|
concat f.text_field(:title)
f.fields_for('comment[]', @comment) do |c|
concat f.fields_for('comment[]', @comment) { |c|
concat c.text_field(:name)
end
}
end
expected = "<form action='http://www.example.com' method='post'>" +
@ -621,9 +625,9 @@ class FormHelperTest < ActionView::TestCase
def test_nested_fields_for_with_index_and_parent_fields
form_for('post', @post, :index => 1) do |c|
concat c.text_field(:title)
c.fields_for('comment', @comment, :index => 1) do |r|
concat c.fields_for('comment', @comment, :index => 1) { |r|
concat r.text_field(:name)
end
}
end
expected = "<form action='http://www.example.com' method='post'>" +
@ -635,10 +639,10 @@ class FormHelperTest < ActionView::TestCase
end
def test_form_for_with_index_and_nested_fields_for
form_for(:post, @post, :index => 1) do |f|
f.fields_for(:comment, @post) do |c|
output_buffer = form_for(:post, @post, :index => 1) do |f|
concat f.fields_for(:comment, @post) { |c|
concat c.text_field(:title)
end
}
end
expected = "<form action='http://www.example.com' method='post'>" +
@ -650,9 +654,9 @@ class FormHelperTest < ActionView::TestCase
def test_nested_fields_for_with_index_on_both
form_for(:post, @post, :index => 1) do |f|
f.fields_for(:comment, @post, :index => 5) do |c|
concat f.fields_for(:comment, @post, :index => 5) { |c|
concat c.text_field(:title)
end
}
end
expected = "<form action='http://www.example.com' method='post'>" +
@ -664,9 +668,9 @@ class FormHelperTest < ActionView::TestCase
def test_nested_fields_for_with_auto_index
form_for("post[]", @post) do |f|
f.fields_for(:comment, @post) do |c|
concat f.fields_for(:comment, @post) { |c|
concat c.text_field(:title)
end
}
end
expected = "<form action='http://www.example.com' method='post'>" +
@ -678,9 +682,9 @@ class FormHelperTest < ActionView::TestCase
def test_nested_fields_for_with_index_radio_button
form_for(:post, @post) do |f|
f.fields_for(:comment, @post, :index => 5) do |c|
concat f.fields_for(:comment, @post, :index => 5) { |c|
concat c.radio_button(:title, "hello")
end
}
end
expected = "<form action='http://www.example.com' method='post'>" +
@ -692,9 +696,9 @@ class FormHelperTest < ActionView::TestCase
def test_nested_fields_for_with_auto_index_on_both
form_for("post[]", @post) do |f|
f.fields_for("comment[]", @post) do |c|
concat f.fields_for("comment[]", @post) { |c|
concat c.text_field(:title)
end
}
end
expected = "<form action='http://www.example.com' method='post'>" +
@ -705,16 +709,16 @@ class FormHelperTest < ActionView::TestCase
end
def test_nested_fields_for_with_index_and_auto_index
form_for("post[]", @post) do |f|
f.fields_for(:comment, @post, :index => 5) do |c|
output_buffer = form_for("post[]", @post) do |f|
concat f.fields_for(:comment, @post, :index => 5) { |c|
concat c.text_field(:title)
end
}
end
form_for(:post, @post, :index => 1) do |f|
f.fields_for("comment[]", @post) do |c|
output_buffer << form_for(:post, @post, :index => 1) do |f|
concat f.fields_for("comment[]", @post) { |c|
concat c.text_field(:title)
end
}
end
expected = "<form action='http://www.example.com' method='post'>" +
@ -732,9 +736,9 @@ class FormHelperTest < ActionView::TestCase
form_for(:post, @post) do |f|
concat f.text_field(:title)
f.fields_for(:author) do |af|
concat f.fields_for(:author) { |af|
concat af.text_field(:name)
end
}
end
expected = '<form action="http://www.example.com" method="post">' +
@ -759,9 +763,9 @@ class FormHelperTest < ActionView::TestCase
form_for(:post, @post) do |f|
concat f.text_field(:title)
f.fields_for(:author) do |af|
concat f.fields_for(:author) { |af|
concat af.text_field(:name)
end
}
end
expected = '<form action="http://www.example.com" method="post">' +
@ -778,10 +782,10 @@ class FormHelperTest < ActionView::TestCase
form_for(:post, @post) do |f|
concat f.text_field(:title)
f.fields_for(:author) do |af|
concat f.fields_for(:author) { |af|
concat af.hidden_field(:id)
concat af.text_field(:name)
end
}
end
expected = '<form action="http://www.example.com" method="post">' +
@ -799,9 +803,9 @@ class FormHelperTest < ActionView::TestCase
form_for(:post, @post) do |f|
concat f.text_field(:title)
@post.comments.each do |comment|
f.fields_for(:comments, comment) do |cf|
concat f.fields_for(:comments, comment) { |cf|
concat cf.text_field(:name)
end
}
end
end
@ -822,10 +826,10 @@ class FormHelperTest < ActionView::TestCase
form_for(:post, @post) do |f|
concat f.text_field(:title)
@post.comments.each do |comment|
f.fields_for(:comments, comment) do |cf|
concat f.fields_for(:comments, comment) { |cf|
concat cf.hidden_field(:id)
concat cf.text_field(:name)
end
}
end
end
@ -846,9 +850,9 @@ class FormHelperTest < ActionView::TestCase
form_for(:post, @post) do |f|
concat f.text_field(:title)
@post.comments.each do |comment|
f.fields_for(:comments, comment) do |cf|
concat f.fields_for(:comments, comment) { |cf|
concat cf.text_field(:name)
end
}
end
end
@ -867,9 +871,9 @@ class FormHelperTest < ActionView::TestCase
form_for(:post, @post) do |f|
concat f.text_field(:title)
@post.comments.each do |comment|
f.fields_for(:comments, comment) do |cf|
concat f.fields_for(:comments, comment) { |cf|
concat cf.text_field(:name)
end
}
end
end
@ -903,9 +907,9 @@ class FormHelperTest < ActionView::TestCase
form_for(:post, @post) do |f|
concat f.text_field(:title)
f.fields_for(:comments, @post.comments) do |cf|
concat f.fields_for(:comments, @post.comments) { |cf|
concat cf.text_field(:name)
end
}
end
expected = '<form action="http://www.example.com" method="post">' +
@ -925,9 +929,9 @@ class FormHelperTest < ActionView::TestCase
form_for(:post, @post) do |f|
concat f.text_field(:title)
f.fields_for(:comments, comments) do |cf|
concat f.fields_for(:comments, comments) { |cf|
concat cf.text_field(:name)
end
}
end
expected = '<form action="http://www.example.com" method="post">' +
@ -947,10 +951,10 @@ class FormHelperTest < ActionView::TestCase
form_for(:post, @post) do |f|
concat f.text_field(:title)
f.fields_for(:comments) do |cf|
concat f.fields_for(:comments) { |cf|
concat cf.text_field(:name)
yielded_comments << cf.object
end
}
end
expected = '<form action="http://www.example.com" method="post">' +
@ -968,9 +972,9 @@ class FormHelperTest < ActionView::TestCase
@post.comments = []
form_for(:post, @post) do |f|
f.fields_for(:comments, Comment.new(321), :child_index => 'abc') do |cf|
concat f.fields_for(:comments, Comment.new(321), :child_index => 'abc') { |cf|
concat cf.text_field(:name)
end
}
end
expected = '<form action="http://www.example.com" method="post">' +
@ -988,24 +992,24 @@ class FormHelperTest < ActionView::TestCase
@post.tags[0].relevances = []
@post.tags[1].relevances = []
form_for(:post, @post) do |f|
f.fields_for(:comments, @post.comments[0]) do |cf|
concat f.fields_for(:comments, @post.comments[0]) { |cf|
concat cf.text_field(:name)
cf.fields_for(:relevances, CommentRelevance.new(314)) do |crf|
concat cf.fields_for(:relevances, CommentRelevance.new(314)) { |crf|
concat crf.text_field(:value)
end
end
f.fields_for(:tags, @post.tags[0]) do |tf|
}
}
concat f.fields_for(:tags, @post.tags[0]) { |tf|
concat tf.text_field(:value)
tf.fields_for(:relevances, TagRelevance.new(3141)) do |trf|
concat tf.fields_for(:relevances, TagRelevance.new(3141)) { |trf|
concat trf.text_field(:value)
end
end
f.fields_for('tags', @post.tags[1]) do |tf|
}
}
concat f.fields_for('tags', @post.tags[1]) { |tf|
concat tf.text_field(:value)
tf.fields_for(:relevances, TagRelevance.new(31415)) do |trf|
concat tf.fields_for(:relevances, TagRelevance.new(31415)) { |trf|
concat trf.text_field(:value)
end
end
}
}
end
expected = '<form action="http://www.example.com" method="post">' +
@ -1027,7 +1031,7 @@ class FormHelperTest < ActionView::TestCase
end
def test_fields_for
fields_for(:post, @post) do |f|
output_buffer = fields_for(:post, @post) do |f|
concat f.text_field(:title)
concat f.text_area(:body)
concat f.check_box(:secret)
@ -1043,7 +1047,7 @@ class FormHelperTest < ActionView::TestCase
end
def test_fields_for_with_index
fields_for("post[]", @post) do |f|
output_buffer = fields_for("post[]", @post) do |f|
concat f.text_field(:title)
concat f.text_area(:body)
concat f.check_box(:secret)
@ -1059,7 +1063,7 @@ class FormHelperTest < ActionView::TestCase
end
def test_fields_for_with_nil_index_option_override
fields_for("post[]", @post, :index => nil) do |f|
output_buffer = fields_for("post[]", @post, :index => nil) do |f|
concat f.text_field(:title)
concat f.text_area(:body)
concat f.check_box(:secret)
@ -1075,7 +1079,7 @@ class FormHelperTest < ActionView::TestCase
end
def test_fields_for_with_index_option_override
fields_for("post[]", @post, :index => "abc") do |f|
output_buffer = fields_for("post[]", @post, :index => "abc") do |f|
concat f.text_field(:title)
concat f.text_area(:body)
concat f.check_box(:secret)
@ -1091,7 +1095,7 @@ class FormHelperTest < ActionView::TestCase
end
def test_fields_for_without_object
fields_for(:post) do |f|
output_buffer = fields_for(:post) do |f|
concat f.text_field(:title)
concat f.text_area(:body)
concat f.check_box(:secret)
@ -1107,7 +1111,7 @@ class FormHelperTest < ActionView::TestCase
end
def test_fields_for_with_only_object
fields_for(@post) do |f|
output_buffer = fields_for(@post) do |f|
concat f.text_field(:title)
concat f.text_area(:body)
concat f.check_box(:secret)
@ -1123,7 +1127,7 @@ class FormHelperTest < ActionView::TestCase
end
def test_fields_for_object_with_bracketed_name
fields_for("author[post]", @post) do |f|
output_buffer = fields_for("author[post]", @post) do |f|
concat f.label(:title)
concat f.text_field(:title)
end
@ -1134,7 +1138,7 @@ class FormHelperTest < ActionView::TestCase
end
def test_fields_for_object_with_bracketed_name_and_index
fields_for("author[post]", @post, :index => 1) do |f|
output_buffer = fields_for("author[post]", @post, :index => 1) do |f|
concat f.label(:title)
concat f.text_field(:title)
end
@ -1153,9 +1157,9 @@ class FormHelperTest < ActionView::TestCase
concat post_form.text_field(:title)
concat post_form.text_area(:body)
fields_for(:parent_post, @post) do |parent_fields|
concat fields_for(:parent_post, @post) { |parent_fields|
concat parent_fields.check_box(:secret)
end
}
end
expected =
@ -1174,9 +1178,9 @@ class FormHelperTest < ActionView::TestCase
concat post_form.text_field(:title)
concat post_form.text_area(:body)
post_form.fields_for(@comment) do |comment_fields|
concat post_form.fields_for(@comment) { |comment_fields|
concat comment_fields.text_field(:name)
end
}
end
expected =
@ -1273,7 +1277,7 @@ class FormHelperTest < ActionView::TestCase
end
def test_fields_for_with_labelled_builder
fields_for(:post, @post, :builder => LabelledFormBuilder) do |f|
output_buffer = fields_for(:post, @post, :builder => LabelledFormBuilder) do |f|
concat f.text_field(:title)
concat f.text_area(:body)
concat f.check_box(:secret)

View file

@ -293,7 +293,7 @@ class FormOptionsHelperTest < ActionView::TestCase
@post = Post.new
@post.category = "<mus>"
fields_for :post, @post do |f|
output_buffer = fields_for :post, @post do |f|
concat f.select(:category, %w( abe <mus> hest))
end
@ -307,7 +307,7 @@ class FormOptionsHelperTest < ActionView::TestCase
@post = Post.new
@post.category = "<mus>"
fields_for :post, @post, :index => 108 do |f|
output_buffer = fields_for :post, @post, :index => 108 do |f|
concat f.select(:category, %w( abe <mus> hest))
end
@ -322,7 +322,7 @@ class FormOptionsHelperTest < ActionView::TestCase
@post.category = "<mus>"
def @post.to_param; 108; end
fields_for "post[]", @post do |f|
output_buffer = fields_for "post[]", @post do |f|
concat f.select(:category, %w( abe <mus> hest))
end
@ -336,7 +336,7 @@ class FormOptionsHelperTest < ActionView::TestCase
@post = Post.new
options = "<option value=\"abe\">abe</option><option value=\"mus\">mus</option><option value=\"hest\">hest</option>"
fields_for :post, @post do |f|
output_buffer = fields_for :post, @post do |f|
concat f.select(:category, options, :prompt => 'The prompt')
end
@ -462,7 +462,7 @@ class FormOptionsHelperTest < ActionView::TestCase
@post = Post.new
@post.author_name = "Babe"
fields_for :post, @post do |f|
output_buffer = fields_for :post, @post do |f|
concat f.collection_select(:author_name, dummy_posts, :author_name, :author_name)
end
@ -476,7 +476,7 @@ class FormOptionsHelperTest < ActionView::TestCase
@post = Post.new
@post.author_name = "Babe"
fields_for :post, @post, :index => 815 do |f|
output_buffer = fields_for :post, @post, :index => 815 do |f|
concat f.collection_select(:author_name, dummy_posts, :author_name, :author_name)
end
@ -491,7 +491,7 @@ class FormOptionsHelperTest < ActionView::TestCase
@post.author_name = "Babe"
def @post.to_param; 815; end
fields_for "post[]", @post do |f|
output_buffer = fields_for "post[]", @post do |f|
concat f.collection_select(:author_name, dummy_posts, :author_name, :author_name)
end
@ -570,7 +570,7 @@ class FormOptionsHelperTest < ActionView::TestCase
def test_time_zone_select_under_fields_for
@firm = Firm.new("D")
fields_for :firm, @firm do |f|
output_buffer = fields_for :firm, @firm do |f|
concat f.time_zone_select(:time_zone)
end
@ -589,7 +589,7 @@ class FormOptionsHelperTest < ActionView::TestCase
def test_time_zone_select_under_fields_for_with_index
@firm = Firm.new("D")
fields_for :firm, @firm, :index => 305 do |f|
output_buffer = fields_for :firm, @firm, :index => 305 do |f|
concat f.time_zone_select(:time_zone)
end
@ -609,7 +609,7 @@ class FormOptionsHelperTest < ActionView::TestCase
@firm = Firm.new("D")
def @firm.to_param; 305; end
fields_for "firm[]", @firm do |f|
output_buffer = fields_for "firm[]", @firm do |f|
concat f.time_zone_select(:time_zone)
end
@ -787,7 +787,7 @@ class FormOptionsHelperTest < ActionView::TestCase
@post = Post.new
@post.origin = 'dk'
fields_for :post, @post do |f|
output_buffer = fields_for :post, @post do |f|
concat f.grouped_collection_select("origin", @continents, :countries, :continent_name, :country_id, :country_name)
end

View file

@ -59,16 +59,14 @@ class FormTagHelperTest < ActionView::TestCase
end
def test_form_tag_with_block_in_erb
__in_erb_template = ''
form_tag("http://example.com") { concat "Hello world!" }
output_buffer = form_tag("http://example.com") { concat "Hello world!" }
expected = %(<form action="http://example.com" method="post">Hello world!</form>)
assert_dom_equal expected, output_buffer
end
def test_form_tag_with_block_and_method_in_erb
__in_erb_template = ''
form_tag("http://example.com", :method => :put) { concat "Hello world!" }
output_buffer = form_tag("http://example.com", :method => :put) { concat "Hello world!" }
expected = %(<form action="http://example.com" method="post"><div style='margin:0;padding:0;display:inline'><input type="hidden" name="_method" value="put" /></div>Hello world!</form>)
assert_dom_equal expected, output_buffer
@ -332,26 +330,22 @@ class FormTagHelperTest < ActionView::TestCase
end
def test_field_set_tag_in_erb
__in_erb_template = ''
field_set_tag("Your details") { concat "Hello world!" }
output_buffer = field_set_tag("Your details") { concat "Hello world!" }
expected = %(<fieldset><legend>Your details</legend>Hello world!</fieldset>)
assert_dom_equal expected, output_buffer
self.output_buffer = ''.html_safe
field_set_tag { concat "Hello world!" }
output_buffer = field_set_tag { concat "Hello world!" }
expected = %(<fieldset>Hello world!</fieldset>)
assert_dom_equal expected, output_buffer
self.output_buffer = ''.html_safe
field_set_tag('') { concat "Hello world!" }
output_buffer = field_set_tag('') { concat "Hello world!" }
expected = %(<fieldset>Hello world!</fieldset>)
assert_dom_equal expected, output_buffer
self.output_buffer = ''.html_safe
field_set_tag('', :class => 'format') { concat "Hello world!" }
output_buffer = field_set_tag('', :class => 'format') { concat "Hello world!" }
expected = %(<fieldset class="format">Hello world!</fieldset>)
assert_dom_equal expected, output_buffer