Skip to content

Commit

Permalink
Fallback to default label when block is provided
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Kwiatkowski & Peter Jaros committed Sep 15, 2011
1 parent 56c0b4f commit c88efe3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/simple_form/form_builder.rb
Expand Up @@ -273,7 +273,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)
Expand Down
12 changes: 10 additions & 2 deletions test/form_builder/label_test.rb
Expand Up @@ -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

Expand Down Expand Up @@ -34,6 +34,14 @@ def with_label_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
Expand Down

0 comments on commit c88efe3

Please sign in to comment.