diff options
| -rw-r--r-- | actionpack/lib/action_view/helpers/form_helper.rb | 11 | ||||
| -rw-r--r-- | actionpack/lib/action_view/helpers/tags/label.rb | 6 | ||||
| -rw-r--r-- | actionpack/test/template/form_helper_test.rb | 24 | 
3 files changed, 23 insertions, 18 deletions
| diff --git a/actionpack/lib/action_view/helpers/form_helper.rb b/actionpack/lib/action_view/helpers/form_helper.rb index ab167e9fa3..6219a7a924 100644 --- a/actionpack/lib/action_view/helpers/form_helper.rb +++ b/actionpack/lib/action_view/helpers/form_helper.rb @@ -1117,17 +1117,10 @@ module ActionView          @template.fields_for(record_name, record_object, fields_options, &block)        end -      def label(method, content_or_options = nil, options = {}, &block) -        if content_or_options.is_a?(Hash) -          content_or_options = objectify_options(content_or_options) -        else -          options = objectify_options(options) -        end - -        @template.label(@object_name, method, content_or_options, options, &block) +      def label(method, text = nil, options = {}, &block) +        @template.label(@object_name, method, text, objectify_options(options), &block)        end -        def check_box(method, options = {}, checked_value = "1", unchecked_value = "0")          @template.check_box(@object_name, method, objectify_options(options), checked_value, unchecked_value)        end diff --git a/actionpack/lib/action_view/helpers/tags/label.rb b/actionpack/lib/action_view/helpers/tags/label.rb index 1bd71c2778..1c8bf063ea 100644 --- a/actionpack/lib/action_view/helpers/tags/label.rb +++ b/actionpack/lib/action_view/helpers/tags/label.rb @@ -3,16 +3,16 @@ module ActionView      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 diff --git a/actionpack/test/template/form_helper_test.rb b/actionpack/test/template/form_helper_test.rb index 2fa7c48a18..7b684822fc 100644 --- a/actionpack/test/template/form_helper_test.rb +++ b/actionpack/test/template/form_helper_test.rb @@ -1046,10 +1046,24 @@ class FormHelperTest < ActionView::TestCase      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 -    default_field_error_proc = ActionView::Base.field_error_proc -    ActionView::Base.field_error_proc = Proc.new{ |html_tag, instance| "<div class='error'>#{html_tag}</div>".html_safe }      form_for(post) do |f|        concat f.label(:author_name, :class => 'label') @@ -1058,14 +1072,12 @@ class FormHelperTest < ActionView::TestCase      end      expected = whole_form('/posts/123', 'edit_post_123' , 'edit_post', 'patch') do -      "<div class='error'><label for='post_author_name' class='label'>Author name</label></div>" + -      "<div class='error'><input name='post[author_name]' type='text' id='post_author_name' value='' /></div>" + +      "<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 -  ensure -    ActionView::Base.field_error_proc = default_field_error_proc    end    def test_form_for_with_namespace | 
