Permalink
Browse files

Fallback to default label when block is provided

  • Loading branch information...
1 parent df337cf commit cf6cde881be81acbbb93480b8a7990a6fdef716e Alex Kwiatkowski & Peter Jaros committed with rafaelfranca Sep 15, 2011
Showing with 11 additions and 3 deletions.
  1. +1 −1 lib/simple_form/form_builder.rb
  2. +10 −2 test/form_builder_test.rb
@@ -266,7 +266,7 @@ def hint(attribute_name, options={})
# 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)
View
@@ -39,9 +39,9 @@ def with_hint_for(object, *args)
end
end
- 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
@@ -627,6 +627,14 @@ def with_association_for(object, *args)
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

0 comments on commit cf6cde8

Please sign in to comment.