提交 889bb4b7 编写于 作者: A Alexey Vakhov

Block version of label should wrapped in field_with_errors in case of error

上级 0244c0d8
......@@ -33,7 +33,8 @@ def render(&block)
options["for"] = name_and_id["id"] unless options.key?("for")
if block_given?
@template_object.label_tag(name_and_id["id"], options, &block)
content = @template_object.capture(&block)
label_tag(name_and_id["id"], content, options)
else
content = if @content.blank?
@object_name.gsub!(/\[(.*)_attributes\]\[\d\]/, '.\1')
......
......@@ -1080,6 +1080,20 @@ def test_form_for_label_error_wrapping_without_conventional_instance_variable
assert_dom_equal expected, output_buffer
end
def test_form_for_label_error_wrapping_block_and_non_block_versions
form_for(@post) do |f|
concat f.label(:author_name, 'Name', :class => 'label')
concat f.label(:author_name, :class => 'label') { 'Name' }
end
expected = whole_form('/posts/123', 'edit_post_123' , 'edit_post', 'patch') do
"<div class='field_with_errors'><label for='post_author_name' class='label'>Name</label></div>" +
"<div class='field_with_errors'><label for='post_author_name' class='label'>Name</label></div>"
end
assert_dom_equal expected, output_buffer
end
def test_form_for_with_namespace
form_for(@post, :namespace => 'namespace') do |f|
concat f.text_field(:title)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册