Fallback to default label when block is provided
This commit is contained in:
parent
56c0b4f25c
commit
c88efe3c0c
|
@ -273,7 +273,7 @@ module SimpleForm
|
||||||
# f.label :name, :id => "cool_label"
|
# f.label :name, :id => "cool_label"
|
||||||
#
|
#
|
||||||
def label(attribute_name, *args)
|
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 = args.extract_options!
|
||||||
options[:label_html] = options.dup
|
options[:label_html] = options.dup
|
||||||
options[:label] = options.delete(:label)
|
options[:label] = options.delete(:label)
|
||||||
|
|
|
@ -2,9 +2,9 @@
|
||||||
require 'test_helper'
|
require 'test_helper'
|
||||||
|
|
||||||
class LabelTest < ActionView::TestCase
|
class LabelTest < ActionView::TestCase
|
||||||
def with_label_for(object, *args)
|
def with_label_for(object, *args, &block)
|
||||||
with_concat_form_for(object) do |f|
|
with_concat_form_for(object) do |f|
|
||||||
f.label(*args)
|
f.label(*args, &block)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -34,6 +34,14 @@ class LabelTest < ActionView::TestCase
|
||||||
assert_no_select 'label.string'
|
assert_no_select 'label.string'
|
||||||
end
|
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
|
test 'builder allows label order to be changed' do
|
||||||
swap SimpleForm, :label_text => lambda { |l, r| "#{l}:" } do
|
swap SimpleForm, :label_text => lambda { |l, r| "#{l}:" } do
|
||||||
with_label_for @user, :age
|
with_label_for @user, :age
|
||||||
|
|
Loading…
Reference in New Issue