Added the ability consider whether the the user exlicitly specified the label or the framework generated it when applying global custom formatting.

This commit is contained in:
Tim Scott 2013-04-17 08:56:25 -05:00
parent 2cb27a3bd2
commit 00704ffb33
2 changed files with 18 additions and 1 deletions

View File

@ -30,7 +30,10 @@ module SimpleForm
end
def label_text
SimpleForm.label_text.call(raw_label_text, required_label_text).strip.html_safe
(SimpleForm.label_text.parameters.size == 3 ?
SimpleForm.label_text.call(raw_label_text, required_label_text, options[:label].present?) :
SimpleForm.label_text.call(raw_label_text, required_label_text))
.strip.html_safe
end
def label_target

View File

@ -68,4 +68,18 @@ class LabelTest < ActionView::TestCase
assert_select 'label.integer[for=user_age]', "Age:"
end
end
test 'builder should allow custom formatting when label is explicitly specified' do
swap SimpleForm, label_text: lambda {|l, r, explicit| explicit ? l : "#{l.titleize}:" } do
with_label_for @user, :time_zone, 'What is your home time zone?'
assert_select 'label[for=user_time_zone]', 'What is your home time zone?'
end
end
test 'builder should allow custom formatting when label is generated' do
swap SimpleForm, label_text: lambda {|l, r, explicit| explicit ? l : "#{l.titleize}:" } do
with_label_for @user, :time_zone
assert_select 'label[for=user_time_zone]', 'Time Zone:'
end
end
end