From c88efe3c0c2d768d28800d0852af5e38a78d20b7 Mon Sep 17 00:00:00 2001 From: Alex Kwiatkowski & Peter Jaros Date: Thu, 15 Sep 2011 12:02:02 -0400 Subject: [PATCH] Fallback to default label when block is provided --- lib/simple_form/form_builder.rb | 2 +- test/form_builder/label_test.rb | 12 ++++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/lib/simple_form/form_builder.rb b/lib/simple_form/form_builder.rb index 9b2b94d3..8458ab48 100644 --- a/lib/simple_form/form_builder.rb +++ b/lib/simple_form/form_builder.rb @@ -273,7 +273,7 @@ module SimpleForm # f.label :name, :id => "cool_label" # def label(attribute_name, *args) - return super if args.first.is_a?(String) + return super if args.first.is_a?(String) || block_given? options = args.extract_options! options[:label_html] = options.dup options[:label] = options.delete(:label) diff --git a/test/form_builder/label_test.rb b/test/form_builder/label_test.rb index a8c7d5b5..5f56655f 100644 --- a/test/form_builder/label_test.rb +++ b/test/form_builder/label_test.rb @@ -2,9 +2,9 @@ require 'test_helper' class LabelTest < ActionView::TestCase - def with_label_for(object, *args) + def with_label_for(object, *args, &block) with_concat_form_for(object) do |f| - f.label(*args) + f.label(*args, &block) end end @@ -34,6 +34,14 @@ class LabelTest < ActionView::TestCase assert_no_select 'label.string' end + test 'builder should fallback to default label when block is given' do + with_label_for @user, :name do + 'Nome do usuário' + end + assert_select 'label', 'Nome do usuário' + assert_no_select 'label.string' + end + test 'builder allows label order to be changed' do swap SimpleForm, :label_text => lambda { |l, r| "#{l}:" } do with_label_for @user, :age