Skip to content

Commit

Permalink
Merge pull request rails#5621 from rafaelfranca/fix-2492-master
Browse files Browse the repository at this point in the history
Fix label_tag to merge the options hash with the object hash
  • Loading branch information
jeremy committed Mar 27, 2012
2 parents 33164c8 + 32763a8 commit da5f656
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 3 deletions.
6 changes: 3 additions & 3 deletions actionpack/lib/action_view/helpers/tags/label.rb
Expand Up @@ -3,16 +3,16 @@ module Helpers
module Tags
class Label < Base #:nodoc:
def initialize(object_name, method_name, template_object, content_or_options = nil, options = nil)
options ||= {}

content_is_options = content_or_options.is_a?(Hash)
if content_is_options
options = content_or_options
options.merge! content_or_options
@content = nil
else
@content = content_or_options
end

options ||= {}

super(object_name, method_name, template_object, options)
end

Expand Down
34 changes: 34 additions & 0 deletions actionpack/test/template/form_helper_test.rb
Expand Up @@ -1046,6 +1046,40 @@ def test_form_for_with_nil_index_option_override
assert_dom_equal expected, output_buffer
end

def test_form_for_label_error_wrapping
form_for(@post) do |f|
concat f.label(:author_name, :class => 'label')
concat f.text_field(:author_name)
concat f.submit('Create post')
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'>Author name</label></div>" +
"<div class='field_with_errors'><input name='post[author_name]' type='text' id='post_author_name' value='' /></div>" +
"<input name='commit' type='submit' value='Create post' />"
end

assert_dom_equal expected, output_buffer
end

def test_form_for_label_error_wrapping_without_conventional_instance_variable
post = remove_instance_variable :@post

form_for(post) do |f|
concat f.label(:author_name, :class => 'label')
concat f.text_field(:author_name)
concat f.submit('Create post')
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'>Author name</label></div>" +
"<div class='field_with_errors'><input name='post[author_name]' type='text' id='post_author_name' value='' /></div>" +
"<input name='commit' type='submit' value='Create post' />"
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)
Expand Down

0 comments on commit da5f656

Please sign in to comment.