Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 8th, 2012  |  syntax: None  |  size: 2.95 KB  |  hits: 23  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. diff --git a/actionpack/lib/action_view/helpers/form_helper.rb b/actionpack/lib/action_view/helpers/form_helper.rb
  2. index b0af836..54bb72b 100644
  3. --- a/actionpack/lib/action_view/helpers/form_helper.rb
  4. +++ b/actionpack/lib/action_view/helpers/form_helper.rb
  5. @@ -215,7 +215,7 @@ module ActionView
  6.        #    ...
  7.        #   <% end %>
  8.        #
  9. -      # If your resource has associations defined, for example, you want to add comments
  10. +      # If your resource has associations defined, for example, you want to add comments
  11.        # to the post given that the routes are set correctly:
  12.        #
  13.        #   <%= form_for([@document, @comment]) do |f| %>
  14. @@ -583,8 +583,9 @@ module ActionView
  15.        #     'Accept <a href="/terms">Terms</a>.'
  16.        #   end
  17.        def label(object_name, method, content_or_options = nil, options = nil, &block)
  18. -        if block_given?
  19. -          options = content_or_options if content_or_options.is_a?(Hash)
  20. +        content_is_options = content_or_options.is_a?(Hash)
  21. +        if content_is_options || block_given?
  22. +          options = content_or_options if content_is_options
  23.            text = nil
  24.          else
  25.            text = content_or_options
  26. diff --git a/actionpack/test/template/form_helper_test.rb b/actionpack/test/template/form_helper_test.rb
  27. index 9ddfa13..749abb5 100644
  28. --- a/actionpack/test/template/form_helper_test.rb
  29. +++ b/actionpack/test/template/form_helper_test.rb
  30. @@ -110,6 +110,13 @@ class FormHelperTest < ActionView::TestCase
  31.      I18n.locale = old_locale
  32.    end
  33.  
  34. +  def test_label_with_locales_and_options
  35. +    old_locale, I18n.locale = I18n.locale, :label
  36. +    assert_dom_equal('<label for="post_body" class="post_body">Write entire text here</label>', label(:post, :body, :class => 'post_body'))
  37. +  ensure
  38. +    I18n.locale = old_locale
  39. +  end
  40. +
  41.    def test_label_with_for_attribute_as_symbol
  42.      assert_dom_equal('<label for="my_for">Title</label>', label(:post, :title, nil, :for => "my_for"))
  43.    end
  44. @@ -603,7 +610,7 @@ class FormHelperTest < ActionView::TestCase
  45.  
  46.    def test_form_for_with_symbol_object_name
  47.      form_for(@post, :as => "other_name", :html => { :id => 'create-post' }) do |f|
  48. -      concat f.label(:title)
  49. +      concat f.label(:title, :class => 'post_title')
  50.        concat f.text_field(:title)
  51.        concat f.text_area(:body)
  52.        concat f.check_box(:secret)
  53. @@ -611,7 +618,7 @@ class FormHelperTest < ActionView::TestCase
  54.      end
  55.  
  56.      expected =  whole_form("/posts/123", "create-post", "other_name_edit", :method => "put") do
  57. -      "<label for='other_name_title'>Title</label>" +
  58. +      "<label for='other_name_title' class='post_title'>Title</label>" +
  59.        "<input name='other_name[title]' size='30' id='other_name_title' value='Hello World' type='text' />" +
  60.        "<textarea name='other_name[body]' id='other_name_body' rows='20' cols='40'>Back to the hill and over it again!</textarea>" +
  61.        "<input name='other_name[secret]' value='0' type='hidden' />" +